Life is not as good as it is, and merging branches is often not smooth sailing.
We are preparing new branch Newbranch.
[Email protected] Mingw32/c/gitskill (Master)
$ git checkout-b newbranch
Switched to a new branch ' Newbranch '
Modify the Readme.txt and add the last line:
$ cat Readme.txt
Master Branch Content
Add Dev Branch Content
Branch Merge Test
Commit on the branch Newbranch:
[Email protected] Mingw32/c/gitskill (Newbranch)
$ git Add readme.txt
[Email protected] Mingw32/c/gitskill (Newbranch)
$ git commit-m "Newbranch first Commit"
[Newbranch Cccee34] Newbranch First Commit
1 file changed, 2 insertions (+), 1 deletion (-)
Switch to the Master branch:
$ git Checkout Master
Switched to branch ' master '
Your Branch is ahead of ' Origin/master ' by 2 commits.
(use "Git push" to publish your local commits)
On the Master branch, add the last line of the Readme.txt file:
Merge test content on Master branch
Add, submit
[Email protected] Mingw32/c/gitskill (Master)
$ git Add readme.txt
[Email protected] Mingw32/c/gitskill (Master)
$ git commit-m "Master branch merge Test"
[Master 4BB4C5A] Master branch merge test
1 file changed, 2 insertions (+), 1 deletion (-)
In this case, the automatic merge conflict occurs:
[Email protected] Mingw32/c/gitskill (Master)
$ git Merge Newbranch
Auto-merging Readme.txt
CONFLICT (content): Merge CONFLICT in Readme.txt
Automatic merge failed; Fix conflicts and then commits the result.
We directly view the contents of the merged Readme.txt file:
$ cat Readme.txt
Master Branch Content
Add Dev Branch Content
<<<<<<< HEAD
Merge test content on Master branch
=======
Branch Merge Test
>>>>>>> Newbranch
Git uses <<<<<<<,=======,>>>>>>> to mark the contents of different branches, and we modify them to save
Master Branch Content
Add Dev Branch Content
Merge test content on Master branch
Branch Merge Test
Then add, Commit:
[Email protected] Mingw32/c/gitskill (master| Merging)
$ git Add readme.txt
[Email protected] Mingw32/c/gitskill (master| Merging)
$ git commit-m "branch merge"
[Master F3D8F1E] branch Merge
You can also see the merging of branches with the git log with parameters:
[Email protected] Mingw32/c/gitskill (Master)
$ git log--graph--pretty=oneline--abbrev-commit
* F3D8F1E Branch Merge
|\
| * Cccee34 Newbranch First Commit
* | 4BB4C5A Master Branch Merge test
|/
* 0D0BBCA Dev First Commit
* D5aea29 Master First Commit
* 023EE21 Initial Commit
Now, delete the Newbranch branch:
[Email protected] Mingw32/c/gitskill (Master)
$ git branch-d newbranch
Deleted Branch Newbranch (was Cccee34).
[Email protected] Mingw32/c/gitskill (Master)
$ git Branch
* Master
Summary: When git cannot automatically merge branches, it must first resolve conflicts, resolve conflicts, and then commit, merge complete
You can see the branch merge diagram with the git log--graph command.
Conflict resolution in GIT merge branch