Steven Lu
Steven Lu

Reputation: 43547

How to read Git 3-way unified diff output format?

Preface

This question is about understanding the basic unified diff output format. Three way diffing and merging is probably something best done from the comfort of a proper GUI merge tool, or at the very least, vim diff mode with plugins like fugitive.vim.

Question

I find that running git diff while merging a conflict produces a diff view that has two columns of pluses and minuses.

It's clear that in comparing three different versions of the same data we'll need more information than when comparing just two. But what do these columns actually mean? There are clearly now a lot more combinations for the possible "bucket" that a given line now belongs to. It used to just be either blank (same), + (added) or - (deleted), and now we have blank, ++, --, + ,  +, - , and  -. And possibly even more that I hadn't seen.

Upvotes: 8

Views: 1994

Answers (2)

Dan Aloni
Dan Aloni

Reputation: 4118

You are referring to the 'combined diff format'. This extension of the original uni-diff format deals with two or more files as input and one file as the result merge. This format is described in details as part of the 'combined diff format' section of the git-diff command manual.

Upvotes: 3

VonC
VonC

Reputation: 1329512

Note that the git diff "combined diff format", with one column for each of fileN is prepended to the output line to note how X's line is different from it, can be costly to generate.

The recent commit 72441af (April 2014) from Kirill Smelkov is very instructive on how such a diff will now be optimized (for Git 2.x, Q3 2014)

D(A,P2) is huge, because, if merge-base of A and P2 is several dozens of merges (from A, via first parent) below, that D(A,P2) will be diffing sum of merges from several subsystems to 1 subsystem.

The solution is to avoid computing n 1-parent diffs, and to find changed-to-all-parents paths via scanning A's and all Pi's trees simultaneously, at each step comparing their entries, and based on that comparison, populate paths result, and deduce we could skip recursing into subdirectories, if at least for 1 parent, sha1 of that dir tree is the same as in A.
That would save us from doing significant amount of needless work.

Upvotes: 1

Related Questions