git-range-diff.txt 9.3 KB

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