Why do I get a merge conflict?

隐身守侯 提交于 2019-12-11 05:54:32

问题


I just downloaded the most recent version of Git to my Windows platform. I have a file with the following content committed:

Line 1
Line 2
Line 3
Line 4

I then create a branch with: git branch development
I continue on the master branch and modify the first line so I now have:

Line 1master
Line 2
Line 3
Line 4

I stage and commit the change on the master branch. I switch to the development branch and modify the second line so I now have:

Line 1
Line 2development
Line 3
Line 4

I stage and commit the change on the development branch. I now switch back to the master branch. I attempt to merge the development branch with:
git merge development
I get the following conflict:

<<<<<<<< HEAD
Line 1master
Line 2
=======
Line 1
Line 2development
>>>>>>> development
Line 3
Line 4

But why? After the branch was created, a change was made each on the master and development branches. But they were to different lines in the file. So why a conflict?


回答1:


You get the conflict because you made the development branch before commiting the changes on master, so master has different content (line1master) at the moment you try to merge the development branch.

this image illustrates better the case;



来源:https://stackoverflow.com/questions/36385887/why-do-i-get-a-merge-conflict

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!