Autogenerated HTML docs for v1.7.4.2-414-g07514
[git/jnareb-git.git] / gitdiffcore.html
blob054c9827a7988c65b953fb98f8a3110fc54e6dbc
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="paragraph"><p><em>git diff</em> *</p></div>
418 </div>
419 <h2 id="_description">DESCRIPTION</h2>
420 <div class="sectionbody">
421 <div class="paragraph"><p>The diff commands <em>git diff-index</em>, <em>git diff-files</em>, and <em>git diff-tree</em>
422 can be told to manipulate differences they find in
423 unconventional ways before showing <em>diff</em> output. The manipulation
424 is collectively called "diffcore transformation". This short note
425 describes what they are and how to use them to produce <em>diff</em> output
426 that is easier to understand than the conventional kind.</p></div>
427 </div>
428 <h2 id="_the_chain_of_operation">The chain of operation</h2>
429 <div class="sectionbody">
430 <div class="paragraph"><p>The <em>git diff-&#42;</em> family works by first comparing two sets of
431 files:</p></div>
432 <div class="ulist"><ul>
433 <li>
435 <em>git diff-index</em> compares contents of a "tree" object and the
436 working directory (when <em>--cached</em> flag is not used) or a
437 "tree" object and the index file (when <em>--cached</em> flag is
438 used);
439 </p>
440 </li>
441 <li>
443 <em>git diff-files</em> compares contents of the index file and the
444 working directory;
445 </p>
446 </li>
447 <li>
449 <em>git diff-tree</em> compares contents of two "tree" objects;
450 </p>
451 </li>
452 </ul></div>
453 <div class="paragraph"><p>In all of these cases, the commands themselves first optionally limit
454 the two sets of files by any pathspecs given on their command-lines,
455 and compare corresponding paths in the two resulting sets of files.</p></div>
456 <div class="paragraph"><p>The pathspecs are used to limit the world diff operates in. They remove
457 the filepairs outside the specified sets of pathnames. E.g. If the
458 input set of filepairs included:</p></div>
459 <div class="listingblock">
460 <div class="content">
461 <pre><tt>:100644 100644 bcd1234... 0123456... M junkfile</tt></pre>
462 </div></div>
463 <div class="paragraph"><p>but the command invocation was <tt>git diff-files myfile</tt>, then the
464 junkfile entry would be removed from the list because only "myfile"
465 is under consideration.</p></div>
466 <div class="paragraph"><p>The result of comparison is passed from these commands to what is
467 internally called "diffcore", in a format similar to what is output
468 when the -p option is not used. E.g.</p></div>
469 <div class="listingblock">
470 <div class="content">
471 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
472 create :000000 100644 0000000... 1234567... A file4
473 delete :100644 000000 1234567... 0000000... D file5
474 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
475 </div></div>
476 <div class="paragraph"><p>The diffcore mechanism is fed a list of such comparison results
477 (each of which is called "filepair", although at this point each
478 of them talks about a single file), and transforms such a list
479 into another list. There are currently 5 such transformations:</p></div>
480 <div class="ulist"><ul>
481 <li>
483 diffcore-break
484 </p>
485 </li>
486 <li>
488 diffcore-rename
489 </p>
490 </li>
491 <li>
493 diffcore-merge-broken
494 </p>
495 </li>
496 <li>
498 diffcore-pickaxe
499 </p>
500 </li>
501 <li>
503 diffcore-order
504 </p>
505 </li>
506 </ul></div>
507 <div class="paragraph"><p>These are applied in sequence. The set of filepairs <em>git diff-&#42;</em>
508 commands find are used as the input to diffcore-break, and
509 the output from diffcore-break is used as the input to the
510 next transformation. The final result is then passed to the
511 output routine and generates either diff-raw format (see Output
512 format sections of the manual for <em>git diff-&#42;</em> commands) or
513 diff-patch format.</p></div>
514 </div>
515 <h2 id="_diffcore_break_for_splitting_up_complete_rewrites">diffcore-break: For Splitting Up "Complete Rewrites"</h2>
516 <div class="sectionbody">
517 <div class="paragraph"><p>The second transformation in the chain is diffcore-break, and is
518 controlled by the -B option to the <em>git diff-&#42;</em> commands. This is
519 used to detect a filepair that represents "complete rewrite" and
520 break such filepair into two filepairs that represent delete and
521 create. E.g. If the input contained this filepair:</p></div>
522 <div class="listingblock">
523 <div class="content">
524 <pre><tt>:100644 100644 bcd1234... 0123456... M file0</tt></pre>
525 </div></div>
526 <div class="paragraph"><p>and if it detects that the file "file0" is completely rewritten,
527 it changes it to:</p></div>
528 <div class="listingblock">
529 <div class="content">
530 <pre><tt>:100644 000000 bcd1234... 0000000... D file0
531 :000000 100644 0000000... 0123456... A file0</tt></pre>
532 </div></div>
533 <div class="paragraph"><p>For the purpose of breaking a filepair, diffcore-break examines
534 the extent of changes between the contents of the files before
535 and after modification (i.e. the contents that have "bcd1234&#8230;"
536 and "0123456&#8230;" as their SHA1 content ID, in the above
537 example). The amount of deletion of original contents and
538 insertion of new material are added together, and if it exceeds
539 the "break score", the filepair is broken into two. The break
540 score defaults to 50% of the size of the smaller of the original
541 and the result (i.e. if the edit shrinks the file, the size of
542 the result is used; if the edit lengthens the file, the size of
543 the original is used), and can be customized by giving a number
544 after "-B" option (e.g. "-B75" to tell it to use 75%).</p></div>
545 </div>
546 <h2 id="_diffcore_rename_for_detection_renames_and_copies">diffcore-rename: For Detection Renames and Copies</h2>
547 <div class="sectionbody">
548 <div class="paragraph"><p>This transformation is used to detect renames and copies, and is
549 controlled by the -M option (to detect renames) and the -C option
550 (to detect copies as well) to the <em>git diff-&#42;</em> commands. If the
551 input contained these filepairs:</p></div>
552 <div class="listingblock">
553 <div class="content">
554 <pre><tt>:100644 000000 0123456... 0000000... D fileX
555 :000000 100644 0000000... 0123456... A file0</tt></pre>
556 </div></div>
557 <div class="paragraph"><p>and the contents of the deleted file fileX is similar enough to
558 the contents of the created file file0, then rename detection
559 merges these filepairs and creates:</p></div>
560 <div class="listingblock">
561 <div class="content">
562 <pre><tt>:100644 100644 0123456... 0123456... R100 fileX file0</tt></pre>
563 </div></div>
564 <div class="paragraph"><p>When the "-C" option is used, the original contents of modified files,
565 and deleted files (and also unmodified files, if the
566 "--find-copies-harder" option is used) are considered as candidates
567 of the source files in rename/copy operation. If the input were like
568 these filepairs, that talk about a modified file fileY and a newly
569 created file file0:</p></div>
570 <div class="listingblock">
571 <div class="content">
572 <pre><tt>:100644 100644 0123456... 1234567... M fileY
573 :000000 100644 0000000... bcd3456... A file0</tt></pre>
574 </div></div>
575 <div class="paragraph"><p>the original contents of fileY and the resulting contents of
576 file0 are compared, and if they are similar enough, they are
577 changed to:</p></div>
578 <div class="listingblock">
579 <div class="content">
580 <pre><tt>:100644 100644 0123456... 1234567... M fileY
581 :100644 100644 0123456... bcd3456... C100 fileY file0</tt></pre>
582 </div></div>
583 <div class="paragraph"><p>In both rename and copy detection, the same "extent of changes"
584 algorithm used in diffcore-break is used to determine if two
585 files are "similar enough", and can be customized to use
586 a similarity score different from the default of 50% by giving a
587 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use
588 8/10 = 80%).</p></div>
589 <div class="paragraph"><p>Note. When the "-C" option is used with <tt>--find-copies-harder</tt>
590 option, <em>git diff-&#42;</em> commands feed unmodified filepairs to
591 diffcore mechanism as well as modified ones. This lets the copy
592 detector consider unmodified files as copy source candidates at
593 the expense of making it slower. Without <tt>--find-copies-harder</tt>,
594 <em>git diff-&#42;</em> commands can detect copies only if the file that was
595 copied happened to have been modified in the same changeset.</p></div>
596 </div>
597 <h2 id="_diffcore_merge_broken_for_putting_complete_rewrites_back_together">diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</h2>
598 <div class="sectionbody">
599 <div class="paragraph"><p>This transformation is used to merge filepairs broken by
600 diffcore-break, and not transformed into rename/copy by
601 diffcore-rename, back into a single modification. This always
602 runs when diffcore-break is used.</p></div>
603 <div class="paragraph"><p>For the purpose of merging broken filepairs back, it uses a
604 different "extent of changes" computation from the ones used by
605 diffcore-break and diffcore-rename. It counts only the deletion
606 from the original, and does not count insertion. If you removed
607 only 10 lines from a 100-line document, even if you added 910
608 new lines to make a new 1000-line document, you did not do a
609 complete rewrite. diffcore-break breaks such a case in order to
610 help diffcore-rename to consider such filepairs as candidate of
611 rename/copy detection, but if filepairs broken that way were not
612 matched with other filepairs to create rename/copy, then this
613 transformation merges them back into the original
614 "modification".</p></div>
615 <div class="paragraph"><p>The "extent of changes" parameter can be tweaked from the
616 default 80% (that is, unless more than 80% of the original
617 material is deleted, the broken pairs are merged back into a
618 single modification) by giving a second number to -B option,
619 like these:</p></div>
620 <div class="ulist"><ul>
621 <li>
623 -B50/60 (give 50% "break score" to diffcore-break, use 60%
624 for diffcore-merge-broken).
625 </p>
626 </li>
627 <li>
629 -B/60 (the same as above, since diffcore-break defaults to 50%).
630 </p>
631 </li>
632 </ul></div>
633 <div class="paragraph"><p>Note that earlier implementation left a broken pair as a separate
634 creation and deletion patches. This was an unnecessary hack and
635 the latest implementation always merges all the broken pairs
636 back into modifications, but the resulting patch output is
637 formatted differently for easier review in case of such
638 a complete rewrite by showing the entire contents of old version
639 prefixed with <em>-</em>, followed by the entire contents of new
640 version prefixed with <em>+</em>.</p></div>
641 </div>
642 <h2 id="_diffcore_pickaxe_for_detecting_addition_deletion_of_specified_string">diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</h2>
643 <div class="sectionbody">
644 <div class="paragraph"><p>This transformation is used to find filepairs that represent
645 changes that touch a specified string, and is controlled by the
646 -S option and the <tt>--pickaxe-all</tt> option to the <em>git diff-&#42;</em>
647 commands.</p></div>
648 <div class="paragraph"><p>When diffcore-pickaxe is in use, it checks if there are
649 filepairs whose "result" side and whose "origin" side have
650 different number of specified string. Such a filepair represents
651 "the string appeared in this changeset". It also checks for the
652 opposite case that loses the specified string.</p></div>
653 <div class="paragraph"><p>When <tt>--pickaxe-all</tt> is not in effect, diffcore-pickaxe leaves
654 only such filepairs that touch the specified string in its
655 output. When <tt>--pickaxe-all</tt> is used, diffcore-pickaxe leaves all
656 filepairs intact if there is such a filepair, or makes the
657 output empty otherwise. The latter behaviour is designed to
658 make reviewing of the changes in the context of the whole
659 changeset easier.</p></div>
660 </div>
661 <h2 id="_diffcore_order_for_sorting_the_output_based_on_filenames">diffcore-order: For Sorting the Output Based on Filenames</h2>
662 <div class="sectionbody">
663 <div class="paragraph"><p>This is used to reorder the filepairs according to the user&#8217;s
664 (or project&#8217;s) taste, and is controlled by the -O option to the
665 <em>git diff-&#42;</em> commands.</p></div>
666 <div class="paragraph"><p>This takes a text file each of whose lines is a shell glob
667 pattern. Filepairs that match a glob pattern on an earlier line
668 in the file are output before ones that match a later line, and
669 filepairs that do not match any glob pattern are output last.</p></div>
670 <div class="paragraph"><p>As an example, a typical orderfile for the core git probably
671 would look like this:</p></div>
672 <div class="listingblock">
673 <div class="content">
674 <pre><tt>README
675 Makefile
676 Documentation
679 t</tt></pre>
680 </div></div>
681 </div>
682 <h2 id="_see_also">SEE ALSO</h2>
683 <div class="sectionbody">
684 <div class="paragraph"><p><a href="git-diff.html">git-diff(1)</a>,
685 <a href="git-diff-files.html">git-diff-files(1)</a>,
686 <a href="git-diff-index.html">git-diff-index(1)</a>,
687 <a href="git-diff-tree.html">git-diff-tree(1)</a>,
688 <a href="git-format-patch.html">git-format-patch(1)</a>,
689 <a href="git-log.html">git-log(1)</a>,
690 <a href="gitglossary.html">gitglossary(7)</a>,
691 <a href="user-manual.html">The Git User&#8217;s Manual</a></p></div>
692 </div>
693 <h2 id="_git">GIT</h2>
694 <div class="sectionbody">
695 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
696 </div>
697 <div id="footer">
698 <div id="footer-text">
699 Last updated 2010-09-30 00:01:59 UTC
700 </div>
701 </div>
702 </body>
703 </html>