logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-range-diff.1 (14011B)


  1. '\" t
  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/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-RANGE\-DIFF" "1" "2025-03-14" "Git 2\&.49\&.0" "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. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-range-diff \- Compare two commit ranges (e\&.g\&. two versions of a branch)
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit range\-diff\fR [\-\-color=[<when>]] [\-\-no\-color] [<diff\-options>]
  36. [\-\-no\-dual\-color] [\-\-creation\-factor=<factor>]
  37. [\-\-left\-only | \-\-right\-only] [\-\-diff\-merges=<format>]
  38. [\-\-remerge\-diff]
  39. ( <range1> <range2> | <rev1>\&...\:<rev2> | <base> <rev1> <rev2> )
  40. [[\-\-] <path>\&...\:]
  41. .fi
  42. .SH "DESCRIPTION"
  43. .sp
  44. This command shows the differences between two versions of a patch series, or more generally, two commit ranges (ignoring merge commits)\&.
  45. .sp
  46. In the presence of \fI<path>\fR arguments, these commit ranges are limited accordingly\&.
  47. .sp
  48. 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. .sp
  50. 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. .sp
  52. There are three ways to specify the commit ranges:
  53. .sp
  54. .RS 4
  55. .ie n \{\
  56. \h'-04'\(bu\h'+03'\c
  57. .\}
  58. .el \{\
  59. .sp -1
  60. .IP \(bu 2.3
  61. .\}
  62. \fI<range1>\fR
  63. \fI<range2>\fR: Either commit range can be of the form
  64. \fI<base>\fR\fB\&.\&.\fR\fI<rev>\fR,
  65. \fI<rev>\fR\fB^\fR! or
  66. \fI<rev>\fR\fB^\-\fR\fI<n>\fR\&. See
  67. \fBSPECIFYING\fR
  68. \fBRANGES\fR
  69. in
  70. \fBgitrevisions\fR(7)
  71. for more details\&.
  72. .RE
  73. .sp
  74. .RS 4
  75. .ie n \{\
  76. \h'-04'\(bu\h'+03'\c
  77. .\}
  78. .el \{\
  79. .sp -1
  80. .IP \(bu 2.3
  81. .\}
  82. \fI<rev1>\fR\fB\&.\&.\&.\fR\fI<rev2>\fR\&. This is equivalent to
  83. \fI<rev2>\fR\fB\&.\&.\fR\fI<rev1>\fR
  84. \fI<rev1>\fR\fB\&.\&.\fR\fI<rev2>\fR\&.
  85. .RE
  86. .sp
  87. .RS 4
  88. .ie n \{\
  89. \h'-04'\(bu\h'+03'\c
  90. .\}
  91. .el \{\
  92. .sp -1
  93. .IP \(bu 2.3
  94. .\}
  95. \fI<base>\fR
  96. \fI<rev1>\fR
  97. \fI<rev2>\fR: This is equivalent to
  98. \fI<base>\fR\fB\&.\&.\fR\fI<rev1>\fR
  99. \fI<base>\fR\fB\&.\&.\fR\fI<rev2>\fR\&.
  100. .RE
  101. .SH "OPTIONS"
  102. .PP
  103. \-\-no\-dual\-color
  104. .RS 4
  105. When the commit diffs differ,
  106. \fBgit\fR
  107. \fBrange\-diff\fR
  108. recreates the original diffs\*(Aq coloring, and adds outer \-/+ diff markers with the
  109. \fBbackground\fR
  110. being red/green to make it easier to see e\&.g\&. when there was a change in what exact lines were added\&.
  111. .sp
  112. Additionally, the commit diff lines that are only present in the first commit range are shown "dimmed" (this can be overridden using the
  113. \fBcolor\&.diff\&.\fR\fI<slot>\fR
  114. config setting where
  115. \fI<slot>\fR
  116. is one of
  117. \fBcontextDimmed\fR,
  118. \fBoldDimmed\fR
  119. and
  120. \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
  121. \fBcolor\&.diff\&.\fR\fI<slot>\fR
  122. with
  123. \fI<slot>\fR
  124. being one of
  125. \fBcontextBold\fR,
  126. \fBoldBold\fR
  127. or
  128. \fBnewBold\fR)\&.
  129. .sp
  130. This is known to
  131. \fBrange\-diff\fR
  132. as "dual coloring"\&. Use
  133. \fB\-\-no\-dual\-color\fR
  134. to revert to color all lines according to the outer diff markers (and completely ignore the inner diff when it comes to color)\&.
  135. .RE
  136. .PP
  137. \-\-creation\-factor=<percent>
  138. .RS 4
  139. Set the creation/deletion cost fudge factor to
  140. \fI<percent>\fR\&. Defaults to 60\&. Try a larger value if
  141. \fBgit\fR
  142. \fBrange\-diff\fR
  143. 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\&.
  144. .RE
  145. .PP
  146. \-\-left\-only
  147. .RS 4
  148. Suppress commits that are missing from the first specified range (or the "left range" when using the
  149. \fI<rev1>\fR\fB\&.\&.\&.\fR\fI<rev2>\fR
  150. format)\&.
  151. .RE
  152. .PP
  153. \-\-right\-only
  154. .RS 4
  155. Suppress commits that are missing from the second specified range (or the "right range" when using the
  156. \fI<rev1>\fR\fB\&.\&.\&.\fR\fI<rev2>\fR
  157. format)\&.
  158. .RE
  159. .PP
  160. \-\-diff\-merges=<format>
  161. .RS 4
  162. Instead of ignoring merge commits, generate diffs for them using the corresponding
  163. \fB\-\-diff\-merges=\fR\fI<format>\fR
  164. option of
  165. \fBgit-log\fR(1), and include them in the comparison\&.
  166. .sp
  167. Note: In the common case, the
  168. \fBremerge\fR
  169. mode will be the most natural one to use, as it shows only the diff on top of what Git\(cqs merge machinery would have produced\&. In other words, if a merge commit is the result of a non\-conflicting
  170. \fBgit\fR
  171. \fBmerge\fR, the
  172. \fBremerge\fR
  173. mode will represent it with an empty diff\&.
  174. .RE
  175. .PP
  176. \-\-remerge\-diff
  177. .RS 4
  178. Convenience option, equivalent to
  179. \fB\-\-diff\-merges=remerge\fR\&.
  180. .RE
  181. .PP
  182. \-\-[no\-]notes[=<ref>]
  183. .RS 4
  184. This flag is passed to the
  185. \fBgit\fR
  186. \fBlog\fR
  187. program (see
  188. \fBgit-log\fR(1)) that generates the patches\&.
  189. .RE
  190. .PP
  191. <range1> <range2>
  192. .RS 4
  193. Compare the commits specified by the two ranges, where
  194. \fI<range1>\fR
  195. is considered an older version of
  196. \fI<range2>\fR\&.
  197. .RE
  198. .PP
  199. <rev1>\&...\:<rev2>
  200. .RS 4
  201. Equivalent to passing
  202. \fI<rev2>\fR\fB\&.\&.\fR\fI<rev1>\fR
  203. and
  204. \fI<rev1>\fR\fB\&.\&.\fR\fI<rev2>\fR\&.
  205. .RE
  206. .PP
  207. <base> <rev1> <rev2>
  208. .RS 4
  209. Equivalent to passing
  210. \fI<base>\fR\fB\&.\&.\fR\fI<rev1>\fR
  211. and
  212. \fI<base>\fR\fB\&.\&.\fR\fI<rev2>\fR\&. Note that
  213. \fI<base>\fR
  214. does not need to be the exact branch point of the branches\&. Example: after rebasing a branch
  215. \fBmy\-topic\fR,
  216. \fBgit\fR
  217. \fBrange\-diff\fR
  218. \fBmy\-topic@\fR{u}
  219. \fBmy\-topic@\fR{1}
  220. \fBmy\-topic\fR
  221. would show the differences introduced by the rebase\&.
  222. .RE
  223. .sp
  224. \fBgit\fR \fBrange\-diff\fR also accepts the regular diff options (see \fBgit-diff\fR(1)), most notably the \fB\-\-color=\fR[\fI<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\fR \fBlog\fR when generating those patches\&.
  225. .SH "OUTPUT STABILITY"
  226. .sp
  227. 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\&.
  228. .sp
  229. 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)\&.
  230. .SH "CONFIGURATION"
  231. .sp
  232. This command uses the \fBdiff\&.color\&.\fR* and \fBpager\&.range\-diff\fR settings (the latter is on by default)\&. See \fBgit-config\fR(1)\&.
  233. .SH "EXAMPLES"
  234. .sp
  235. When a rebase required merge conflicts to be resolved, compare the changes introduced by the rebase directly afterwards using:
  236. .sp
  237. .if n \{\
  238. .RS 4
  239. .\}
  240. .nf
  241. $ git range\-diff @{u} @{1} @
  242. .fi
  243. .if n \{\
  244. .RE
  245. .\}
  246. .sp
  247. A typical output of \fBgit\fR \fBrange\-diff\fR would look like this:
  248. .sp
  249. .if n \{\
  250. .RS 4
  251. .\}
  252. .nf
  253. \-: \-\-\-\-\-\-\- > 1: 0ddba11 Prepare for the inevitable!
  254. 1: c0debee = 2: cab005e Add a helpful message at the start
  255. 2: f00dbal ! 3: decafe1 Describe a bug
  256. @@ \-1,3 +1,3 @@
  257. Author: A U Thor <author@example\&.com>
  258. \-TODO: Describe a bug
  259. +Describe a bug
  260. @@ \-324,5 +324,6
  261. This is expected\&.
  262. \-+What is unexpected is that it will also crash\&.
  263. ++Unexpectedly, it also crashes\&. This is a bug, and the jury is
  264. ++still out there how to fix it best\&. See ticket #314 for details\&.
  265. Contact
  266. 3: bedead < \-: \-\-\-\-\-\-\- TO\-UNDO
  267. .fi
  268. .if n \{\
  269. .RE
  270. .\}
  271. .sp
  272. 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\&.
  273. .sp
  274. When the output goes to a terminal, it is color\-coded by default, just like regular \fBgit\fR \fBdiff\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\fR \fBshow\fR\*(Aqs output, and the third line colors the old commit red, the new one green and the rest like \fBgit\fR \fBshow\fR\*(Aqs commit header\&.
  275. .sp
  276. 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\&.
  277. .sp
  278. 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\&.
  279. .SH "ALGORITHM"
  280. .sp
  281. The general idea is this: we generate a cost matrix between the commits in both commit ranges, then solve the least\-cost assignment\&.
  282. .sp
  283. 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\&.
  284. .sp
  285. 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\&.
  286. .sp
  287. 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:
  288. .sp
  289. .if n \{\
  290. .RS 4
  291. .\}
  292. .nf
  293. 1 A
  294. 2 B
  295. C
  296. .fi
  297. .if n \{\
  298. .RE
  299. .\}
  300. .sp
  301. 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:
  302. .sp
  303. .if n \{\
  304. .RS 4
  305. .\}
  306. .nf
  307. 1 A
  308. /
  309. 2 \-\-\-\-\-\-\-\-\*(Aq B
  310. C
  311. .fi
  312. .if n \{\
  313. .RE
  314. .\}
  315. .sp
  316. 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:
  317. .sp
  318. .if n \{\
  319. .RS 4
  320. .\}
  321. .nf
  322. 1 \-\-\-\-\&. A
  323. | /
  324. 2 \-\-\-\-+\-\-\-\*(Aq B
  325. |
  326. `\-\-\-\-\- C
  327. c>0
  328. .fi
  329. .if n \{\
  330. .RE
  331. .\}
  332. .sp
  333. 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:
  334. .sp
  335. .if n \{\
  336. .RS 4
  337. .\}
  338. .nf
  339. 1 \-\-\-\-\&. A
  340. | /
  341. 2 \-\-\-\-+\-\-\-\*(Aq B
  342. |
  343. o `\-\-\-\-\- C
  344. c>0
  345. o o
  346. o o
  347. .fi
  348. .if n \{\
  349. .RE
  350. .\}
  351. .sp
  352. 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\&.
  353. .sp
  354. 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:
  355. .sp
  356. .if n \{\
  357. .RS 4
  358. .\}
  359. .nf
  360. 1 \-\-\-\-\&. A
  361. | /
  362. 2 \-\-\-\-+\-\-\-\*(Aq B
  363. \&.\-\-+\-\-\-\-\-\*(Aq
  364. o \-\*(Aq `\-\-\-\-\- C
  365. c>0
  366. o \-\-\-\-\-\-\-\-\-\- o
  367. o \-\-\-\-\-\-\-\-\-\- o
  368. .fi
  369. .if n \{\
  370. .RE
  371. .\}
  372. .SH "SEE ALSO"
  373. .sp
  374. \fBgit-log\fR(1)
  375. .SH "GIT"
  376. .sp
  377. Part of the \fBgit\fR(1) suite