Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git union merge brings back some deleted lines

Tags:

git

git-merge

I'm trying to make sense of a puzzling behavior with git union merge. To repro, start with a hello.txt that has:

1
2
3

In another commit, add a line, e.g.

1
2
new
3

In a different foo branch off of the original commit, delete the middle line:

1
3

Here I would expect the merge to not contain the deleted line, even when using union merge. Yet I see it contain (after running git merge foo while on master.):

1
2
new
3

So it's ignoring my line deletion. Am I just misunderstanding how union merge works? Sample repo here: https://github.com/davidebbo/MergeTest

One more note: if instead of deleting line 2, you delete line 1, then the merge happens as expected, ending up with:

2
new
3

So the weirdness only seems to occur in scenarios that would cause conflicts under standard (non-union) merge.

like image 599
David Ebbo Avatar asked Oct 18 '12 05:10

David Ebbo


1 Answers

The --union merge is working just as it should. See the git-merge-file man page:

Instead of leaving conflicts in the file, resolve conflicts favouring both side of the lines.

The the second scenario does not count as a conflict at all. The modified lines are not adjacent (#1 and #3).

like image 56
Tsvetomir Tsonev Avatar answered Oct 08 '22 10:10

Tsvetomir Tsonev