Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...