1GIT-RANGE-DIFF(1)                 Git Manual                 GIT-RANGE-DIFF(1)
2
3
4

NAME

6       git-range-diff - Compare two commit ranges (e.g. two versions of a
7       branch)
8

SYNOPSIS

10       git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
11               [--no-dual-color] [--creation-factor=<factor>]
12               [--left-only | --right-only]
13               ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
14               [[--] <path>...]
15

DESCRIPTION

17       This command shows the differences between two versions of a patch
18       series, or more generally, two commit ranges (ignoring merge commits).
19
20       In the presence of <path> arguments, these commit ranges are limited
21       accordingly.
22
23       To that end, it first finds pairs of commits from both commit ranges
24       that correspond with each other. Two commits are said to correspond
25       when the diff between their patches (i.e. the author information, the
26       commit message and the commit diff) is reasonably small compared to the
27       patches' size. See ``Algorithm`` below for details.
28
29       Finally, the list of matching commits is shown in the order of the
30       second commit range, with unmatched commits being inserted just after
31       all of their ancestors have been shown.
32
33       There are three ways to specify the commit ranges:
34
35<range1> <range2>: Either commit range can be of the form
36           <base>..<rev>, <rev>^!  or <rev>^-<n>. See SPECIFYING RANGES in
37           gitrevisions(7) for more details.
38
39<rev1>...<rev2>. This is equivalent to <rev2>..<rev1>
40           <rev1>..<rev2>.
41
42<base> <rev1> <rev2>: This is equivalent to <base>..<rev1>
43           <base>..<rev2>.
44

OPTIONS

46       --no-dual-color
47           When the commit diffs differ, git range-diff recreates the original
48           diffs' coloring, and adds outer -/+ diff markers with the
49           background being red/green to make it easier to see e.g. when there
50           was a change in what exact lines were added.
51
52           Additionally, the commit diff lines that are only present in the
53           first commit range are shown "dimmed" (this can be overridden using
54           the color.diff.<slot> config setting where <slot> is one of
55           contextDimmed, oldDimmed and newDimmed), and the commit diff lines
56           that are only present in the second commit range are shown in bold
57           (which can be overridden using the config settings
58           color.diff.<slot> with <slot> being one of contextBold, oldBold or
59           newBold).
60
61           This is known to range-diff as "dual coloring". Use --no-dual-color
62           to revert to color all lines according to the outer diff markers
63           (and completely ignore the inner diff when it comes to color).
64
65       --creation-factor=<percent>
66           Set the creation/deletion cost fudge factor to <percent>. Defaults
67           to 60. Try a larger value if git range-diff erroneously considers a
68           large change a total rewrite (deletion of one commit and addition
69           of another), and a smaller one in the reverse case. See the
70           ``Algorithm`` section below for an explanation of why this is
71           needed.
72
73       --left-only
74           Suppress commits that are missing from the first specified range
75           (or the "left range" when using the <rev1>...<rev2> format).
76
77       --right-only
78           Suppress commits that are missing from the second specified range
79           (or the "right range" when using the <rev1>...<rev2> format).
80
81       --[no-]notes[=<ref>]
82           This flag is passed to the git log program (see git-log(1)) that
83           generates the patches.
84
85       <range1> <range2>
86           Compare the commits specified by the two ranges, where <range1> is
87           considered an older version of <range2>.
88
89       <rev1>...<rev2>
90           Equivalent to passing <rev2>..<rev1> and <rev1>..<rev2>.
91
92       <base> <rev1> <rev2>
93           Equivalent to passing <base>..<rev1> and <base>..<rev2>. Note that
94           <base> does not need to be the exact branch point of the branches.
95           Example: after rebasing a branch my-topic, git range-diff
96           my-topic@{u} my-topic@{1} my-topic would show the differences
97           introduced by the rebase.
98
99       git range-diff also accepts the regular diff options (see git-diff(1)),
100       most notably the --color=[<when>] and --no-color options. These options
101       are used when generating the "diff between patches", i.e. to compare
102       the author, commit message and diff of corresponding old/new commits.
103       There is currently no means to tweak most of the diff options passed to
104       git log when generating those patches.
105

OUTPUT STABILITY

107       The output of the range-diff command is subject to change. It is
108       intended to be human-readable porcelain output, not something that can
109       be used across versions of Git to get a textually stable range-diff (as
110       opposed to something like the --stable option to git-patch-id(1)).
111       There’s also no equivalent of git-apply(1) for range-diff, the output
112       is not intended to be machine-readable.
113
114       This is particularly true when passing in diff options. Currently some
115       options like --stat can, as an emergent effect, produce output that’s
116       quite useless in the context of range-diff. Future versions of
117       range-diff may learn to interpret such options in a manner specific to
118       range-diff (e.g. for --stat producing human-readable output which
119       summarizes how the diffstat changed).
120

CONFIGURATION

122       This command uses the diff.color.* and pager.range-diff settings (the
123       latter is on by default). See git-config(1).
124

EXAMPLES

126       When a rebase required merge conflicts to be resolved, compare the
127       changes introduced by the rebase directly afterwards using:
128
129           $ git range-diff @{u} @{1} @
130
131       A typical output of git range-diff would look like this:
132
133           -:  ------- > 1:  0ddba11 Prepare for the inevitable!
134           1:  c0debee = 2:  cab005e Add a helpful message at the start
135           2:  f00dbal ! 3:  decafe1 Describe a bug
136               @@ -1,3 +1,3 @@
137                Author: A U Thor <author@example.com>
138
139               -TODO: Describe a bug
140               +Describe a bug
141               @@ -324,5 +324,6
142                 This is expected.
143
144               -+What is unexpected is that it will also crash.
145               ++Unexpectedly, it also crashes. This is a bug, and the jury is
146               ++still out there how to fix it best. See ticket #314 for details.
147
148                 Contact
149           3:  bedead < -:  ------- TO-UNDO
150
151       In this example, there are 3 old and 3 new commits, where the developer
152       removed the 3rd, added a new one before the first two, and modified the
153       commit message of the 2nd commit as well as its diff.
154
155       When the output goes to a terminal, it is color-coded by default, just
156       like regular git diff's output. In addition, the first line (adding a
157       commit) is green, the last line (deleting a commit) is red, the second
158       line (with a perfect match) is yellow like the commit header of git
159       show's output, and the third line colors the old commit red, the new
160       one green and the rest like git show's commit header.
161
162       A naive color-coded diff of diffs is actually a bit hard to read,
163       though, as it colors the entire lines red or green. The line that added
164       "What is unexpected" in the old commit, for example, is completely red,
165       even if the intent of the old commit was to add something.
166
167       To help with that, range uses the --dual-color mode by default. In this
168       mode, the diff of diffs will retain the original diff colors, and
169       prefix the lines with -/+ markers that have their background red or
170       green, to make it more obvious that they describe how the diff itself
171       changed.
172

ALGORITHM

174       The general idea is this: we generate a cost matrix between the commits
175       in both commit ranges, then solve the least-cost assignment.
176
177       The cost matrix is populated thusly: for each pair of commits, both
178       diffs are generated and the "diff of diffs" is generated, with 3
179       context lines, then the number of lines in that diff is used as cost.
180
181       To avoid false positives (e.g. when a patch has been removed, and an
182       unrelated patch has been added between two iterations of the same patch
183       series), the cost matrix is extended to allow for that, by adding
184       fixed-cost entries for wholesale deletes/adds.
185
186       Example: Let commits 1--2 be the first iteration of a patch series and
187       A--C the second iteration. Let’s assume that A is a cherry-pick of 2,
188       and C is a cherry-pick of 1 but with a small modification (say, a fixed
189       typo). Visualize the commits as a bipartite graph:
190
191               1            A
192
193               2            B
194
195                            C
196
197       We are looking for a "best" explanation of the new series in terms of
198       the old one. We can represent an "explanation" as an edge in the graph:
199
200               1            A
201                          /
202               2 --------'  B
203
204                            C
205
206       This explanation comes for "free" because there was no change.
207       Similarly C could be explained using 1, but that comes at some cost c>0
208       because of the modification:
209
210               1 ----.      A
211                     |    /
212               2 ----+---'  B
213                     |
214                     `----- C
215                     c>0
216
217       In mathematical terms, what we are looking for is some sort of a
218       minimum cost bipartite matching; 1 is matched to C at some cost, etc.
219       The underlying graph is in fact a complete bipartite graph; the cost we
220       associate with every edge is the size of the diff between the two
221       commits' patches. To explain also new commits, we introduce dummy nodes
222       on both sides:
223
224               1 ----.      A
225                     |    /
226               2 ----+---'  B
227                     |
228               o     `----- C
229                     c>0
230               o            o
231
232               o            o
233
234       The cost of an edge o--C is the size of C's diff, modified by a fudge
235       factor that should be smaller than 100%. The cost of an edge o--o is
236       free. The fudge factor is necessary because even if 1 and C have
237       nothing in common, they may still share a few empty lines and such,
238       possibly making the assignment 1--C, o--o slightly cheaper than 1--o,
239       o--C even if 1 and C have nothing in common. With the fudge factor we
240       require a much larger common part to consider patches as corresponding.
241
242       The overall time needed to compute this algorithm is the time needed to
243       compute n+m commit diffs and then n*m diffs of patches, plus the time
244       needed to compute the least-cost assignment between n and m diffs. Git
245       uses an implementation of the Jonker-Volgenant algorithm to solve the
246       assignment problem, which has cubic runtime complexity. The matching
247       found in this case will look like this:
248
249               1 ----.      A
250                     |    /
251               2 ----+---'  B
252                  .--+-----'
253               o -'  `----- C
254                     c>0
255               o ---------- o
256
257               o ---------- o
258

SEE ALSO

260       git-log(1)
261

GIT

263       Part of the git(1) suite
264
265
266
267Git 2.43.0                        11/20/2023                 GIT-RANGE-DIFF(1)
Impressum