'\" t .\" Title: git-range-diff .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: 04/20/2020 .\" Manual: Git Manual .\" Source: Git 2.20.1 .\" Language: English .\" .TH "GIT\-RANGE\-DIFF" "1" "04/20/2020" "Git 2\&.20\&.1" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-range-diff \- Compare two commit ranges (e\&.g\&. two versions of a branch) .SH "SYNOPSIS" .sp .nf \fIgit range\-diff\fR [\-\-color=[]] [\-\-no\-color] [] [\-\-no\-dual\-color] [\-\-creation\-factor=] ( | \&... | ) .fi .sp .SH "DESCRIPTION" .sp This command shows the differences between two versions of a patch series, or more generally, two commit ranges (ignoring merge commits)\&. .sp To that end, it first finds pairs of commits from both commit ranges that correspond with each other\&. Two commits are said to correspond when the diff between their patches (i\&.e\&. the author information, the commit message and the commit diff) is reasonably small compared to the patches\*(Aq size\&. See ``Algorithm`` below for details\&. .sp Finally, the list of matching commits is shown in the order of the second commit range, with unmatched commits being inserted just after all of their ancestors have been shown\&. .SH "OPTIONS" .PP \-\-no\-dual\-color .RS 4 When the commit diffs differ, \(oqgit range\-diff` recreates the original diffs\(cq coloring, and adds outer \-/+ diff markers with the \fBbackground\fR being red/green to make it easier to see e\&.g\&. when there was a change in what exact lines were added\&. .sp Additionally, the commit diff lines that are only present in the first commit range are shown "dimmed" (this can be overridden using the \fBcolor\&.diff\&.\fR config setting where \fB\fR is one of \fBcontextDimmed\fR, \fBoldDimmed\fR and \fBnewDimmed\fR), and the commit diff lines that are only present in the second commit range are shown in bold (which can be overridden using the config settings \fBcolor\&.diff\&.\fR with \fB\fR being one of \fBcontextBold\fR, \fBoldBold\fR or \fBnewBold\fR)\&. .sp This is known to \fBrange\-diff\fR as "dual coloring"\&. Use \fB\-\-no\-dual\-color\fR to revert to color all lines according to the outer diff markers (and completely ignore the inner diff when it comes to color)\&. .RE .PP \-\-creation\-factor= .RS 4 Set the creation/deletion cost fudge factor to \fB\fR\&. Defaults to 60\&. Try a larger value if \fBgit range\-diff\fR erroneously considers a large change a total rewrite (deletion of one commit and addition of another), and a smaller one in the reverse case\&. See the ``Algorithm`` section below for an explanation why this is needed\&. .RE .PP .RS 4 Compare the commits specified by the two ranges, where \fB\fR is considered an older version of \fB\fR\&. .RE .PP \&... .RS 4 Equivalent to passing \fB\&.\&.\fR and \fB\&.\&.\fR\&. .RE .PP .RS 4 Equivalent to passing \fB\&.\&.\fR and \fB\&.\&.\fR\&. Note that \fB\fR does not need to be the exact branch point of the branches\&. Example: after rebasing a branch \fBmy\-topic\fR, \fBgit range\-diff my\-topic@{u} my\-topic@{1} my\-topic\fR would show the differences introduced by the rebase\&. .RE .sp \fBgit range\-diff\fR also accepts the regular diff options (see \fBgit-diff\fR(1)), most notably the \fB\-\-color=[]\fR and \fB\-\-no\-color\fR options\&. These options are used when generating the "diff between patches", i\&.e\&. to compare the author, commit message and diff of corresponding old/new commits\&. There is currently no means to tweak the diff options passed to \fBgit log\fR when generating those patches\&. .SH "OUTPUT STABILITY" .sp The output of the \fBrange\-diff\fR command is subject to change\&. It is intended to be human\-readable porcelain output, not something that can be used across versions of Git to get a textually stable \fBrange\-diff\fR (as opposed to something like the \fB\-\-stable\fR option to \fBgit-patch-id\fR(1))\&. There\(cqs also no equivalent of \fBgit-apply\fR(1) for \fBrange\-diff\fR, the output is not intended to be machine\-readable\&. .sp This is particularly true when passing in diff options\&. Currently some options like \fB\-\-stat\fR can, as an emergent effect, produce output that\(cqs quite useless in the context of \fBrange\-diff\fR\&. Future versions of \fBrange\-diff\fR may learn to interpret such options in a manner specific to \fBrange\-diff\fR (e\&.g\&. for \fB\-\-stat\fR producing human\-readable output which summarizes how the diffstat changed)\&. .SH "CONFIGURATION" .sp This command uses the \fBdiff\&.color\&.*\fR and \fBpager\&.range\-diff\fR settings (the latter is on by default)\&. See \fBgit-config\fR(1)\&. .SH "EXAMPLES" .sp When a rebase required merge conflicts to be resolved, compare the changes introduced by the rebase directly afterwards using: .sp .if n \{\ .RS 4 .\} .nf $ git range\-diff @{u} @{1} @ .fi .if n \{\ .RE .\} .sp .sp A typical output of \fBgit range\-diff\fR would look like this: .sp .if n \{\ .RS 4 .\} .nf \-: \-\-\-\-\-\-\- > 1: 0ddba11 Prepare for the inevitable! 1: c0debee = 2: cab005e Add a helpful message at the start 2: f00dbal ! 3: decafe1 Describe a bug @@ \-1,3 +1,3 @@ Author: A U Thor \-TODO: Describe a bug +Describe a bug @@ \-324,5 +324,6 This is expected\&. \-+What is unexpected is that it will also crash\&. ++Unexpectedly, it also crashes\&. This is a bug, and the jury is ++still out there how to fix it best\&. See ticket #314 for details\&. Contact 3: bedead < \-: \-\-\-\-\-\-\- TO\-UNDO .fi .if n \{\ .RE .\} .sp .sp In this example, there are 3 old and 3 new commits, where the developer removed the 3rd, added a new one before the first two, and modified the commit message of the 2nd commit as well its diff\&. .sp When the output goes to a terminal, it is color\-coded by default, just like regular \fBgit diff\fR\*(Aqs output\&. In addition, the first line (adding a commit) is green, the last line (deleting a commit) is red, the second line (with a perfect match) is yellow like the commit header of \fBgit show\fR\*(Aqs output, and the third line colors the old commit red, the new one green and the rest like \fBgit show\fR\*(Aqs commit header\&. .sp A naive color\-coded diff of diffs is actually a bit hard to read, though, as it colors the entire lines red or green\&. The line that added "What is unexpected" in the old commit, for example, is completely red, even if the intent of the old commit was to add something\&. .sp To help with that, \fBrange\fR uses the \fB\-\-dual\-color\fR mode by default\&. In this mode, the diff of diffs will retain the original diff colors, and prefix the lines with \-/+ markers that have their \fBbackground\fR red or green, to make it more obvious that they describe how the diff itself changed\&. .SH "ALGORITHM" .sp The general idea is this: we generate a cost matrix between the commits in both commit ranges, then solve the least\-cost assignment\&. .sp The cost matrix is populated thusly: for each pair of commits, both diffs are generated and the "diff of diffs" is generated, with 3 context lines, then the number of lines in that diff is used as cost\&. .sp To avoid false positives (e\&.g\&. when a patch has been removed, and an unrelated patch has been added between two iterations of the same patch series), the cost matrix is extended to allow for that, by adding fixed\-cost entries for wholesale deletes/adds\&. .sp Example: Let commits \fB1\-\-2\fR be the first iteration of a patch series and \fBA\-\-C\fR the second iteration\&. Let\(cqs assume that \fBA\fR is a cherry\-pick of \fB2,\fR and \fBC\fR is a cherry\-pick of \fB1\fR but with a small modification (say, a fixed typo)\&. Visualize the commits as a bipartite graph: .sp .if n \{\ .RS 4 .\} .nf 1 A 2 B C .fi .if n \{\ .RE .\} .sp .sp We are looking for a "best" explanation of the new series in terms of the old one\&. We can represent an "explanation" as an edge in the graph: .sp .if n \{\ .RS 4 .\} .nf 1 A / 2 \-\-\-\-\-\-\-\-\*(Aq B C .fi .if n \{\ .RE .\} .sp .sp This explanation comes for "free" because there was no change\&. Similarly \fBC\fR could be explained using \fB1\fR, but that comes at some cost c>0 because of the modification: .sp .if n \{\ .RS 4 .\} .nf 1 \-\-\-\-\&. A | / 2 \-\-\-\-+\-\-\-\*(Aq B | `\-\-\-\-\- C c>0 .fi .if n \{\ .RE .\} .sp .sp In mathematical terms, what we are looking for is some sort of a minimum cost bipartite matching; \(oq1` is matched to \fBC\fR at some cost, etc\&. The underlying graph is in fact a complete bipartite graph; the cost we associate with every edge is the size of the diff between the two commits\(cq patches\&. To explain also new commits, we introduce dummy nodes on both sides: .sp .if n \{\ .RS 4 .\} .nf 1 \-\-\-\-\&. A | / 2 \-\-\-\-+\-\-\-\*(Aq B | o `\-\-\-\-\- C c>0 o o o o .fi .if n \{\ .RE .\} .sp .sp The cost of an edge \fBo\-\-C\fR is the size of \fBC\fR\*(Aqs diff, modified by a fudge factor that should be smaller than 100%\&. The cost of an edge \fBo\-\-o\fR is free\&. The fudge factor is necessary because even if \fB1\fR and \fBC\fR have nothing in common, they may still share a few empty lines and such, possibly making the assignment \fB1\-\-C\fR, \fBo\-\-o\fR slightly cheaper than \fB1\-\-o\fR, \fBo\-\-C\fR even if \fB1\fR and \fBC\fR have nothing in common\&. With the fudge factor we require a much larger common part to consider patches as corresponding\&. .sp The overall time needed to compute this algorithm is the time needed to compute n+m commit diffs and then n*m diffs of patches, plus the time needed to compute the least\-cost assigment between n and m diffs\&. Git uses an implementation of the Jonker\-Volgenant algorithm to solve the assignment problem, which has cubic runtime complexity\&. The matching found in this case will look like this: .sp .if n \{\ .RS 4 .\} .nf 1 \-\-\-\-\&. A | / 2 \-\-\-\-+\-\-\-\*(Aq B \&.\-\-+\-\-\-\-\-\*(Aq o \-\*(Aq `\-\-\-\-\- C c>0 o \-\-\-\-\-\-\-\-\-\- o o \-\-\-\-\-\-\-\-\-\- o .fi .if n \{\ .RE .\} .sp .SH "SEE ALSO" .sp \fBgit-log\fR(1) .SH "GIT" .sp Part of the \fBgit\fR(1) suite