Autogenerated HTML docs for v1.6.6-35-g1d85d
[git/jnareb-git.git] / gitdiffcore.html
blob966aaa6b312b33a9558ac9f952aa14d2a9f1fd6c
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.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>gitdiffcore(7)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 gitdiffcore(7) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>gitdiffcore -
317 Tweaking diff output (June 2005)
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="para"><p><em>git diff</em> *</p></div>
324 </div>
325 <h2 id="_description">DESCRIPTION</h2>
326 <div class="sectionbody">
327 <div class="para"><p>The diff commands <em>git-diff-index</em>, <em>git-diff-files</em>, and <em>git-diff-tree</em>
328 can be told to manipulate differences they find in
329 unconventional ways before showing <em>diff</em> output. The manipulation
330 is collectively called "diffcore transformation". This short note
331 describes what they are and how to use them to produce <em>diff</em> output
332 that is easier to understand than the conventional kind.</p></div>
333 </div>
334 <h2 id="_the_chain_of_operation">The chain of operation</h2>
335 <div class="sectionbody">
336 <div class="para"><p>The <em>git-diff-&#42;</em> family works by first comparing two sets of
337 files:</p></div>
338 <div class="ilist"><ul>
339 <li>
341 <em>git-diff-index</em> compares contents of a "tree" object and the
342 working directory (when <em>--cached</em> flag is not used) or a
343 "tree" object and the index file (when <em>--cached</em> flag is
344 used);
345 </p>
346 </li>
347 <li>
349 <em>git-diff-files</em> compares contents of the index file and the
350 working directory;
351 </p>
352 </li>
353 <li>
355 <em>git-diff-tree</em> compares contents of two "tree" objects;
356 </p>
357 </li>
358 </ul></div>
359 <div class="para"><p>In all of these cases, the commands themselves first optionally limit
360 the two sets of files by any pathspecs given on their command-lines,
361 and compare corresponding paths in the two resulting sets of files.</p></div>
362 <div class="para"><p>The pathspecs are used to limit the world diff operates in. They remove
363 the filepairs outside the specified sets of pathnames. E.g. If the
364 input set of filepairs included:</p></div>
365 <div class="listingblock">
366 <div class="content">
367 <pre><tt>:100644 100644 bcd1234... 0123456... M junkfile</tt></pre>
368 </div></div>
369 <div class="para"><p>but the command invocation was <tt>git diff-files myfile</tt>, then the
370 junkfile entry would be removed from the list because only "myfile"
371 is under consideration.</p></div>
372 <div class="para"><p>The result of comparison is passed from these commands to what is
373 internally called "diffcore", in a format similar to what is output
374 when the -p option is not used. E.g.</p></div>
375 <div class="listingblock">
376 <div class="content">
377 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
378 create :000000 100644 0000000... 1234567... A file4
379 delete :100644 000000 1234567... 0000000... D file5
380 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
381 </div></div>
382 <div class="para"><p>The diffcore mechanism is fed a list of such comparison results
383 (each of which is called "filepair", although at this point each
384 of them talks about a single file), and transforms such a list
385 into another list. There are currently 5 such transformations:</p></div>
386 <div class="ilist"><ul>
387 <li>
389 diffcore-break
390 </p>
391 </li>
392 <li>
394 diffcore-rename
395 </p>
396 </li>
397 <li>
399 diffcore-merge-broken
400 </p>
401 </li>
402 <li>
404 diffcore-pickaxe
405 </p>
406 </li>
407 <li>
409 diffcore-order
410 </p>
411 </li>
412 </ul></div>
413 <div class="para"><p>These are applied in sequence. The set of filepairs <em>git-diff-&#42;</em>
414 commands find are used as the input to diffcore-break, and
415 the output from diffcore-break is used as the input to the
416 next transformation. The final result is then passed to the
417 output routine and generates either diff-raw format (see Output
418 format sections of the manual for <em>git-diff-&#42;</em> commands) or
419 diff-patch format.</p></div>
420 </div>
421 <h2 id="_diffcore_break_for_splitting_up_complete_rewrites">diffcore-break: For Splitting Up "Complete Rewrites"</h2>
422 <div class="sectionbody">
423 <div class="para"><p>The second transformation in the chain is diffcore-break, and is
424 controlled by the -B option to the <em>git-diff-&#42;</em> commands. This is
425 used to detect a filepair that represents "complete rewrite" and
426 break such filepair into two filepairs that represent delete and
427 create. E.g. If the input contained this filepair:</p></div>
428 <div class="listingblock">
429 <div class="content">
430 <pre><tt>:100644 100644 bcd1234... 0123456... M file0</tt></pre>
431 </div></div>
432 <div class="para"><p>and if it detects that the file "file0" is completely rewritten,
433 it changes it to:</p></div>
434 <div class="listingblock">
435 <div class="content">
436 <pre><tt>:100644 000000 bcd1234... 0000000... D file0
437 :000000 100644 0000000... 0123456... A file0</tt></pre>
438 </div></div>
439 <div class="para"><p>For the purpose of breaking a filepair, diffcore-break examines
440 the extent of changes between the contents of the files before
441 and after modification (i.e. the contents that have "bcd1234&#8230;"
442 and "0123456&#8230;" as their SHA1 content ID, in the above
443 example). The amount of deletion of original contents and
444 insertion of new material are added together, and if it exceeds
445 the "break score", the filepair is broken into two. The break
446 score defaults to 50% of the size of the smaller of the original
447 and the result (i.e. if the edit shrinks the file, the size of
448 the result is used; if the edit lengthens the file, the size of
449 the original is used), and can be customized by giving a number
450 after "-B" option (e.g. "-B75" to tell it to use 75%).</p></div>
451 </div>
452 <h2 id="_diffcore_rename_for_detection_renames_and_copies">diffcore-rename: For Detection Renames and Copies</h2>
453 <div class="sectionbody">
454 <div class="para"><p>This transformation is used to detect renames and copies, and is
455 controlled by the -M option (to detect renames) and the -C option
456 (to detect copies as well) to the <em>git-diff-&#42;</em> commands. If the
457 input contained these filepairs:</p></div>
458 <div class="listingblock">
459 <div class="content">
460 <pre><tt>:100644 000000 0123456... 0000000... D fileX
461 :000000 100644 0000000... 0123456... A file0</tt></pre>
462 </div></div>
463 <div class="para"><p>and the contents of the deleted file fileX is similar enough to
464 the contents of the created file file0, then rename detection
465 merges these filepairs and creates:</p></div>
466 <div class="listingblock">
467 <div class="content">
468 <pre><tt>:100644 100644 0123456... 0123456... R100 fileX file0</tt></pre>
469 </div></div>
470 <div class="para"><p>When the "-C" option is used, the original contents of modified files,
471 and deleted files (and also unmodified files, if the
472 "--find-copies-harder" option is used) are considered as candidates
473 of the source files in rename/copy operation. If the input were like
474 these filepairs, that talk about a modified file fileY and a newly
475 created file file0:</p></div>
476 <div class="listingblock">
477 <div class="content">
478 <pre><tt>:100644 100644 0123456... 1234567... M fileY
479 :000000 100644 0000000... bcd3456... A file0</tt></pre>
480 </div></div>
481 <div class="para"><p>the original contents of fileY and the resulting contents of
482 file0 are compared, and if they are similar enough, they are
483 changed to:</p></div>
484 <div class="listingblock">
485 <div class="content">
486 <pre><tt>:100644 100644 0123456... 1234567... M fileY
487 :100644 100644 0123456... bcd3456... C100 fileY file0</tt></pre>
488 </div></div>
489 <div class="para"><p>In both rename and copy detection, the same "extent of changes"
490 algorithm used in diffcore-break is used to determine if two
491 files are "similar enough", and can be customized to use
492 a similarity score different from the default of 50% by giving a
493 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use
494 8/10 = 80%).</p></div>
495 <div class="para"><p>Note. When the "-C" option is used with <tt>--find-copies-harder</tt>
496 option, <em>git-diff-&#42;</em> commands feed unmodified filepairs to
497 diffcore mechanism as well as modified ones. This lets the copy
498 detector consider unmodified files as copy source candidates at
499 the expense of making it slower. Without <tt>--find-copies-harder</tt>,
500 <em>git-diff-&#42;</em> commands can detect copies only if the file that was
501 copied happened to have been modified in the same changeset.</p></div>
502 </div>
503 <h2 id="_diffcore_merge_broken_for_putting_complete_rewrites_back_together">diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</h2>
504 <div class="sectionbody">
505 <div class="para"><p>This transformation is used to merge filepairs broken by
506 diffcore-break, and not transformed into rename/copy by
507 diffcore-rename, back into a single modification. This always
508 runs when diffcore-break is used.</p></div>
509 <div class="para"><p>For the purpose of merging broken filepairs back, it uses a
510 different "extent of changes" computation from the ones used by
511 diffcore-break and diffcore-rename. It counts only the deletion
512 from the original, and does not count insertion. If you removed
513 only 10 lines from a 100-line document, even if you added 910
514 new lines to make a new 1000-line document, you did not do a
515 complete rewrite. diffcore-break breaks such a case in order to
516 help diffcore-rename to consider such filepairs as candidate of
517 rename/copy detection, but if filepairs broken that way were not
518 matched with other filepairs to create rename/copy, then this
519 transformation merges them back into the original
520 "modification".</p></div>
521 <div class="para"><p>The "extent of changes" parameter can be tweaked from the
522 default 80% (that is, unless more than 80% of the original
523 material is deleted, the broken pairs are merged back into a
524 single modification) by giving a second number to -B option,
525 like these:</p></div>
526 <div class="ilist"><ul>
527 <li>
529 -B50/60 (give 50% "break score" to diffcore-break, use 60%
530 for diffcore-merge-broken).
531 </p>
532 </li>
533 <li>
535 -B/60 (the same as above, since diffcore-break defaults to 50%).
536 </p>
537 </li>
538 </ul></div>
539 <div class="para"><p>Note that earlier implementation left a broken pair as a separate
540 creation and deletion patches. This was an unnecessary hack and
541 the latest implementation always merges all the broken pairs
542 back into modifications, but the resulting patch output is
543 formatted differently for easier review in case of such
544 a complete rewrite by showing the entire contents of old version
545 prefixed with <em>-</em>, followed by the entire contents of new
546 version prefixed with <em>+</em>.</p></div>
547 </div>
548 <h2 id="_diffcore_pickaxe_for_detecting_addition_deletion_of_specified_string">diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</h2>
549 <div class="sectionbody">
550 <div class="para"><p>This transformation is used to find filepairs that represent
551 changes that touch a specified string, and is controlled by the
552 -S option and the <tt>--pickaxe-all</tt> option to the <em>git-diff-&#42;</em>
553 commands.</p></div>
554 <div class="para"><p>When diffcore-pickaxe is in use, it checks if there are
555 filepairs whose "original" side has the specified string and
556 whose "result" side does not. Such a filepair represents "the
557 string appeared in this changeset". It also checks for the
558 opposite case that loses the specified string.</p></div>
559 <div class="para"><p>When <tt>--pickaxe-all</tt> is not in effect, diffcore-pickaxe leaves
560 only such filepairs that touch the specified string in its
561 output. When <tt>--pickaxe-all</tt> is used, diffcore-pickaxe leaves all
562 filepairs intact if there is such a filepair, or makes the
563 output empty otherwise. The latter behaviour is designed to
564 make reviewing of the changes in the context of the whole
565 changeset easier.</p></div>
566 </div>
567 <h2 id="_diffcore_order_for_sorting_the_output_based_on_filenames">diffcore-order: For Sorting the Output Based on Filenames</h2>
568 <div class="sectionbody">
569 <div class="para"><p>This is used to reorder the filepairs according to the user's
570 (or project's) taste, and is controlled by the -O option to the
571 <em>git-diff-&#42;</em> commands.</p></div>
572 <div class="para"><p>This takes a text file each of whose lines is a shell glob
573 pattern. Filepairs that match a glob pattern on an earlier line
574 in the file are output before ones that match a later line, and
575 filepairs that do not match any glob pattern are output last.</p></div>
576 <div class="para"><p>As an example, a typical orderfile for the core git probably
577 would look like this:</p></div>
578 <div class="listingblock">
579 <div class="content">
580 <pre><tt>README
581 Makefile
582 Documentation
585 t</tt></pre>
586 </div></div>
587 </div>
588 <h2 id="_see_also">SEE ALSO</h2>
589 <div class="sectionbody">
590 <div class="para"><p><a href="git-diff.html">git-diff(1)</a>,
591 <a href="git-diff-files.html">git-diff-files(1)</a>,
592 <a href="git-diff-index.html">git-diff-index(1)</a>,
593 <a href="git-diff-tree.html">git-diff-tree(1)</a>,
594 <a href="git-format-patch.html">git-format-patch(1)</a>,
595 <a href="git-log.html">git-log(1)</a>,
596 <a href="gitglossary.html">gitglossary(7)</a>,
597 <a href="user-manual.html">The Git User's Manual</a></p></div>
598 </div>
599 <h2 id="_git">GIT</h2>
600 <div class="sectionbody">
601 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
602 </div>
603 <div id="footer">
604 <div id="footer-text">
605 Last updated 2009-12-03 09:12:56 UTC
606 </div>
607 </div>
608 </body>
609 </html>