-1

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.)

1 Answers1

0

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.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Thanks for the answer. Could you give me the document for 'at least a single line of separation' rule? – heeam shin Aug 28 '20 at 01:17
  • Here is a little something I wrote, hope it's informative enough. It has a conflict where you can see how having a single line of separation skips the conflict: http://www.ezconflict.com/en/conflictsse6.html – eftshift0 Sep 05 '20 at 05:55
  • I found this comment today. Thanks. – heeam shin Nov 17 '20 at 00:55