Unexpected merge conflict with git

So I have this simple file with 3 lines:

some
random
words

      

First merge test

I created two different branches with the original file at the top of this post from master. I am creating a branch merge1

that changes the first line from some

to will

. I am creating a branch merge2

that changes line 3 from words

to work

. I merge first merge1

, and merge2

- into master and everything works fine as expected.

Second merge test

I created two different branches with the original file at the top of this post from master. I am creating a branch merge1

that changes the first line from some

to doesnt

. I am creating a branch merge2

that changes line 2 from random

to work

. I compress first merge1

and it works when I try to combine merge2

. I am getting a conflict error that I was not expecting.

When I open the file, this is what I see:

<<<<<<< HEAD
doesnt
random
=======
some
work
>>>>>>> merge2
words

      

I don't understand why merge2 is showing the first line like some

, since merge2 hasn't changed that line. It's ironic that SVN handles great.

Am I missing something? Why do I have two different branches created from the same commit, change different lines of a small file just fine, but can't change consecutive lines?

+3


source to share


1 answer


Some assumptions based on working with git ...

Changes are tracked based on their environment. If you look at the diff for commit merge2, it looks something like this:

 some
-random
+work
 words

      



When you try to merge this into a file modified with merge1, it cannot find the pivot point "some". As a result, he must ask you how to proceed. If you change the inconsistent lines, it can still find some place in the file to bind the changes that need to be applied.

Also, keep in mind that git is for tracking code changes. It tends to be wrong on the merge caution side, because it's better for the user to define the merge, rather than automatically merging and breaking the code in some non-obvious way.

+5


source







All Articles