Skip to content

Instantly share code, notes, and snippets.

@thcipriani
Last active Sep 11, 2020
Embed
What would you like to do?

The Git criss-cross merge

http://www.gelato.unsw.edu.au/archives/git/0504/2279.html

* (refs/heads/B -- Change line 8 to "---")
* Merge 'C' into 'B'
|\
| | * (refs/heads/C -- Change line 3 to "---")
| | * Merge 'B' into 'C'
| |/|
| |/
|/|
* | B8 (Change line 8 to "v-x")
| * C3 (Change line 3 to "gh-")
|/
* A (refs/heads/A)

README at refs/heads/A

abc
def
ghi
jkl
mno
pqr
stu
vwx
yz

README at refs/heads/B:

abc
def
gh-
jkl
mno
pqr
stu
---
yz

README at refs/heads/C:

abc
def
---
jkl
mno
pqr
stu
v-x
yz

Conflict as a result of git merge B C:

abc
def
---
jkl
mno
pqr
stu
<<<<<<< .merge_file_lFPzXz
---
=======
v-x
>>>>>>> .merge_file_Y3INVD
yz

The Git criss-cross revert

When there is a criss-cross merge, followed by a revert, the output is extra confusing. Again, both branch B and C contain eachother's commits. The output I'd expect is that line 3 and line 8 were ---. Instead, line 3 is ghi and line 8 is v-x. There are merge conflicts, but there are no marks in the file telling us where the conflict is.

* (refs/heads/B -- git revert C3)
* Merge 'C' into 'B'
|\
| | * (refs/heads/C -- git revert B8)
| | * Merge 'B' into 'C'
| |/|
| |/
|/|
* | B8 (Change line 8 to "v-x")
| * C3 (Change line 3 to "gh-")
|/
* A (refs/heads/A)

README at refs/heads/A

abc
def
ghi
jkl
mno
pqr
stu
vwx
yz

README at refs/heads/B:

abc
def
ghi
jkl
mno
pqr
stu
v-x
yz

README at refs/heads/C:

abc
def
gh-
jkl
mno
pqr
stu
vwx
yz

Conflict as a result of git merge B C:

$ git merge B C
Fast-forwarding to: B
Trying simple merge with C
Simple merge did not work, trying automatic merge.
Added README in both, but differently.
fatal: merge program failed
Automatic merge failed; fix conflicts and then commit the result.
$ git st
On branch main
You have unmerged paths.
 (fix conflicts and run "git commit")
 (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
   both added:      README

$ cat README 
abc
def
ghi
jkl
mno
pqr
stu
v-x
yz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment