3

I've had a strange situation where a git merge does not correctly identify all merge conflicts in a file.

If I use a, b, c, etc. to represent blocks of code (which in reality are 100s/1000s of lines of XML), the following happens:

Original Branched Master File

a
b
c
d
e

Altered File on Feature1 Branch

g
b
c
h
i
d
j

Altered File on Master

a
b
f
d
e

So if I merge master into feature1 I should get the following conflicted file

g
b
<<<<<<< HEAD
c
h
i
=======
f
>>>>>>> master
d
j

(and I tested this using files as above, rather than the actual ones, where I do get the correct conflicted file)

But what I actually get with the real files is effectively

g
b
c
<<<<<<< HEAD
h
i
=======
f
>>>>>>> master
d
j

That is, it thinks blocks h/i and f are in conflict, when actually block f is what replaced block c in master.

Is there any reason why git should mess up like this? I have triple-checked and I'm 99.9% sure that the representation here is accurate.

Stuart Rossiter
  • 2,432
  • 1
  • 17
  • 20
  • Are you also sure there were no merges and/or reverts before? Git really doesn't like reverting merge commits... – CptBartender May 19 '16 at 23:24
  • @CptBartender Actually yes there was a reverted commit on master prior to the correct commit. So I was effectively merging 3 commits (original, revert and 'correct' commit). That can cause problems then? – Stuart Rossiter May 24 '16 at 16:52
  • Reverted commit in and of itself is not a problem - it's only a problem if you revert a merge commit. Example: you have a file in master (comments don't allow newlines in them, so assume spaces are line separators): `a b`. You make a branch and change it to `a c`, then merge it to master. Then on master you make a reverting commit, so it's back to `a b`. Then you change the file on branch to `x c` and merge it to master again. At this point, the branch has `x c` and master has `a b`. From master's perspective, the changes are: `b->c`, `c->b`, `a->x`, so the merge result is `x b`, not `x c` – CptBartender May 24 '16 at 22:36
  • @CptBartender OK thanks, nice clear explanation. So doesn't look like a cause here. – Stuart Rossiter May 26 '16 at 11:34

0 Answers0