Johannes Schindelin | 348ae56 | 2018-08-13 04:33:02 -0700 | [diff] [blame] | 1 | git-range-diff(1) |
| 2 | ================= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-range-diff - Compare two commit ranges (e.g. two versions of a branch) |
| 7 | |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 8 | SYNOPSIS |
| 9 | -------- |
| 10 | [verse] |
| 11 | 'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>] |
Johannes Schindelin | 2752679 | 2018-08-13 04:33:30 -0700 | [diff] [blame] | 12 | [--no-dual-color] [--creation-factor=<factor>] |
Johannes Schindelin | 1e79f97 | 2021-02-05 14:46:13 +0000 | [diff] [blame] | 13 | [--left-only | --right-only] |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 14 | ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> ) |
Johannes Schindelin | b757478 | 2022-08-26 09:39:30 +0000 | [diff] [blame] | 15 | [[--] <path>...] |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 16 | |
| 17 | DESCRIPTION |
| 18 | ----------- |
| 19 | |
| 20 | This command shows the differences between two versions of a patch |
| 21 | series, or more generally, two commit ranges (ignoring merge commits). |
| 22 | |
Johannes Schindelin | b757478 | 2022-08-26 09:39:30 +0000 | [diff] [blame] | 23 | In the presence of `<path>` arguments, these commit ranges are limited |
| 24 | accordingly. |
| 25 | |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 26 | To that end, it first finds pairs of commits from both commit ranges |
| 27 | that correspond with each other. Two commits are said to correspond when |
| 28 | the diff between their patches (i.e. the author information, the commit |
| 29 | message and the commit diff) is reasonably small compared to the |
| 30 | patches' size. See ``Algorithm`` below for details. |
| 31 | |
| 32 | Finally, the list of matching commits is shown in the order of the |
| 33 | second commit range, with unmatched commits being inserted just after |
| 34 | all of their ancestors have been shown. |
| 35 | |
Johannes Schindelin | 2cc543d | 2021-02-05 14:44:49 +0000 | [diff] [blame] | 36 | There are three ways to specify the commit ranges: |
| 37 | |
| 38 | - `<range1> <range2>`: Either commit range can be of the form |
| 39 | `<base>..<rev>`, `<rev>^!` or `<rev>^-<n>`. See `SPECIFYING RANGES` |
| 40 | in linkgit:gitrevisions[7] for more details. |
| 41 | |
| 42 | - `<rev1>...<rev2>`. This is equivalent to |
| 43 | `<rev2>..<rev1> <rev1>..<rev2>`. |
| 44 | |
| 45 | - `<base> <rev1> <rev2>`: This is equivalent to `<base>..<rev1> |
| 46 | <base>..<rev2>`. |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 47 | |
| 48 | OPTIONS |
| 49 | ------- |
Johannes Schindelin | 2752679 | 2018-08-13 04:33:30 -0700 | [diff] [blame] | 50 | --no-dual-color:: |
| 51 | When the commit diffs differ, `git range-diff` recreates the |
| 52 | original diffs' coloring, and adds outer -/+ diff markers with |
| 53 | the *background* being red/green to make it easier to see e.g. |
Johannes Schindelin | a7be92a | 2018-08-13 04:33:32 -0700 | [diff] [blame] | 54 | when there was a change in what exact lines were added. |
| 55 | + |
| 56 | Additionally, the commit diff lines that are only present in the first commit |
| 57 | range are shown "dimmed" (this can be overridden using the `color.diff.<slot>` |
| 58 | config setting where `<slot>` is one of `contextDimmed`, `oldDimmed` and |
| 59 | `newDimmed`), and the commit diff lines that are only present in the second |
| 60 | commit range are shown in bold (which can be overridden using the config |
| 61 | settings `color.diff.<slot>` with `<slot>` being one of `contextBold`, |
| 62 | `oldBold` or `newBold`). |
| 63 | + |
| 64 | This is known to `range-diff` as "dual coloring". Use `--no-dual-color` |
| 65 | to revert to color all lines according to the outer diff markers |
| 66 | (and completely ignore the inner diff when it comes to color). |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 67 | |
| 68 | --creation-factor=<percent>:: |
| 69 | Set the creation/deletion cost fudge factor to `<percent>`. |
| 70 | Defaults to 60. Try a larger value if `git range-diff` erroneously |
| 71 | considers a large change a total rewrite (deletion of one commit |
| 72 | and addition of another), and a smaller one in the reverse case. |
Elijah Newren | cf6cac2 | 2023-10-08 06:45:03 +0000 | [diff] [blame] | 73 | See the ``Algorithm`` section below for an explanation of why this is |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 74 | needed. |
| 75 | |
Johannes Schindelin | 1e79f97 | 2021-02-05 14:46:13 +0000 | [diff] [blame] | 76 | --left-only:: |
| 77 | Suppress commits that are missing from the first specified range |
| 78 | (or the "left range" when using the `<rev1>...<rev2>` format). |
| 79 | |
| 80 | --right-only:: |
| 81 | Suppress commits that are missing from the second specified range |
| 82 | (or the "right range" when using the `<rev1>...<rev2>` format). |
| 83 | |
Denton Liu | bd36191 | 2019-11-20 13:18:45 -0800 | [diff] [blame] | 84 | --[no-]notes[=<ref>]:: |
| 85 | This flag is passed to the `git log` program |
| 86 | (see linkgit:git-log[1]) that generates the patches. |
| 87 | |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 88 | <range1> <range2>:: |
| 89 | Compare the commits specified by the two ranges, where |
| 90 | `<range1>` is considered an older version of `<range2>`. |
| 91 | |
| 92 | <rev1>...<rev2>:: |
| 93 | Equivalent to passing `<rev2>..<rev1>` and `<rev1>..<rev2>`. |
| 94 | |
| 95 | <base> <rev1> <rev2>:: |
| 96 | Equivalent to passing `<base>..<rev1>` and `<base>..<rev2>`. |
| 97 | Note that `<base>` does not need to be the exact branch point |
| 98 | of the branches. Example: after rebasing a branch `my-topic`, |
| 99 | `git range-diff my-topic@{u} my-topic@{1} my-topic` would |
| 100 | show the differences introduced by the rebase. |
| 101 | |
| 102 | `git range-diff` also accepts the regular diff options (see |
| 103 | linkgit:git-diff[1]), most notably the `--color=[<when>]` and |
| 104 | `--no-color` options. These options are used when generating the "diff |
| 105 | between patches", i.e. to compare the author, commit message and diff of |
Denton Liu | bd36191 | 2019-11-20 13:18:45 -0800 | [diff] [blame] | 106 | corresponding old/new commits. There is currently no means to tweak most of the |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 107 | diff options passed to `git log` when generating those patches. |
| 108 | |
Ævar Arnfjörð Bjarmason | df569c3 | 2018-11-09 10:18:01 +0000 | [diff] [blame] | 109 | OUTPUT STABILITY |
| 110 | ---------------- |
| 111 | |
| 112 | The output of the `range-diff` command is subject to change. It is |
| 113 | intended to be human-readable porcelain output, not something that can |
| 114 | be used across versions of Git to get a textually stable `range-diff` |
| 115 | (as opposed to something like the `--stable` option to |
| 116 | linkgit:git-patch-id[1]). There's also no equivalent of |
| 117 | linkgit:git-apply[1] for `range-diff`, the output is not intended to |
| 118 | be machine-readable. |
| 119 | |
| 120 | This is particularly true when passing in diff options. Currently some |
| 121 | options like `--stat` can, as an emergent effect, produce output |
| 122 | that's quite useless in the context of `range-diff`. Future versions |
| 123 | of `range-diff` may learn to interpret such options in a manner |
| 124 | specific to `range-diff` (e.g. for `--stat` producing human-readable |
| 125 | output which summarizes how the diffstat changed). |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 126 | |
| 127 | CONFIGURATION |
| 128 | ------------- |
| 129 | This command uses the `diff.color.*` and `pager.range-diff` settings |
| 130 | (the latter is on by default). |
| 131 | See linkgit:git-config[1]. |
| 132 | |
| 133 | |
| 134 | EXAMPLES |
| 135 | -------- |
| 136 | |
| 137 | When a rebase required merge conflicts to be resolved, compare the changes |
| 138 | introduced by the rebase directly afterwards using: |
| 139 | |
| 140 | ------------ |
| 141 | $ git range-diff @{u} @{1} @ |
| 142 | ------------ |
| 143 | |
| 144 | |
| 145 | A typical output of `git range-diff` would look like this: |
| 146 | |
| 147 | ------------ |
| 148 | -: ------- > 1: 0ddba11 Prepare for the inevitable! |
| 149 | 1: c0debee = 2: cab005e Add a helpful message at the start |
| 150 | 2: f00dbal ! 3: decafe1 Describe a bug |
| 151 | @@ -1,3 +1,3 @@ |
| 152 | Author: A U Thor <author@example.com> |
| 153 | |
| 154 | -TODO: Describe a bug |
| 155 | +Describe a bug |
| 156 | @@ -324,5 +324,6 |
| 157 | This is expected. |
| 158 | |
| 159 | -+What is unexpected is that it will also crash. |
| 160 | ++Unexpectedly, it also crashes. This is a bug, and the jury is |
| 161 | ++still out there how to fix it best. See ticket #314 for details. |
| 162 | |
| 163 | Contact |
| 164 | 3: bedead < -: ------- TO-UNDO |
| 165 | ------------ |
| 166 | |
| 167 | In this example, there are 3 old and 3 new commits, where the developer |
| 168 | removed the 3rd, added a new one before the first two, and modified the |
Štěpán Němec | 97509a3 | 2023-10-05 11:00:51 +0200 | [diff] [blame] | 169 | commit message of the 2nd commit as well as its diff. |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 170 | |
| 171 | When the output goes to a terminal, it is color-coded by default, just |
| 172 | like regular `git diff`'s output. In addition, the first line (adding a |
| 173 | commit) is green, the last line (deleting a commit) is red, the second |
| 174 | line (with a perfect match) is yellow like the commit header of `git |
| 175 | show`'s output, and the third line colors the old commit red, the new |
| 176 | one green and the rest like `git show`'s commit header. |
| 177 | |
Johannes Schindelin | 2752679 | 2018-08-13 04:33:30 -0700 | [diff] [blame] | 178 | A naive color-coded diff of diffs is actually a bit hard to read, |
| 179 | though, as it colors the entire lines red or green. The line that added |
| 180 | "What is unexpected" in the old commit, for example, is completely red, |
| 181 | even if the intent of the old commit was to add something. |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 182 | |
Johannes Schindelin | 2752679 | 2018-08-13 04:33:30 -0700 | [diff] [blame] | 183 | To help with that, `range` uses the `--dual-color` mode by default. In |
| 184 | this mode, the diff of diffs will retain the original diff colors, and |
| 185 | prefix the lines with -/+ markers that have their *background* red or |
| 186 | green, to make it more obvious that they describe how the diff itself |
| 187 | changed. |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 188 | |
| 189 | |
| 190 | Algorithm |
| 191 | --------- |
| 192 | |
| 193 | The general idea is this: we generate a cost matrix between the commits |
| 194 | in both commit ranges, then solve the least-cost assignment. |
| 195 | |
| 196 | The cost matrix is populated thusly: for each pair of commits, both |
| 197 | diffs are generated and the "diff of diffs" is generated, with 3 context |
| 198 | lines, then the number of lines in that diff is used as cost. |
| 199 | |
| 200 | To avoid false positives (e.g. when a patch has been removed, and an |
| 201 | unrelated patch has been added between two iterations of the same patch |
| 202 | series), the cost matrix is extended to allow for that, by adding |
| 203 | fixed-cost entries for wholesale deletes/adds. |
| 204 | |
| 205 | Example: Let commits `1--2` be the first iteration of a patch series and |
| 206 | `A--C` the second iteration. Let's assume that `A` is a cherry-pick of |
| 207 | `2,` and `C` is a cherry-pick of `1` but with a small modification (say, |
| 208 | a fixed typo). Visualize the commits as a bipartite graph: |
| 209 | |
| 210 | ------------ |
| 211 | 1 A |
| 212 | |
| 213 | 2 B |
| 214 | |
| 215 | C |
| 216 | ------------ |
| 217 | |
| 218 | We are looking for a "best" explanation of the new series in terms of |
| 219 | the old one. We can represent an "explanation" as an edge in the graph: |
| 220 | |
| 221 | |
| 222 | ------------ |
| 223 | 1 A |
| 224 | / |
| 225 | 2 --------' B |
| 226 | |
| 227 | C |
| 228 | ------------ |
| 229 | |
| 230 | This explanation comes for "free" because there was no change. Similarly |
| 231 | `C` could be explained using `1`, but that comes at some cost c>0 |
| 232 | because of the modification: |
| 233 | |
| 234 | ------------ |
| 235 | 1 ----. A |
| 236 | | / |
| 237 | 2 ----+---' B |
| 238 | | |
| 239 | `----- C |
| 240 | c>0 |
| 241 | ------------ |
| 242 | |
| 243 | In mathematical terms, what we are looking for is some sort of a minimum |
| 244 | cost bipartite matching; `1` is matched to `C` at some cost, etc. The |
| 245 | underlying graph is in fact a complete bipartite graph; the cost we |
| 246 | associate with every edge is the size of the diff between the two |
| 247 | commits' patches. To explain also new commits, we introduce dummy nodes |
| 248 | on both sides: |
| 249 | |
| 250 | ------------ |
| 251 | 1 ----. A |
| 252 | | / |
| 253 | 2 ----+---' B |
| 254 | | |
| 255 | o `----- C |
| 256 | c>0 |
| 257 | o o |
| 258 | |
| 259 | o o |
| 260 | ------------ |
| 261 | |
| 262 | The cost of an edge `o--C` is the size of `C`'s diff, modified by a |
| 263 | fudge factor that should be smaller than 100%. The cost of an edge |
| 264 | `o--o` is free. The fudge factor is necessary because even if `1` and |
| 265 | `C` have nothing in common, they may still share a few empty lines and |
| 266 | such, possibly making the assignment `1--C`, `o--o` slightly cheaper |
| 267 | than `1--o`, `o--C` even if `1` and `C` have nothing in common. With the |
| 268 | fudge factor we require a much larger common part to consider patches as |
| 269 | corresponding. |
| 270 | |
| 271 | The overall time needed to compute this algorithm is the time needed to |
| 272 | compute n+m commit diffs and then n*m diffs of patches, plus the time |
Elijah Newren | 031fd4b | 2019-11-05 17:07:20 +0000 | [diff] [blame] | 273 | needed to compute the least-cost assignment between n and m diffs. Git |
Johannes Schindelin | ba931ed | 2018-08-13 04:33:25 -0700 | [diff] [blame] | 274 | uses an implementation of the Jonker-Volgenant algorithm to solve the |
| 275 | assignment problem, which has cubic runtime complexity. The matching |
| 276 | found in this case will look like this: |
| 277 | |
| 278 | ------------ |
| 279 | 1 ----. A |
| 280 | | / |
| 281 | 2 ----+---' B |
| 282 | .--+-----' |
| 283 | o -' `----- C |
| 284 | c>0 |
| 285 | o ---------- o |
| 286 | |
| 287 | o ---------- o |
| 288 | ------------ |
| 289 | |
| 290 | |
| 291 | SEE ALSO |
| 292 | -------- |
| 293 | linkgit:git-log[1] |
| 294 | |
Johannes Schindelin | 348ae56 | 2018-08-13 04:33:02 -0700 | [diff] [blame] | 295 | GIT |
| 296 | --- |
| 297 | Part of the linkgit:git[1] suite |