diff3 output in git conflict style, including mergeable hunks

41 views Asked by At

I would like to produce a file consisting of the three-way diff of three files, with every difference represented as a conflict in the git style. That is, common lines are shown verbatim, and differing sections of a file are shown with conflict markers "<<<<<<", "||||||", "======", and ">>>>>>" (also called "conflict brackets"):

common line 1
common line 2
<<<<<<<
text from mine.txt
|||||||
text from base.txt
more text from base.txt
=======
text from yours.txt
>>>>>>>
common line 3
common line 4
<<<<<<<
same text in mine.txt and yours.txt, none in base.txt
|||||||
=======
same text in mine.txt and yours.txt, none in base.txt
>>>>>>>
common line 5
common line 6

I would like every difference to be marked with conflict brackets, including differences that are mergeable. And I would like to obtain the output without human intervention.

Here are some options that do not work:

  • git diff only takes two files as input; that is, it compares two things rather than three.
  • git merge-file does not show mergeable differences (it merges them).
  • diff3 -m is like git merge-file: close: it shows the whole file, with conflict markers for conflicts, but it does not show conflict markers for mergeable differences.
  • diff3 shows all the differences, even mergeable ones, but not in the given format.
  • diff3 -A does not show all the differences, and mergeable ones are not output with conflict markers.

I can write a program that takes the diff3 output and the original files, and outputs the conflicted file in git style. However, I would prefer to avoid that if I can.

1

There are 1 answers

2
jthill On

Git's vimdiff mergetool shows you all four versions (ours, base, theirs, results-so-far), you can step through the changes, including all the automerged ones, with ]c and [c and see everything, 1do to take the local version, 2do to take the base version, 3do to take the remote version.