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.
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.
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.
Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.
By default, git diff command options will display the unified diff format between two commits. The combined diff format shows two or more user-specified files with one file and shows how that file is different from each of the specified files. You can use the -c or --cc option to produce a combined diff.
When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.
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.
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, ifmerge-base
ofA
andP2
is several dozens of merges (fromA
, via first parent) below, thatD(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 inA
.
That would save us from doing significant amount of needless work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With