1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\r
6 <meta name="generator" content="AsciiDoc 7.0.1" />
\r
7 <style type="text/css">
\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
\r
11 border: 1px solid red;
\r
16 margin: 1em 5% 1em 5%;
\r
20 a:visited { color: fuchsia; }
\r
34 h1, h2, h3, h4, h5, h6 {
\r
36 font-family: sans-serif;
\r
38 margin-bottom: 0.5em;
\r
43 border-bottom: 2px solid silver;
\r
46 border-bottom: 2px solid silver;
\r
56 border: 1px solid silver;
\r
61 margin-bottom: 0.5em;
\r
71 font-family: sans-serif;
\r
78 font-family: sans-serif;
\r
82 font-family: sans-serif;
\r
84 border-top: 2px solid silver;
\r
90 padding-bottom: 0.5em;
\r
94 padding-bottom: 0.5em;
\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
100 div.admonitionblock {
\r
103 margin-bottom: 1.5em;
\r
105 div.admonitionblock {
\r
107 margin-bottom: 2.5em;
\r
110 div.content { /* Block element content. */
\r
114 /* Block element titles. */
\r
115 div.title, caption.title {
\r
116 font-family: sans-serif;
\r
120 margin-bottom: 0.5em;
\r
126 td div.title:first-child {
\r
129 div.content div.title:first-child {
\r
132 div.content + div.title {
\r
136 div.sidebarblock > div.content {
\r
137 background: #ffffee;
\r
138 border: 1px solid silver;
\r
142 div.listingblock > div.content {
\r
143 border: 1px solid silver;
\r
144 background: #f4f4f4;
\r
148 div.quoteblock > div.content {
\r
149 padding-left: 2.0em;
\r
151 div.quoteblock .attribution {
\r
155 div.admonitionblock .icon {
\r
156 vertical-align: top;
\r
159 text-decoration: underline;
\r
161 padding-right: 0.5em;
\r
163 div.admonitionblock td.content {
\r
164 padding-left: 0.5em;
\r
165 border-left: 2px solid silver;
\r
168 div.exampleblock > div.content {
\r
169 border-left: 2px solid silver;
\r
173 div.verseblock div.content {
\r
177 div.imageblock div.content { padding-left: 0; }
\r
178 div.imageblock img { border: 1px solid silver; }
\r
179 span.image img { border-style: none; }
\r
183 margin-bottom: 0.8em;
\r
188 font-style: italic;
\r
190 dd > *:first-child {
\r
195 list-style-position: outside;
\r
198 list-style-type: lower-alpha;
\r
201 div.tableblock > table {
\r
202 border-color: #527bbd;
\r
206 font-family: sans-serif;
\r
215 margin-bottom: 0.8em;
\r
218 vertical-align: top;
\r
219 font-style: italic;
\r
220 padding-right: 0.8em;
\r
223 vertical-align: top;
\r
227 div#footer-badges { display: none; }
\r
229 /* Workarounds for IE6's broken and incomplete CSS2. */
\r
231 div.sidebar-content {
\r
232 background: #ffffee;
\r
233 border: 1px solid silver;
\r
236 div.sidebar-title, div.image-title {
\r
237 font-family: sans-serif;
\r
240 margin-bottom: 0.5em;
\r
243 div.listingblock div.content {
\r
244 border: 1px solid silver;
\r
245 background: #f4f4f4;
\r
249 div.quoteblock-content {
\r
250 padding-left: 2.0em;
\r
253 div.exampleblock-content {
\r
254 border-left: 2px solid silver;
\r
255 padding-left: 0.5em;
\r
258 <title>Tweaking diff output</title>
\r
262 <h1>Tweaking diff output</h1>
\r
263 <span id="author">June 2005</span><br />
\r
265 <h2>Introduction</h2>
\r
266 <div class="sectionbody">
\r
267 <p>The diff commands git-diff-index, git-diff-files, git-diff-tree, and
\r
268 git-diff-stages can be told to manipulate differences they find in
\r
269 unconventional ways before showing diff(1) output. The manipulation
\r
270 is collectively called "diffcore transformation". This short note
\r
271 describes what they are and how to use them to produce diff outputs
\r
272 that are easier to understand than the conventional kind.</p>
\r
274 <h2>The chain of operation</h2>
\r
275 <div class="sectionbody">
\r
276 <p>The git-diff-* family works by first comparing two sets of
\r
281 git-diff-index compares contents of a "tree" object and the
\r
282 working directory (when <em>--cached</em> flag is not used) or a
\r
283 "tree" object and the index file (when <em>--cached</em> flag is
\r
289 git-diff-files compares contents of the index file and the
\r
295 git-diff-tree compares contents of two "tree" objects;
\r
300 git-diff-stages compares contents of blobs at two stages in an
\r
301 unmerged index file.
\r
305 <p>In all of these cases, the commands themselves compare
\r
306 corresponding paths in the two sets of files. The result of
\r
307 comparison is passed from these commands to what is internally
\r
308 called "diffcore", in a format similar to what is output when
\r
309 the -p option is not used. E.g.</p>
\r
310 <div class="listingblock">
\r
311 <div class="content">
\r
312 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
\r
313 create :000000 100644 0000000... 1234567... A file4
\r
314 delete :100644 000000 1234567... 0000000... D file5
\r
315 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
\r
317 <p>The diffcore mechanism is fed a list of such comparison results
\r
318 (each of which is called "filepair", although at this point each
\r
319 of them talks about a single file), and transforms such a list
\r
320 into another list. There are currently 6 such transformations:</p>
\r
339 diffcore-merge-broken
\r
353 <p>These are applied in sequence. The set of filepairs git-diff-*
\r
354 commands find are used as the input to diffcore-pathspec, and
\r
355 the output from diffcore-pathspec is used as the input to the
\r
356 next transformation. The final result is then passed to the
\r
357 output routine and generates either diff-raw format (see Output
\r
358 format sections of the manual for git-diff-* commands) or
\r
359 diff-patch format.</p>
\r
361 <h2>diffcore-pathspec: For Ignoring Files Outside Our Consideration</h2>
\r
362 <div class="sectionbody">
\r
363 <p>The first transformation in the chain is diffcore-pathspec, and
\r
364 is controlled by giving the pathname parameters to the
\r
365 git-diff-* commands on the command line. The pathspec is used
\r
366 to limit the world diff operates in. It removes the filepairs
\r
367 outside the specified set of pathnames. E.g. If the input set
\r
368 of filepairs included:</p>
\r
369 <div class="listingblock">
\r
370 <div class="content">
\r
371 <pre><tt>:100644 100644 bcd1234... 0123456... M junkfile</tt></pre>
\r
373 <p>but the command invocation was "git-diff-files myfile", then the
\r
374 junkfile entry would be removed from the list because only "myfile"
\r
375 is under consideration.</p>
\r
376 <p>Implementation note. For performance reasons, git-diff-tree
\r
377 uses the pathname parameters on the command line to cull set of
\r
378 filepairs it feeds the diffcore mechanism itself, and does not
\r
379 use diffcore-pathspec, but the end result is the same.</p>
\r
381 <h2>diffcore-break: For Splitting Up "Complete Rewrites"</h2>
\r
382 <div class="sectionbody">
\r
383 <p>The second transformation in the chain is diffcore-break, and is
\r
384 controlled by the -B option to the git-diff-* commands. This is
\r
385 used to detect a filepair that represents "complete rewrite" and
\r
386 break such filepair into two filepairs that represent delete and
\r
387 create. E.g. If the input contained this filepair:</p>
\r
388 <div class="listingblock">
\r
389 <div class="content">
\r
390 <pre><tt>:100644 100644 bcd1234... 0123456... M file0</tt></pre>
\r
392 <p>and if it detects that the file "file0" is completely rewritten,
\r
393 it changes it to:</p>
\r
394 <div class="listingblock">
\r
395 <div class="content">
\r
396 <pre><tt>:100644 000000 bcd1234... 0000000... D file0
\r
397 :000000 100644 0000000... 0123456... A file0</tt></pre>
\r
399 <p>For the purpose of breaking a filepair, diffcore-break examines
\r
400 the extent of changes between the contents of the files before
\r
401 and after modification (i.e. the contents that have "bcd1234…"
\r
402 and "0123456…" as their SHA1 content ID, in the above
\r
403 example). The amount of deletion of original contents and
\r
404 insertion of new material are added together, and if it exceeds
\r
405 the "break score", the filepair is broken into two. The break
\r
406 score defaults to 50% of the size of the smaller of the original
\r
407 and the result (i.e. if the edit shrinks the file, the size of
\r
408 the result is used; if the edit lengthens the file, the size of
\r
409 the original is used), and can be customized by giving a number
\r
410 after "-B" option (e.g. "-B75" to tell it to use 75%).</p>
\r
412 <h2>diffcore-rename: For Detection Renames and Copies</h2>
\r
413 <div class="sectionbody">
\r
414 <p>This transformation is used to detect renames and copies, and is
\r
415 controlled by the -M option (to detect renames) and the -C option
\r
416 (to detect copies as well) to the git-diff-* commands. If the
\r
417 input contained these filepairs:</p>
\r
418 <div class="listingblock">
\r
419 <div class="content">
\r
420 <pre><tt>:100644 000000 0123456... 0000000... D fileX
\r
421 :000000 100644 0000000... 0123456... A file0</tt></pre>
\r
423 <p>and the contents of the deleted file fileX is similar enough to
\r
424 the contents of the created file file0, then rename detection
\r
425 merges these filepairs and creates:</p>
\r
426 <div class="listingblock">
\r
427 <div class="content">
\r
428 <pre><tt>:100644 100644 0123456... 0123456... R100 fileX file0</tt></pre>
\r
430 <p>When the "-C" option is used, the original contents of modified files,
\r
431 and deleted files (and also unmodified files, if the
\r
432 "--find-copies-harder" option is used) are considered as candidates
\r
433 of the source files in rename/copy operation. If the input were like
\r
434 these filepairs, that talk about a modified file fileY and a newly
\r
435 created file file0:</p>
\r
436 <div class="listingblock">
\r
437 <div class="content">
\r
438 <pre><tt>:100644 100644 0123456... 1234567... M fileY
\r
439 :000000 100644 0000000... bcd3456... A file0</tt></pre>
\r
441 <p>the original contents of fileY and the resulting contents of
\r
442 file0 are compared, and if they are similar enough, they are
\r
444 <div class="listingblock">
\r
445 <div class="content">
\r
446 <pre><tt>:100644 100644 0123456... 1234567... M fileY
\r
447 :100644 100644 0123456... bcd3456... C100 fileY file0</tt></pre>
\r
449 <p>In both rename and copy detection, the same "extent of changes"
\r
450 algorithm used in diffcore-break is used to determine if two
\r
451 files are "similar enough", and can be customized to use
\r
452 a similarity score different from the default of 50% by giving a
\r
453 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use
\r
455 <p>Note. When the "-C" option is used with <tt>--find-copies-harder</tt>
\r
456 option, git-diff-* commands feed unmodified filepairs to
\r
457 diffcore mechanism as well as modified ones. This lets the copy
\r
458 detector consider unmodified files as copy source candidates at
\r
459 the expense of making it slower. Without <tt>--find-copies-harder</tt>,
\r
460 git-diff-* commands can detect copies only if the file that was
\r
461 copied happened to have been modified in the same changeset.</p>
\r
463 <h2>diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</h2>
\r
464 <div class="sectionbody">
\r
465 <p>This transformation is used to merge filepairs broken by
\r
466 diffcore-break, and not transformed into rename/copy by
\r
467 diffcore-rename, back into a single modification. This always
\r
468 runs when diffcore-break is used.</p>
\r
469 <p>For the purpose of merging broken filepairs back, it uses a
\r
470 different "extent of changes" computation from the ones used by
\r
471 diffcore-break and diffcore-rename. It counts only the deletion
\r
472 from the original, and does not count insertion. If you removed
\r
473 only 10 lines from a 100-line document, even if you added 910
\r
474 new lines to make a new 1000-line document, you did not do a
\r
475 complete rewrite. diffcore-break breaks such a case in order to
\r
476 help diffcore-rename to consider such filepairs as candidate of
\r
477 rename/copy detection, but if filepairs broken that way were not
\r
478 matched with other filepairs to create rename/copy, then this
\r
479 transformation merges them back into the original
\r
480 "modification".</p>
\r
481 <p>The "extent of changes" parameter can be tweaked from the
\r
482 default 80% (that is, unless more than 80% of the original
\r
483 material is deleted, the broken pairs are merged back into a
\r
484 single modification) by giving a second number to -B option,
\r
489 -B50/60 (give 50% "break score" to diffcore-break, use 60%
\r
490 for diffcore-merge-broken).
\r
495 -B/60 (the same as above, since diffcore-break defaults to 50%).
\r
499 <p>Note that earlier implementation left a broken pair as a separate
\r
500 creation and deletion patches. This was an unnecessary hack and
\r
501 the latest implementation always merges all the broken pairs
\r
502 back into modifications, but the resulting patch output is
\r
503 formatted differently for easier review in case of such
\r
504 a complete rewrite by showing the entire contents of old version
\r
505 prefixed with <em>-</em>, followed by the entire contents of new
\r
506 version prefixed with <em>+</em>.</p>
\r
508 <h2>diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</h2>
\r
509 <div class="sectionbody">
\r
510 <p>This transformation is used to find filepairs that represent
\r
511 changes that touch a specified string, and is controlled by the
\r
512 -S option and the <tt>--pickaxe-all</tt> option to the git-diff-*
\r
514 <p>When diffcore-pickaxe is in use, it checks if there are
\r
515 filepairs whose "original" side has the specified string and
\r
516 whose "result" side does not. Such a filepair represents "the
\r
517 string appeared in this changeset". It also checks for the
\r
518 opposite case that loses the specified string.</p>
\r
519 <p>When <tt>--pickaxe-all</tt> is not in effect, diffcore-pickaxe leaves
\r
520 only such filepairs that touch the specified string in its
\r
521 output. When <tt>--pickaxe-all</tt> is used, diffcore-pickaxe leaves all
\r
522 filepairs intact if there is such a filepair, or makes the
\r
523 output empty otherwise. The latter behaviour is designed to
\r
524 make reviewing of the changes in the context of the whole
\r
525 changeset easier.</p>
\r
527 <h2>diffcore-order: For Sorting the Output Based on Filenames</h2>
\r
528 <div class="sectionbody">
\r
529 <p>This is used to reorder the filepairs according to the user's
\r
530 (or project's) taste, and is controlled by the -O option to the
\r
531 git-diff-* commands.</p>
\r
532 <p>This takes a text file each of whose lines is a shell glob
\r
533 pattern. Filepairs that match a glob pattern on an earlier line
\r
534 in the file are output before ones that match a later line, and
\r
535 filepairs that do not match any glob pattern are output last.</p>
\r
536 <p>As an example, a typical orderfile for the core git probably
\r
537 would look like this:</p>
\r
538 <div class="listingblock">
\r
539 <div class="content">
\r
549 <div id="footer-text">
\r
550 Last updated 27-Dec-2005 00:17:07 PDT
\r