Autogenerated HTML docs for v1.7.6-396-ge0613
[git/jnareb-git.git] / gitdiffcore.html
blob01f4e0513fe4e63e20558d3bc99e186ded64dc05
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.4.5" />
7 <title>gitdiffcore(7)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 gitdiffcore(7) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>gitdiffcore -
411 Tweaking diff output
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="verseblock">
418 <div class="verseblock-content"><em>git diff</em> *</div>
419 <div class="verseblock-attribution">
420 </div></div>
421 </div>
422 <h2 id="_description">DESCRIPTION</h2>
423 <div class="sectionbody">
424 <div class="paragraph"><p>The diff commands <em>git diff-index</em>, <em>git diff-files</em>, and <em>git diff-tree</em>
425 can be told to manipulate differences they find in
426 unconventional ways before showing <em>diff</em> output. The manipulation
427 is collectively called "diffcore transformation". This short note
428 describes what they are and how to use them to produce <em>diff</em> output
429 that is easier to understand than the conventional kind.</p></div>
430 </div>
431 <h2 id="_the_chain_of_operation">The chain of operation</h2>
432 <div class="sectionbody">
433 <div class="paragraph"><p>The <em>git diff-&#42;</em> family works by first comparing two sets of
434 files:</p></div>
435 <div class="ulist"><ul>
436 <li>
438 <em>git diff-index</em> compares contents of a "tree" object and the
439 working directory (when <em>--cached</em> flag is not used) or a
440 "tree" object and the index file (when <em>--cached</em> flag is
441 used);
442 </p>
443 </li>
444 <li>
446 <em>git diff-files</em> compares contents of the index file and the
447 working directory;
448 </p>
449 </li>
450 <li>
452 <em>git diff-tree</em> compares contents of two "tree" objects;
453 </p>
454 </li>
455 </ul></div>
456 <div class="paragraph"><p>In all of these cases, the commands themselves first optionally limit
457 the two sets of files by any pathspecs given on their command-lines,
458 and compare corresponding paths in the two resulting sets of files.</p></div>
459 <div class="paragraph"><p>The pathspecs are used to limit the world diff operates in. They remove
460 the filepairs outside the specified sets of pathnames. E.g. If the
461 input set of filepairs included:</p></div>
462 <div class="listingblock">
463 <div class="content">
464 <pre><tt>:100644 100644 bcd1234... 0123456... M junkfile</tt></pre>
465 </div></div>
466 <div class="paragraph"><p>but the command invocation was <tt>git diff-files myfile</tt>, then the
467 junkfile entry would be removed from the list because only "myfile"
468 is under consideration.</p></div>
469 <div class="paragraph"><p>The result of comparison is passed from these commands to what is
470 internally called "diffcore", in a format similar to what is output
471 when the -p option is not used. E.g.</p></div>
472 <div class="listingblock">
473 <div class="content">
474 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
475 create :000000 100644 0000000... 1234567... A file4
476 delete :100644 000000 1234567... 0000000... D file5
477 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
478 </div></div>
479 <div class="paragraph"><p>The diffcore mechanism is fed a list of such comparison results
480 (each of which is called "filepair", although at this point each
481 of them talks about a single file), and transforms such a list
482 into another list. There are currently 5 such transformations:</p></div>
483 <div class="ulist"><ul>
484 <li>
486 diffcore-break
487 </p>
488 </li>
489 <li>
491 diffcore-rename
492 </p>
493 </li>
494 <li>
496 diffcore-merge-broken
497 </p>
498 </li>
499 <li>
501 diffcore-pickaxe
502 </p>
503 </li>
504 <li>
506 diffcore-order
507 </p>
508 </li>
509 </ul></div>
510 <div class="paragraph"><p>These are applied in sequence. The set of filepairs <em>git diff-&#42;</em>
511 commands find are used as the input to diffcore-break, and
512 the output from diffcore-break is used as the input to the
513 next transformation. The final result is then passed to the
514 output routine and generates either diff-raw format (see Output
515 format sections of the manual for <em>git diff-&#42;</em> commands) or
516 diff-patch format.</p></div>
517 </div>
518 <h2 id="_diffcore_break_for_splitting_up_complete_rewrites">diffcore-break: For Splitting Up "Complete Rewrites"</h2>
519 <div class="sectionbody">
520 <div class="paragraph"><p>The second transformation in the chain is diffcore-break, and is
521 controlled by the -B option to the <em>git diff-&#42;</em> commands. This is
522 used to detect a filepair that represents "complete rewrite" and
523 break such filepair into two filepairs that represent delete and
524 create. E.g. If the input contained this filepair:</p></div>
525 <div class="listingblock">
526 <div class="content">
527 <pre><tt>:100644 100644 bcd1234... 0123456... M file0</tt></pre>
528 </div></div>
529 <div class="paragraph"><p>and if it detects that the file "file0" is completely rewritten,
530 it changes it to:</p></div>
531 <div class="listingblock">
532 <div class="content">
533 <pre><tt>:100644 000000 bcd1234... 0000000... D file0
534 :000000 100644 0000000... 0123456... A file0</tt></pre>
535 </div></div>
536 <div class="paragraph"><p>For the purpose of breaking a filepair, diffcore-break examines
537 the extent of changes between the contents of the files before
538 and after modification (i.e. the contents that have "bcd1234&#8230;"
539 and "0123456&#8230;" as their SHA1 content ID, in the above
540 example). The amount of deletion of original contents and
541 insertion of new material are added together, and if it exceeds
542 the "break score", the filepair is broken into two. The break
543 score defaults to 50% of the size of the smaller of the original
544 and the result (i.e. if the edit shrinks the file, the size of
545 the result is used; if the edit lengthens the file, the size of
546 the original is used), and can be customized by giving a number
547 after "-B" option (e.g. "-B75" to tell it to use 75%).</p></div>
548 </div>
549 <h2 id="_diffcore_rename_for_detection_renames_and_copies">diffcore-rename: For Detection Renames and Copies</h2>
550 <div class="sectionbody">
551 <div class="paragraph"><p>This transformation is used to detect renames and copies, and is
552 controlled by the -M option (to detect renames) and the -C option
553 (to detect copies as well) to the <em>git diff-&#42;</em> commands. If the
554 input contained these filepairs:</p></div>
555 <div class="listingblock">
556 <div class="content">
557 <pre><tt>:100644 000000 0123456... 0000000... D fileX
558 :000000 100644 0000000... 0123456... A file0</tt></pre>
559 </div></div>
560 <div class="paragraph"><p>and the contents of the deleted file fileX is similar enough to
561 the contents of the created file file0, then rename detection
562 merges these filepairs and creates:</p></div>
563 <div class="listingblock">
564 <div class="content">
565 <pre><tt>:100644 100644 0123456... 0123456... R100 fileX file0</tt></pre>
566 </div></div>
567 <div class="paragraph"><p>When the "-C" option is used, the original contents of modified files,
568 and deleted files (and also unmodified files, if the
569 "--find-copies-harder" option is used) are considered as candidates
570 of the source files in rename/copy operation. If the input were like
571 these filepairs, that talk about a modified file fileY and a newly
572 created file file0:</p></div>
573 <div class="listingblock">
574 <div class="content">
575 <pre><tt>:100644 100644 0123456... 1234567... M fileY
576 :000000 100644 0000000... bcd3456... A file0</tt></pre>
577 </div></div>
578 <div class="paragraph"><p>the original contents of fileY and the resulting contents of
579 file0 are compared, and if they are similar enough, they are
580 changed to:</p></div>
581 <div class="listingblock">
582 <div class="content">
583 <pre><tt>:100644 100644 0123456... 1234567... M fileY
584 :100644 100644 0123456... bcd3456... C100 fileY file0</tt></pre>
585 </div></div>
586 <div class="paragraph"><p>In both rename and copy detection, the same "extent of changes"
587 algorithm used in diffcore-break is used to determine if two
588 files are "similar enough", and can be customized to use
589 a similarity score different from the default of 50% by giving a
590 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use
591 8/10 = 80%).</p></div>
592 <div class="paragraph"><p>Note. When the "-C" option is used with <tt>--find-copies-harder</tt>
593 option, <em>git diff-&#42;</em> commands feed unmodified filepairs to
594 diffcore mechanism as well as modified ones. This lets the copy
595 detector consider unmodified files as copy source candidates at
596 the expense of making it slower. Without <tt>--find-copies-harder</tt>,
597 <em>git diff-&#42;</em> commands can detect copies only if the file that was
598 copied happened to have been modified in the same changeset.</p></div>
599 </div>
600 <h2 id="_diffcore_merge_broken_for_putting_complete_rewrites_back_together">diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</h2>
601 <div class="sectionbody">
602 <div class="paragraph"><p>This transformation is used to merge filepairs broken by
603 diffcore-break, and not transformed into rename/copy by
604 diffcore-rename, back into a single modification. This always
605 runs when diffcore-break is used.</p></div>
606 <div class="paragraph"><p>For the purpose of merging broken filepairs back, it uses a
607 different "extent of changes" computation from the ones used by
608 diffcore-break and diffcore-rename. It counts only the deletion
609 from the original, and does not count insertion. If you removed
610 only 10 lines from a 100-line document, even if you added 910
611 new lines to make a new 1000-line document, you did not do a
612 complete rewrite. diffcore-break breaks such a case in order to
613 help diffcore-rename to consider such filepairs as candidate of
614 rename/copy detection, but if filepairs broken that way were not
615 matched with other filepairs to create rename/copy, then this
616 transformation merges them back into the original
617 "modification".</p></div>
618 <div class="paragraph"><p>The "extent of changes" parameter can be tweaked from the
619 default 80% (that is, unless more than 80% of the original
620 material is deleted, the broken pairs are merged back into a
621 single modification) by giving a second number to -B option,
622 like these:</p></div>
623 <div class="ulist"><ul>
624 <li>
626 -B50/60 (give 50% "break score" to diffcore-break, use 60%
627 for diffcore-merge-broken).
628 </p>
629 </li>
630 <li>
632 -B/60 (the same as above, since diffcore-break defaults to 50%).
633 </p>
634 </li>
635 </ul></div>
636 <div class="paragraph"><p>Note that earlier implementation left a broken pair as a separate
637 creation and deletion patches. This was an unnecessary hack and
638 the latest implementation always merges all the broken pairs
639 back into modifications, but the resulting patch output is
640 formatted differently for easier review in case of such
641 a complete rewrite by showing the entire contents of old version
642 prefixed with <em>-</em>, followed by the entire contents of new
643 version prefixed with <em>+</em>.</p></div>
644 </div>
645 <h2 id="_diffcore_pickaxe_for_detecting_addition_deletion_of_specified_string">diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</h2>
646 <div class="sectionbody">
647 <div class="paragraph"><p>This transformation is used to find filepairs that represent
648 changes that touch a specified string, and is controlled by the
649 -S option and the <tt>--pickaxe-all</tt> option to the <em>git diff-&#42;</em>
650 commands.</p></div>
651 <div class="paragraph"><p>When diffcore-pickaxe is in use, it checks if there are
652 filepairs whose "result" side and whose "origin" side have
653 different number of specified string. Such a filepair represents
654 "the string appeared in this changeset". It also checks for the
655 opposite case that loses the specified string.</p></div>
656 <div class="paragraph"><p>When <tt>--pickaxe-all</tt> is not in effect, diffcore-pickaxe leaves
657 only such filepairs that touch the specified string in its
658 output. When <tt>--pickaxe-all</tt> is used, diffcore-pickaxe leaves all
659 filepairs intact if there is such a filepair, or makes the
660 output empty otherwise. The latter behaviour is designed to
661 make reviewing of the changes in the context of the whole
662 changeset easier.</p></div>
663 </div>
664 <h2 id="_diffcore_order_for_sorting_the_output_based_on_filenames">diffcore-order: For Sorting the Output Based on Filenames</h2>
665 <div class="sectionbody">
666 <div class="paragraph"><p>This is used to reorder the filepairs according to the user&#8217;s
667 (or project&#8217;s) taste, and is controlled by the -O option to the
668 <em>git diff-&#42;</em> commands.</p></div>
669 <div class="paragraph"><p>This takes a text file each of whose lines is a shell glob
670 pattern. Filepairs that match a glob pattern on an earlier line
671 in the file are output before ones that match a later line, and
672 filepairs that do not match any glob pattern are output last.</p></div>
673 <div class="paragraph"><p>As an example, a typical orderfile for the core git probably
674 would look like this:</p></div>
675 <div class="listingblock">
676 <div class="content">
677 <pre><tt>README
678 Makefile
679 Documentation
682 t</tt></pre>
683 </div></div>
684 </div>
685 <h2 id="_see_also">SEE ALSO</h2>
686 <div class="sectionbody">
687 <div class="paragraph"><p><a href="git-diff.html">git-diff(1)</a>,
688 <a href="git-diff-files.html">git-diff-files(1)</a>,
689 <a href="git-diff-index.html">git-diff-index(1)</a>,
690 <a href="git-diff-tree.html">git-diff-tree(1)</a>,
691 <a href="git-format-patch.html">git-format-patch(1)</a>,
692 <a href="git-log.html">git-log(1)</a>,
693 <a href="gitglossary.html">gitglossary(7)</a>,
694 <a href="user-manual.html">The Git User&#8217;s Manual</a></p></div>
695 </div>
696 <h2 id="_git">GIT</h2>
697 <div class="sectionbody">
698 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
699 </div>
700 <div id="footer">
701 <div id="footer-text">
702 Last updated 2011-07-23 00:49:30 UTC
703 </div>
704 </div>
705 </body>
706 </html>