Life is not as good as ten, and merging branches is often not smooth sailing.
Prepare a new feature1
branch and continue our new branch development:
git checkout- b feature1 New ' Feature1 '
Modify the last line of Readme.txt to read:
New is quick and simple.
Commit on the feature1
branch:
$ git add readme.txt - M " and Simple" 111 deletion (-)
Switch to master
branch:
$ git checkout master ' Master ' is'origin/master'1 commit.
Git also automatically prompts US master
that the current branch is ahead of 1 commits than a remote master
branch.
On the master
branch, change the last line of the Readme.txt file to:
New are quick & simple.
Submit:
git add readme.txt $-m "& Simple"&11 1 deletion (-)
Now, the master
branches and feature1
branches each have new commits, each of which becomes:
In this case, git cannot perform a "quick merge" and can only attempt to merge its own changes, but the merge may conflict, so let's try this:
git merge Feature1 Auto- in readme.txtautomatic merge failed, fix conflicts and then commit the result.
It's a conflict! Git tells us that there is a conflict with the Readme.txt file and must be resolved manually before committing . git status
You can also tell us the conflicting files:
$ git status # on branch master# Your branch
is ahead of " origin/master " by 2 commits.## unmerged paths:# (use git Add/rm <file>, ..... " as appropriate to mark Resolution) # # Both modified:readme.txt#no changes added to Commit (use git add " and/or " git commit-a ")
We can view the contents of Readme.txt directly:
is are free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. <<<<<<<new is quick & simple . =======new is quick and simple . >>>>>>> Feature1
Git uses <<<<<<<
, =======
to >>>>>>>
mark out the contents of different branches, we modify the following to save:
New is quick and simple.
Re-submit:
$ git add readme.txt - M "Conflict fixed" Fixed
Now, the master
branches and feature1
branches become the following:
git log
you can also see the merging of branches with parameters:
git log--graph--pretty=oneline--abbrev-commit* 59BC1CB Conflict fixed| | * 75a857c and simple* | 400b400 & simple|/* fec145a Branch test ...
Finally, delete the feature1
branch:
git branch- d feature1Deleted branch Feature1 (was 75a857c).
Work done.
Summary
When git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.
git log --graph
you can see the branch merge diagram with the command.
Git-Resolving conflicts