1git-range-diff(1) 2================= 3 4NAME 5---- 6git-range-diff - Compare two commit ranges (e.g. two versions of a branch) 7 8SYNOPSIS 9-------- 10[verse] 11'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>] 12 [--no-dual-color] [--creation-factor=<factor>] 13 ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> ) 14 15DESCRIPTION 16----------- 17 18This command shows the differences between two versions of a patch 19series, or more generally, two commit ranges (ignoring merge commits). 20 21To that end, it first finds pairs of commits from both commit ranges 22that correspond with each other. Two commits are said to correspond when 23the diff between their patches (i.e. the author information, the commit 24message and the commit diff) is reasonably small compared to the 25patches' size. See ``Algorithm`` below for details. 26 27Finally, the list of matching commits is shown in the order of the 28second commit range, with unmatched commits being inserted just after 29all of their ancestors have been shown. 30 31 32OPTIONS 33------- 34--no-dual-color:: 35 When the commit diffs differ, `git range-diff` recreates the 36 original diffs' coloring, and adds outer -/+ diff markers with 37 the *background* being red/green to make it easier to see e.g. 38 when there was a change in what exact lines were added. This is 39 known to `range-diff` as "dual coloring". Use `--no-dual-color` 40 to revert to color all lines according to the outer diff markers 41 (and completely ignore the inner diff when it comes to color). 42 43--creation-factor=<percent>:: 44 Set the creation/deletion cost fudge factor to `<percent>`. 45 Defaults to 60. Try a larger value if `git range-diff` erroneously 46 considers a large change a total rewrite (deletion of one commit 47 and addition of another), and a smaller one in the reverse case. 48 See the ``Algorithm`` section below for an explanation why this is 49 needed. 50 51<range1> <range2>:: 52 Compare the commits specified by the two ranges, where 53 `<range1>` is considered an older version of `<range2>`. 54 55<rev1>...<rev2>:: 56 Equivalent to passing `<rev2>..<rev1>` and `<rev1>..<rev2>`. 57 58<base> <rev1> <rev2>:: 59 Equivalent to passing `<base>..<rev1>` and `<base>..<rev2>`. 60 Note that `<base>` does not need to be the exact branch point 61 of the branches. Example: after rebasing a branch `my-topic`, 62 `git range-diff my-topic@{u} my-topic@{1} my-topic` would 63 show the differences introduced by the rebase. 64 65`git range-diff` also accepts the regular diff options (see 66linkgit:git-diff[1]), most notably the `--color=[<when>]` and 67`--no-color` options. These options are used when generating the "diff 68between patches", i.e. to compare the author, commit message and diff of 69corresponding old/new commits. There is currently no means to tweak the 70diff options passed to `git log` when generating those patches. 71 72 73CONFIGURATION 74------------- 75This command uses the `diff.color.*` and `pager.range-diff` settings 76(the latter is on by default). 77See linkgit:git-config[1]. 78 79 80EXAMPLES 81-------- 82 83When a rebase required merge conflicts to be resolved, compare the changes 84introduced by the rebase directly afterwards using: 85 86------------ 87$ git range-diff @{u} @{1} @ 88------------ 89 90 91A typical output of `git range-diff` would look like this: 92 93------------ 94-: ------- > 1: 0ddba11 Prepare for the inevitable! 951: c0debee = 2: cab005e Add a helpful message at the start 962: f00dbal ! 3: decafe1 Describe a bug 97 @@ -1,3 +1,3 @@ 98 Author: A U Thor <author@example.com> 99 100 -TODO: Describe a bug 101 +Describe a bug 102 @@ -324,5 +324,6 103 This is expected. 104 105 -+What is unexpected is that it will also crash. 106 ++Unexpectedly, it also crashes. This is a bug, and the jury is 107 ++still out there how to fix it best. See ticket #314 for details. 108 109 Contact 1103: bedead < -: ------- TO-UNDO 111------------ 112 113In this example, there are 3 old and 3 new commits, where the developer 114removed the 3rd, added a new one before the first two, and modified the 115commit message of the 2nd commit as well its diff. 116 117When the output goes to a terminal, it is color-coded by default, just 118like regular `git diff`'s output. In addition, the first line (adding a 119commit) is green, the last line (deleting a commit) is red, the second 120line (with a perfect match) is yellow like the commit header of `git 121show`'s output, and the third line colors the old commit red, the new 122one green and the rest like `git show`'s commit header. 123 124A naive color-coded diff of diffs is actually a bit hard to read, 125though, as it colors the entire lines red or green. The line that added 126"What is unexpected" in the old commit, for example, is completely red, 127even if the intent of the old commit was to add something. 128 129To help with that, `range` uses the `--dual-color` mode by default. In 130this mode, the diff of diffs will retain the original diff colors, and 131prefix the lines with -/+ markers that have their *background* red or 132green, to make it more obvious that they describe how the diff itself 133changed. 134 135 136Algorithm 137--------- 138 139The general idea is this: we generate a cost matrix between the commits 140in both commit ranges, then solve the least-cost assignment. 141 142The cost matrix is populated thusly: for each pair of commits, both 143diffs are generated and the "diff of diffs" is generated, with 3 context 144lines, then the number of lines in that diff is used as cost. 145 146To avoid false positives (e.g. when a patch has been removed, and an 147unrelated patch has been added between two iterations of the same patch 148series), the cost matrix is extended to allow for that, by adding 149fixed-cost entries for wholesale deletes/adds. 150 151Example: Let commits `1--2` be the first iteration of a patch series and 152`A--C` the second iteration. Let's assume that `A` is a cherry-pick of 153`2,` and `C` is a cherry-pick of `1` but with a small modification (say, 154a fixed typo). Visualize the commits as a bipartite graph: 155 156------------ 157 1 A 158 159 2 B 160 161 C 162------------ 163 164We are looking for a "best" explanation of the new series in terms of 165the old one. We can represent an "explanation" as an edge in the graph: 166 167 168------------ 169 1 A 170 / 171 2 --------' B 172 173 C 174------------ 175 176This explanation comes for "free" because there was no change. Similarly 177`C` could be explained using `1`, but that comes at some cost c>0 178because of the modification: 179 180------------ 181 1 ----. A 182 | / 183 2 ----+---' B 184 | 185 `----- C 186 c>0 187------------ 188 189In mathematical terms, what we are looking for is some sort of a minimum 190cost bipartite matching; `1` is matched to `C` at some cost, etc. The 191underlying graph is in fact a complete bipartite graph; the cost we 192associate with every edge is the size of the diff between the two 193commits' patches. To explain also new commits, we introduce dummy nodes 194on both sides: 195 196------------ 197 1 ----. A 198 | / 199 2 ----+---' B 200 | 201 o `----- C 202 c>0 203 o o 204 205 o o 206------------ 207 208The cost of an edge `o--C` is the size of `C`'s diff, modified by a 209fudge factor that should be smaller than 100%. The cost of an edge 210`o--o` is free. The fudge factor is necessary because even if `1` and 211`C` have nothing in common, they may still share a few empty lines and 212such, possibly making the assignment `1--C`, `o--o` slightly cheaper 213than `1--o`, `o--C` even if `1` and `C` have nothing in common. With the 214fudge factor we require a much larger common part to consider patches as 215corresponding. 216 217The overall time needed to compute this algorithm is the time needed to 218compute n+m commit diffs and then n*m diffs of patches, plus the time 219needed to compute the least-cost assigment between n and m diffs. Git 220uses an implementation of the Jonker-Volgenant algorithm to solve the 221assignment problem, which has cubic runtime complexity. The matching 222found in this case will look like this: 223 224------------ 225 1 ----. A 226 | / 227 2 ----+---' B 228 .--+-----' 229 o -' `----- C 230 c>0 231 o ---------- o 232 233 o ---------- o 234------------ 235 236 237SEE ALSO 238-------- 239linkgit:git-log[1] 240 241GIT 242--- 243Part of the linkgit:git[1] suite