Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

Why changes in another line arise git merge conflict?

I modified different lines in different branches, but those changes occur git merge conflict. I read the post, but I think the changes occur in totally different lines.

Here are my test codes.

branch-base

Hello, my first conflict.
Second line.a    # add a single character 'a' at line 2
Third line.

branch-a

Hello, my first conflict.
Second line.
Third line.a    # add a single character 'a' at line 3

And I executed the following code, it says git merge conflict.

$ git checkout branch-base
$ git merge branch-a

Here's my conflict file.

Hello, my first conflict.
<<<<<<< HEAD
Second line.a
Third line.
=======
Second line.
Third line.a
>>>>>>> branch-a

Why this conflict happens? I think I made changes in totally different lines (although those are adjacent.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There has to be at least a single line of separation that remains the same so that they can be treated separately and not produce a conflict. Given that they are not separated by a line that stays the same on all 3 revisions (the two tips and the common ancestor) then they are treated as a single block. One branch modifies that block one way, the other in another way... so, conflict.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...