Monday, 13 February 2017

How to Solve CONFLICT When Trying to merge branches

We would like to merge branch issue2 and branch issue3 to master.
So first, switch to master and merge issue2:
$ git checkout master
Switched to branch 'master'
$ git merge issue2
Updating b2b23c4..8f7aa27
Fast-forward
 myfile.txt |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
This is fast-forward merge.
目前的历史记录


Now let's merge issue3:
$ git merge issue3
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Automatic merge failed; fix conflicts and then commit the result.
We can see the automatical merge failed because there is conflict on the same lines from two different branches. And we can see the conflict files become:
old stuff
add some new stuff
<<<<<<< HEAD
did something before
=======
pull something from some one else
>>>>>>> issue3
Git has generated the differences where the conflicts happened. We must change the file to:

old stuff
add some new stuff
did something before
pull something from some one else
Basically, manually fix the conflict and commit again: 

$ git add myfile.txt
$ git commit -m "merge issue3"
# On branch master
nothing to commit (working directory clean)
We can see this is not fast-forward but non fast-forward.
目前的历史记录

ref:
http://backlogtool.com/git-guide/cn/stepup/stepup2_7.html

No comments:

Post a Comment