2 .\" Title: git-range-diff
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.0.164.g477ce5ccd6
10 .TH "GIT\-RANGE\-DIFF" "1" "2024-08-14" "Git 2\&.46\&.0\&.164\&.g477ce5" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-range-diff \- Compare two commit ranges (e\&.g\&. two versions of a branch)
35 \fIgit range\-diff\fR [\-\-color=[<when>]] [\-\-no\-color] [<diff\-options>]
36 [\-\-no\-dual\-color] [\-\-creation\-factor=<factor>]
37 [\-\-left\-only | \-\-right\-only]
38 ( <range1> <range2> | <rev1>\&...\:<rev2> | <base> <rev1> <rev2> )
39 [[\-\-] <path>\&...\:]
43 This command shows the differences between two versions of a patch series, or more generally, two commit ranges (ignoring merge commits)\&.
45 In the presence of \fB<path>\fR arguments, these commit ranges are limited accordingly\&.
47 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\&.
49 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\&.
51 There are three ways to specify the commit ranges:
61 \fB<range1> <range2>\fR: Either commit range can be of the form
62 \fB<base>\&.\&.<rev>\fR,
65 \fB<rev>^\-<n>\fR\&. See
66 \fBSPECIFYING RANGES\fR
80 \fB<rev1>\&.\&.\&.<rev2>\fR\&. This is equivalent to
81 \fB<rev2>\&.\&.<rev1> <rev1>\&.\&.<rev2>\fR\&.
92 \fB<base> <rev1> <rev2>\fR: This is equivalent to
93 \fB<base>\&.\&.<rev1> <base>\&.\&.<rev2>\fR\&.
99 When the commit diffs differ,
100 \fBgit range\-diff\fR
101 recreates the original diffs\*(Aq coloring, and adds outer \-/+ diff markers with the
103 being red/green to make it easier to see e\&.g\&. when there was a change in what exact lines were added\&.
105 Additionally, the commit diff lines that are only present in the first commit range are shown "dimmed" (this can be overridden using the
106 \fBcolor\&.diff\&.<slot>\fR
113 \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
114 \fBcolor\&.diff\&.<slot>\fR
125 as "dual coloring"\&. Use
126 \fB\-\-no\-dual\-color\fR
127 to revert to color all lines according to the outer diff markers (and completely ignore the inner diff when it comes to color)\&.
130 \-\-creation\-factor=<percent>
132 Set the creation/deletion cost fudge factor to
133 \fB<percent>\fR\&. Defaults to 60\&. Try a larger value if
134 \fBgit range\-diff\fR
135 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 of why this is needed\&.
140 Suppress commits that are missing from the first specified range (or the "left range" when using the
141 \fB<rev1>\&.\&.\&.<rev2>\fR
147 Suppress commits that are missing from the second specified range (or the "right range" when using the
148 \fB<rev1>\&.\&.\&.<rev2>\fR
152 \-\-[no\-]notes[=<ref>]
154 This flag is passed to the
157 \fBgit-log\fR(1)) that generates the patches\&.
162 Compare the commits specified by the two ranges, where
164 is considered an older version of
170 Equivalent to passing
171 \fB<rev2>\&.\&.<rev1>\fR
173 \fB<rev1>\&.\&.<rev2>\fR\&.
178 Equivalent to passing
179 \fB<base>\&.\&.<rev1>\fR
181 \fB<base>\&.\&.<rev2>\fR\&. Note that
183 does not need to be the exact branch point of the branches\&. Example: after rebasing a branch
185 \fBgit range\-diff my\-topic@{u} my\-topic@{1} my\-topic\fR
186 would show the differences introduced by the rebase\&.
189 \fBgit range\-diff\fR also accepts the regular diff options (see \fBgit-diff\fR(1)), most notably the \fB\-\-color=[<when>]\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 most of the diff options passed to \fBgit log\fR when generating those patches\&.
190 .SH "OUTPUT STABILITY"
192 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\&.
194 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)\&.
197 This command uses the \fBdiff\&.color\&.*\fR and \fBpager\&.range\-diff\fR settings (the latter is on by default)\&. See \fBgit-config\fR(1)\&.
200 When a rebase required merge conflicts to be resolved, compare the changes introduced by the rebase directly afterwards using:
206 $ git range\-diff @{u} @{1} @
212 A typical output of \fBgit range\-diff\fR would look like this:
218 \-: \-\-\-\-\-\-\- > 1: 0ddba11 Prepare for the inevitable!
219 1: c0debee = 2: cab005e Add a helpful message at the start
220 2: f00dbal ! 3: decafe1 Describe a bug
222 Author: A U Thor <author@example\&.com>
224 \-TODO: Describe a bug
229 \-+What is unexpected is that it will also crash\&.
230 ++Unexpectedly, it also crashes\&. This is a bug, and the jury is
231 ++still out there how to fix it best\&. See ticket #314 for details\&.
234 3: bedead < \-: \-\-\-\-\-\-\- TO\-UNDO
240 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 as its diff\&.
242 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\&.
244 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\&.
246 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\&.
249 The general idea is this: we generate a cost matrix between the commits in both commit ranges, then solve the least\-cost assignment\&.
251 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\&.
253 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\&.
255 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:
271 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:
279 2 \-\-\-\-\-\-\-\-\*(Aq B
287 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:
295 2 \-\-\-\-+\-\-\-\*(Aq B
304 In mathematical terms, what we are looking for is some sort of a minimum cost bipartite matching; \fB1\fR 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\*(Aq patches\&. To explain also new commits, we introduce dummy nodes on both sides:
312 2 \-\-\-\-+\-\-\-\*(Aq B
324 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\&.
326 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 assignment 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:
334 2 \-\-\-\-+\-\-\-\*(Aq B
335 \&.\-\-+\-\-\-\-\-\*(Aq
336 o \-\*(Aq `\-\-\-\-\- C
338 o \-\-\-\-\-\-\-\-\-\- o
340 o \-\-\-\-\-\-\-\-\-\- o
350 Part of the \fBgit\fR(1) suite