Autogenerated HTML docs for v1.7.1
[git/jnareb-git.git] / git-diff-index.html
blobc21809ff4313cee6afc5f6dcccaae33e141927c9
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>git-diff-index(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-diff-index(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-diff-index -
317 Compares content and mode of blobs between the index and repository
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="para"><p><em>git diff-index</em> [-m] [--cached] [&lt;common diff options&gt;] &lt;tree-ish&gt; [&lt;path&gt;&#8230;]</p></div>
324 </div>
325 <h2 id="_description">DESCRIPTION</h2>
326 <div class="sectionbody">
327 <div class="para"><p>Compares the content and mode of the blobs found via a tree
328 object with the content of the current index and, optionally
329 ignoring the stat state of the file on disk. When paths are
330 specified, compares only those named paths. Otherwise all
331 entries in the index are compared.</p></div>
332 </div>
333 <h2 id="_options">OPTIONS</h2>
334 <div class="sectionbody">
335 <div class="vlist"><dl>
336 <dt>
338 </dt>
339 <dt>
341 </dt>
342 <dd>
344 Generate patch (see section on generating patches).
346 </p>
347 </dd>
348 <dt>
349 -U&lt;n&gt;
350 </dt>
351 <dt>
352 --unified=&lt;n&gt;
353 </dt>
354 <dd>
356 Generate diffs with &lt;n&gt; lines of context instead of
357 the usual three.
358 Implies <tt>-p</tt>.
359 </p>
360 </dd>
361 <dt>
362 --raw
363 </dt>
364 <dd>
366 Generate the raw format.
367 This is the default.
368 </p>
369 </dd>
370 <dt>
371 --patch-with-raw
372 </dt>
373 <dd>
375 Synonym for <tt>-p --raw</tt>.
376 </p>
377 </dd>
378 <dt>
379 --patience
380 </dt>
381 <dd>
383 Generate a diff using the "patience diff" algorithm.
384 </p>
385 </dd>
386 <dt>
387 --stat[=width[,name-width]]
388 </dt>
389 <dd>
391 Generate a diffstat. You can override the default
392 output width for 80-column terminal by <tt>--stat=width</tt>.
393 The width of the filename part can be controlled by
394 giving another width to it separated by a comma.
395 </p>
396 </dd>
397 <dt>
398 --numstat
399 </dt>
400 <dd>
402 Similar to <tt>--stat</tt>, but shows number of added and
403 deleted lines in decimal notation and pathname without
404 abbreviation, to make it more machine friendly. For
405 binary files, outputs two <tt>-</tt> instead of saying
406 <tt>0 0</tt>.
407 </p>
408 </dd>
409 <dt>
410 --shortstat
411 </dt>
412 <dd>
414 Output only the last line of the <tt>--stat</tt> format containing total
415 number of modified files, as well as number of added and deleted
416 lines.
417 </p>
418 </dd>
419 <dt>
420 --dirstat[=limit]
421 </dt>
422 <dd>
424 Output the distribution of relative amount of changes (number of lines added or
425 removed) for each sub-directory. Directories with changes below
426 a cut-off percent (3% by default) are not shown. The cut-off percent
427 can be set with <tt>--dirstat=limit</tt>. Changes in a child directory is not
428 counted for the parent directory, unless <tt>--cumulative</tt> is used.
429 </p>
430 </dd>
431 <dt>
432 --dirstat-by-file[=limit]
433 </dt>
434 <dd>
436 Same as <tt>--dirstat</tt>, but counts changed files instead of lines.
437 </p>
438 </dd>
439 <dt>
440 --summary
441 </dt>
442 <dd>
444 Output a condensed summary of extended header information
445 such as creations, renames and mode changes.
446 </p>
447 </dd>
448 <dt>
449 --patch-with-stat
450 </dt>
451 <dd>
453 Synonym for <tt>-p --stat</tt>.
454 </p>
455 </dd>
456 <dt>
458 </dt>
459 <dd>
461 When <tt>--raw</tt>, <tt>--numstat</tt>, <tt>--name-only</tt> or <tt>--name-status</tt> has been
462 given, do not munge pathnames and use NULs as output field terminators.
463 </p>
464 <div class="para"><p>Without this option, each pathname output will have TAB, LF, double quotes,
465 and backslash characters replaced with <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt>, and <tt>\\</tt>,
466 respectively, and the pathname will be enclosed in double quotes if
467 any of those replacements occurred.</p></div>
468 </dd>
469 <dt>
470 --name-only
471 </dt>
472 <dd>
474 Show only names of changed files.
475 </p>
476 </dd>
477 <dt>
478 --name-status
479 </dt>
480 <dd>
482 Show only names and status of changed files. See the description
483 of the <tt>--diff-filter</tt> option on what the status letters mean.
484 </p>
485 </dd>
486 <dt>
487 --submodule[=&lt;format&gt;]
488 </dt>
489 <dd>
491 Chose the output format for submodule differences. &lt;format&gt; can be one of
492 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
493 is used when this option is not given. <em>log</em> is the default value for this
494 option and lists the commits in that commit range like the <em>summary</em>
495 option of <a href="git-submodule.html">git-submodule(1)</a> does.
496 </p>
497 </dd>
498 <dt>
499 --color[=&lt;when&gt;]
500 </dt>
501 <dd>
503 Show colored diff.
504 The value must be always (the default), never, or auto.
505 </p>
506 </dd>
507 <dt>
508 --no-color
509 </dt>
510 <dd>
512 Turn off colored diff, even when the configuration file
513 gives the default to color output.
514 Same as <tt>--color=never</tt>.
515 </p>
516 </dd>
517 <dt>
518 --color-words[=&lt;regex&gt;]
519 </dt>
520 <dd>
522 Show colored word diff, i.e., color words which have changed.
523 By default, words are separated by whitespace.
524 </p>
525 <div class="para"><p>When a &lt;regex&gt; is specified, every non-overlapping match of the
526 &lt;regex&gt; is considered a word. Anything between these matches is
527 considered whitespace and ignored(!) for the purposes of finding
528 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
529 expression to make sure that it matches all non-whitespace characters.
530 A match that contains a newline is silently truncated(!) at the
531 newline.</p></div>
532 <div class="para"><p>The regex can also be set via a diff driver or configuration option, see
533 <a href="gitattributes.html">gitattributes(1)</a> or <a href="git-config.html">git-config(1)</a>. Giving it explicitly
534 overrides any diff driver or configuration setting. Diff drivers
535 override configuration settings.</p></div>
536 </dd>
537 <dt>
538 --no-renames
539 </dt>
540 <dd>
542 Turn off rename detection, even when the configuration
543 file gives the default to do so.
544 </p>
545 </dd>
546 <dt>
547 --check
548 </dt>
549 <dd>
551 Warn if changes introduce trailing whitespace
552 or an indent that uses a space before a tab. Exits with
553 non-zero status if problems are found. Not compatible with
554 --exit-code.
555 </p>
556 </dd>
557 <dt>
558 --full-index
559 </dt>
560 <dd>
562 Instead of the first handful of characters, show the full
563 pre- and post-image blob object names on the "index"
564 line when generating patch format output.
565 </p>
566 </dd>
567 <dt>
568 --binary
569 </dt>
570 <dd>
572 In addition to <tt>--full-index</tt>, output a binary diff that
573 can be applied with <tt>git-apply</tt>.
574 </p>
575 </dd>
576 <dt>
577 --abbrev[=&lt;n&gt;]
578 </dt>
579 <dd>
581 Instead of showing the full 40-byte hexadecimal object
582 name in diff-raw format output and diff-tree header
583 lines, show only a partial prefix. This is
584 independent of the <tt>--full-index</tt> option above, which controls
585 the diff-patch output format. Non default number of
586 digits can be specified with <tt>--abbrev=&lt;n&gt;</tt>.
587 </p>
588 </dd>
589 <dt>
591 </dt>
592 <dd>
594 Break complete rewrite changes into pairs of delete and create.
595 </p>
596 </dd>
597 <dt>
599 </dt>
600 <dd>
602 Detect renames.
603 </p>
604 </dd>
605 <dt>
607 </dt>
608 <dd>
610 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
611 </p>
612 </dd>
613 <dt>
614 --diff-filter=[ACDMRTUXB*]
615 </dt>
616 <dd>
618 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
619 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
620 type (i.e. regular file, symlink, submodule, &#8230;) changed (<tt>T</tt>),
621 are Unmerged (<tt>U</tt>), are
622 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
623 Any combination of the filter characters may be used.
624 When <tt>*</tt> (All-or-none) is added to the combination, all
625 paths are selected if there is any file that matches
626 other criteria in the comparison; if there is no file
627 that matches other criteria, nothing is selected.
628 </p>
629 </dd>
630 <dt>
631 --find-copies-harder
632 </dt>
633 <dd>
635 For performance reasons, by default, <tt>-C</tt> option finds copies only
636 if the original file of the copy was modified in the same
637 changeset. This flag makes the command
638 inspect unmodified files as candidates for the source of
639 copy. This is a very expensive operation for large
640 projects, so use it with caution. Giving more than one
641 <tt>-C</tt> option has the same effect.
642 </p>
643 </dd>
644 <dt>
645 -l&lt;num&gt;
646 </dt>
647 <dd>
649 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
650 is the number of potential rename/copy targets. This
651 option prevents rename/copy detection from running if
652 the number of rename/copy targets exceeds the specified
653 number.
654 </p>
655 </dd>
656 <dt>
657 -S&lt;string&gt;
658 </dt>
659 <dd>
661 Look for differences that introduce or remove an instance of
662 &lt;string&gt;. Note that this is different than the string simply
663 appearing in diff output; see the <em>pickaxe</em> entry in
664 <a href="gitdiffcore.html">gitdiffcore(7)</a> for more details.
665 </p>
666 </dd>
667 <dt>
668 --pickaxe-all
669 </dt>
670 <dd>
672 When <tt>-S</tt> finds a change, show all the changes in that
673 changeset, not just the files that contain the change
674 in &lt;string&gt;.
675 </p>
676 </dd>
677 <dt>
678 --pickaxe-regex
679 </dt>
680 <dd>
682 Make the &lt;string&gt; not a plain string but an extended POSIX
683 regex to match.
684 </p>
685 </dd>
686 <dt>
687 -O&lt;orderfile&gt;
688 </dt>
689 <dd>
691 Output the patch in the order specified in the
692 &lt;orderfile&gt;, which has one shell glob pattern per line.
693 </p>
694 </dd>
695 <dt>
697 </dt>
698 <dd>
700 Swap two inputs; that is, show differences from index or
701 on-disk file to tree contents.
702 </p>
703 </dd>
704 <dt>
705 --relative[=&lt;path&gt;]
706 </dt>
707 <dd>
709 When run from a subdirectory of the project, it can be
710 told to exclude changes outside the directory and show
711 pathnames relative to it with this option. When you are
712 not in a subdirectory (e.g. in a bare repository), you
713 can name which subdirectory to make the output relative
714 to by giving a &lt;path&gt; as an argument.
715 </p>
716 </dd>
717 <dt>
719 </dt>
720 <dt>
721 --text
722 </dt>
723 <dd>
725 Treat all files as text.
726 </p>
727 </dd>
728 <dt>
729 --ignore-space-at-eol
730 </dt>
731 <dd>
733 Ignore changes in whitespace at EOL.
734 </p>
735 </dd>
736 <dt>
738 </dt>
739 <dt>
740 --ignore-space-change
741 </dt>
742 <dd>
744 Ignore changes in amount of whitespace. This ignores whitespace
745 at line end, and considers all other sequences of one or
746 more whitespace characters to be equivalent.
747 </p>
748 </dd>
749 <dt>
751 </dt>
752 <dt>
753 --ignore-all-space
754 </dt>
755 <dd>
757 Ignore whitespace when comparing lines. This ignores
758 differences even if one line has whitespace where the other
759 line has none.
760 </p>
761 </dd>
762 <dt>
763 --inter-hunk-context=&lt;lines&gt;
764 </dt>
765 <dd>
767 Show the context between diff hunks, up to the specified number
768 of lines, thereby fusing hunks that are close to each other.
769 </p>
770 </dd>
771 <dt>
772 --exit-code
773 </dt>
774 <dd>
776 Make the program exit with codes similar to diff(1).
777 That is, it exits with 1 if there were differences and
778 0 means no differences.
779 </p>
780 </dd>
781 <dt>
782 --quiet
783 </dt>
784 <dd>
786 Disable all output of the program. Implies <tt>--exit-code</tt>.
787 </p>
788 </dd>
789 <dt>
790 --ext-diff
791 </dt>
792 <dd>
794 Allow an external diff helper to be executed. If you set an
795 external diff driver with <a href="gitattributes.html">gitattributes(5)</a>, you need
796 to use this option with <a href="git-log.html">git-log(1)</a> and friends.
797 </p>
798 </dd>
799 <dt>
800 --no-ext-diff
801 </dt>
802 <dd>
804 Disallow external diff drivers.
805 </p>
806 </dd>
807 <dt>
808 --ignore-submodules
809 </dt>
810 <dd>
812 Ignore changes to submodules in the diff generation.
813 </p>
814 </dd>
815 <dt>
816 --src-prefix=&lt;prefix&gt;
817 </dt>
818 <dd>
820 Show the given source prefix instead of "a/".
821 </p>
822 </dd>
823 <dt>
824 --dst-prefix=&lt;prefix&gt;
825 </dt>
826 <dd>
828 Show the given destination prefix instead of "b/".
829 </p>
830 </dd>
831 <dt>
832 --no-prefix
833 </dt>
834 <dd>
836 Do not show any source or destination prefix.
837 </p>
838 </dd>
839 </dl></div>
840 <div class="para"><p>For more detailed explanation on these common options, see also
841 <a href="gitdiffcore.html">gitdiffcore(7)</a>.</p></div>
842 <div class="vlist"><dl>
843 <dt>
844 &lt;tree-ish&gt;
845 </dt>
846 <dd>
848 The id of a tree object to diff against.
849 </p>
850 </dd>
851 <dt>
852 --cached
853 </dt>
854 <dd>
856 do not consider the on-disk file at all
857 </p>
858 </dd>
859 <dt>
861 </dt>
862 <dd>
864 By default, files recorded in the index but not checked
865 out are reported as deleted. This flag makes
866 <em>git diff-index</em> say that all non-checked-out files are up
867 to date.
868 </p>
869 </dd>
870 </dl></div>
871 </div>
872 <h2 id="_raw_output_format">Raw output format</h2>
873 <div class="sectionbody">
874 <div class="para"><p>The raw output format from "git-diff-index", "git-diff-tree",
875 "git-diff-files" and "git diff --raw" are very similar.</p></div>
876 <div class="para"><p>These commands all compare two sets of things; what is
877 compared differs:</p></div>
878 <div class="vlist"><dl>
879 <dt>
880 git-diff-index &lt;tree-ish&gt;
881 </dt>
882 <dd>
884 compares the &lt;tree-ish&gt; and the files on the filesystem.
885 </p>
886 </dd>
887 <dt>
888 git-diff-index --cached &lt;tree-ish&gt;
889 </dt>
890 <dd>
892 compares the &lt;tree-ish&gt; and the index.
893 </p>
894 </dd>
895 <dt>
896 git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
897 </dt>
898 <dd>
900 compares the trees named by the two arguments.
901 </p>
902 </dd>
903 <dt>
904 git-diff-files [&lt;pattern&gt;&#8230;]
905 </dt>
906 <dd>
908 compares the index and the files on the filesystem.
909 </p>
910 </dd>
911 </dl></div>
912 <div class="para"><p>The "git-diff-tree" command begins its output by printing the hash of
913 what is being compared. After that, all the commands print one output
914 line per changed file.</p></div>
915 <div class="para"><p>An output line is formatted this way:</p></div>
916 <div class="listingblock">
917 <div class="content">
918 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
919 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
920 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
921 create :000000 100644 0000000... 1234567... A file4
922 delete :100644 000000 1234567... 0000000... D file5
923 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
924 </div></div>
925 <div class="para"><p>That is, from the left to the right:</p></div>
926 <div class="olist"><ol>
927 <li>
929 a colon.
930 </p>
931 </li>
932 <li>
934 mode for "src"; 000000 if creation or unmerged.
935 </p>
936 </li>
937 <li>
939 a space.
940 </p>
941 </li>
942 <li>
944 mode for "dst"; 000000 if deletion or unmerged.
945 </p>
946 </li>
947 <li>
949 a space.
950 </p>
951 </li>
952 <li>
954 sha1 for "src"; 0{40} if creation or unmerged.
955 </p>
956 </li>
957 <li>
959 a space.
960 </p>
961 </li>
962 <li>
964 sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
965 </p>
966 </li>
967 <li>
969 a space.
970 </p>
971 </li>
972 <li>
974 status, followed by optional "score" number.
975 </p>
976 </li>
977 <li>
979 a tab or a NUL when <em>-z</em> option is used.
980 </p>
981 </li>
982 <li>
984 path for "src"
985 </p>
986 </li>
987 <li>
989 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
990 </p>
991 </li>
992 <li>
994 path for "dst"; only exists for C or R.
995 </p>
996 </li>
997 <li>
999 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1000 </p>
1001 </li>
1002 </ol></div>
1003 <div class="para"><p>Possible status letters are:</p></div>
1004 <div class="ilist"><ul>
1005 <li>
1007 A: addition of a file
1008 </p>
1009 </li>
1010 <li>
1012 C: copy of a file into a new one
1013 </p>
1014 </li>
1015 <li>
1017 D: deletion of a file
1018 </p>
1019 </li>
1020 <li>
1022 M: modification of the contents or mode of a file
1023 </p>
1024 </li>
1025 <li>
1027 R: renaming of a file
1028 </p>
1029 </li>
1030 <li>
1032 T: change in the type of the file
1033 </p>
1034 </li>
1035 <li>
1037 U: file is unmerged (you must complete the merge before it can
1038 be committed)
1039 </p>
1040 </li>
1041 <li>
1043 X: "unknown" change type (most probably a bug, please report it)
1044 </p>
1045 </li>
1046 </ul></div>
1047 <div class="para"><p>Status letters C and R are always followed by a score (denoting the
1048 percentage of similarity between the source and target of the move or
1049 copy), and are the only ones to be so.</p></div>
1050 <div class="para"><p>&lt;sha1&gt; is shown as all 0's if a file is new on the filesystem
1051 and it is out of sync with the index.</p></div>
1052 <div class="para"><p>Example:</p></div>
1053 <div class="listingblock">
1054 <div class="content">
1055 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1056 </div></div>
1057 <div class="para"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1058 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1059 respectively.</p></div>
1060 </div>
1061 <h2 id="_diff_format_for_merges">diff format for merges</h2>
1062 <div class="sectionbody">
1063 <div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff --raw"
1064 can take <em>-c</em> or <em>--cc</em> option
1065 to generate diff output also for merge commits. The output differs
1066 from the format described above in the following way:</p></div>
1067 <div class="olist"><ol>
1068 <li>
1070 there is a colon for each parent
1071 </p>
1072 </li>
1073 <li>
1075 there are more "src" modes and "src" sha1
1076 </p>
1077 </li>
1078 <li>
1080 status is concatenated status characters for each parent
1081 </p>
1082 </li>
1083 <li>
1085 no optional "score" number
1086 </p>
1087 </li>
1088 <li>
1090 single path, only for "dst"
1091 </p>
1092 </li>
1093 </ol></div>
1094 <div class="para"><p>Example:</p></div>
1095 <div class="listingblock">
1096 <div class="content">
1097 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1098 </div></div>
1099 <div class="para"><p>Note that <em>combined diff</em> lists only files which were modified from
1100 all parents.</p></div>
1101 </div>
1102 <h2 id="_generating_patches_with_p">Generating patches with -p</h2>
1103 <div class="sectionbody">
1104 <div class="para"><p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
1105 with a <em>-p</em> option, "git diff" without the <em>--raw</em> option, or
1106 "git log" with the "-p" option, they
1107 do not produce the output described above; instead they produce a
1108 patch file. You can customize the creation of such patches via the
1109 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1110 <div class="para"><p>What the -p option produces is slightly different from the traditional
1111 diff format.</p></div>
1112 <div class="olist"><ol>
1113 <li>
1115 It is preceded with a "git diff" header, that looks like
1116 this:
1117 </p>
1118 <div class="literalblock">
1119 <div class="content">
1120 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1121 </div></div>
1122 <div class="para"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1123 involved. Especially, even for a creation or a deletion,
1124 <tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1125 <div class="para"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1126 name of the source file of the rename/copy and the name of
1127 the file that rename/copy produces, respectively.</p></div>
1128 </li>
1129 <li>
1131 It is followed by one or more extended header lines:
1132 </p>
1133 <div class="literalblock">
1134 <div class="content">
1135 <pre><tt>old mode &lt;mode&gt;
1136 new mode &lt;mode&gt;
1137 deleted file mode &lt;mode&gt;
1138 new file mode &lt;mode&gt;
1139 copy from &lt;path&gt;
1140 copy to &lt;path&gt;
1141 rename from &lt;path&gt;
1142 rename to &lt;path&gt;
1143 similarity index &lt;number&gt;
1144 dissimilarity index &lt;number&gt;
1145 index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</tt></pre>
1146 </div></div>
1147 </li>
1148 <li>
1150 TAB, LF, double quote and backslash characters in pathnames
1151 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and <tt>\\</tt>, respectively.
1152 If there is need for such substitution then the whole
1153 pathname is put in double quotes.
1154 </p>
1155 </li>
1156 </ol></div>
1157 <div class="para"><p>The similarity index is the percentage of unchanged lines, and
1158 the dissimilarity index is the percentage of changed lines. It
1159 is a rounded down integer, followed by a percent sign. The
1160 similarity index value of 100% is thus reserved for two equal
1161 files, while 100% dissimilarity means that no line from the old
1162 file made it into the new one.</p></div>
1163 </div>
1164 <h2 id="_combined_diff_format">combined diff format</h2>
1165 <div class="sectionbody">
1166 <div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff" can take <em>-c</em> or
1167 <em>--cc</em> option to produce <em>combined diff</em>. For showing a merge commit
1168 with "git log -p", this is the default format; you can force showing
1169 full diff with the <em>-m</em> option.
1170 A <em>combined diff</em> format looks like this:</p></div>
1171 <div class="listingblock">
1172 <div class="content">
1173 <pre><tt>diff --combined describe.c
1174 index fabadb8,cc95eb0..4866510
1175 --- a/describe.c
1176 +++ b/describe.c
1177 @@@ -98,20 -98,12 +98,20 @@@
1178 return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
1181 - static void describe(char *arg)
1182 -static void describe(struct commit *cmit, int last_one)
1183 ++static void describe(char *arg, int last_one)
1185 + unsigned char sha1[20];
1186 + struct commit *cmit;
1187 struct commit_list *list;
1188 static int initialized = 0;
1189 struct commit_name *n;
1191 + if (get_sha1(arg, sha1) &lt; 0)
1192 + usage(describe_usage);
1193 + cmit = lookup_commit_reference(sha1);
1194 + if (!cmit)
1195 + usage(describe_usage);
1197 if (!initialized) {
1198 initialized = 1;
1199 for_each_ref(get_name);</tt></pre>
1200 </div></div>
1201 <div class="olist"><ol>
1202 <li>
1204 It is preceded with a "git diff" header, that looks like
1205 this (when <em>-c</em> option is used):
1206 </p>
1207 <div class="literalblock">
1208 <div class="content">
1209 <pre><tt>diff --combined file</tt></pre>
1210 </div></div>
1211 <div class="para"><p>or like this (when <em>--cc</em> option is used):</p></div>
1212 <div class="literalblock">
1213 <div class="content">
1214 <pre><tt>diff --cc file</tt></pre>
1215 </div></div>
1216 </li>
1217 <li>
1219 It is followed by one or more extended header lines
1220 (this example shows a merge with two parents):
1221 </p>
1222 <div class="literalblock">
1223 <div class="content">
1224 <pre><tt>index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;
1225 mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;
1226 new file mode &lt;mode&gt;
1227 deleted file mode &lt;mode&gt;,&lt;mode&gt;</tt></pre>
1228 </div></div>
1229 <div class="para"><p>The <tt>mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;</tt> line appears only if at least one of
1230 the &lt;mode&gt; is different from the rest. Extended headers with
1231 information about detected contents movement (renames and
1232 copying detection) are designed to work with diff of two
1233 &lt;tree-ish&gt; and are not used by combined diff format.</p></div>
1234 </li>
1235 <li>
1237 It is followed by two-line from-file/to-file header
1238 </p>
1239 <div class="literalblock">
1240 <div class="content">
1241 <pre><tt>--- a/file
1242 +++ b/file</tt></pre>
1243 </div></div>
1244 <div class="para"><p>Similar to two-line header for traditional <em>unified</em> diff
1245 format, <tt>/dev/null</tt> is used to signal created or deleted
1246 files.</p></div>
1247 </li>
1248 <li>
1250 Chunk header format is modified to prevent people from
1251 accidentally feeding it to <tt>patch -p1</tt>. Combined diff format
1252 was created for review of merge commit changes, and was not
1253 meant for apply. The change is similar to the change in the
1254 extended <em>index</em> header:
1255 </p>
1256 <div class="literalblock">
1257 <div class="content">
1258 <pre><tt>@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</tt></pre>
1259 </div></div>
1260 <div class="para"><p>There are (number of parents + 1) <tt>@</tt> characters in the chunk
1261 header for combined diff format.</p></div>
1262 </li>
1263 </ol></div>
1264 <div class="para"><p>Unlike the traditional <em>unified</em> diff format, which shows two
1265 files A and B with a single column that has <tt>-</tt> (minus &#8212;
1266 appears in A but removed in B), <tt>+</tt> (plus &#8212; missing in A but
1267 added to B), or <tt>" "</tt> (space &#8212; unchanged) prefix, this format
1268 compares two or more files file1, file2,&#8230; with one file X, and
1269 shows how X differs from each of fileN. One column for each of
1270 fileN is prepended to the output line to note how X's line is
1271 different from it.</p></div>
1272 <div class="para"><p>A <tt>-</tt> character in the column N means that the line appears in
1273 fileN but it does not appear in the result. A <tt>+</tt> character
1274 in the column N means that the line appears in the result,
1275 and fileN does not have that line (in other words, the line was
1276 added, from the point of view of that parent).</p></div>
1277 <div class="para"><p>In the above example output, the function signature was changed
1278 from both files (hence two <tt>-</tt> removals from both file1 and
1279 file2, plus <tt>++</tt> to mean one line that was added does not appear
1280 in either file1 nor file2). Also eight other lines are the same
1281 from file1 but do not appear in file2 (hence prefixed with <tt>&#43;</tt>).</p></div>
1282 <div class="para"><p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
1283 merge commit with the merge result (i.e. file1..fileN are the
1284 parents). When shown by <tt>git diff-files -c</tt>, it compares the
1285 two unresolved merge parents with the working tree file
1286 (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
1287 "their version").</p></div>
1288 </div>
1289 <h2 id="_other_diff_formats">other diff formats</h2>
1290 <div class="sectionbody">
1291 <div class="para"><p>The <tt>--summary</tt> option describes newly added, deleted, renamed and
1292 copied files. The <tt>--stat</tt> option adds diffstat(1) graph to the
1293 output. These options can be combined with other options, such as
1294 <tt>-p</tt>, and are meant for human consumption.</p></div>
1295 <div class="para"><p>When showing a change that involves a rename or a copy, <tt>--stat</tt> output
1296 formats the pathnames compactly by combining common prefix and suffix of
1297 the pathnames. For example, a change that moves <tt>arch/i386/Makefile</tt> to
1298 <tt>arch/x86/Makefile</tt> while modifying 4 lines will be shown like this:</p></div>
1299 <div class="listingblock">
1300 <div class="content">
1301 <pre><tt>arch/{i386 =&gt; x86}/Makefile | 4 +--</tt></pre>
1302 </div></div>
1303 <div class="para"><p>The <tt>--numstat</tt> option gives the diffstat(1) information but is designed
1304 for easier machine consumption. An entry in <tt>--numstat</tt> output looks
1305 like this:</p></div>
1306 <div class="listingblock">
1307 <div class="content">
1308 <pre><tt>1 2 README
1309 3 1 arch/{i386 =&gt; x86}/Makefile</tt></pre>
1310 </div></div>
1311 <div class="para"><p>That is, from left to right:</p></div>
1312 <div class="olist"><ol>
1313 <li>
1315 the number of added lines;
1316 </p>
1317 </li>
1318 <li>
1320 a tab;
1321 </p>
1322 </li>
1323 <li>
1325 the number of deleted lines;
1326 </p>
1327 </li>
1328 <li>
1330 a tab;
1331 </p>
1332 </li>
1333 <li>
1335 pathname (possibly with rename/copy information);
1336 </p>
1337 </li>
1338 <li>
1340 a newline.
1341 </p>
1342 </li>
1343 </ol></div>
1344 <div class="para"><p>When <tt>-z</tt> output option is in effect, the output is formatted this way:</p></div>
1345 <div class="listingblock">
1346 <div class="content">
1347 <pre><tt>1 2 README NUL
1348 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</tt></pre>
1349 </div></div>
1350 <div class="para"><p>That is:</p></div>
1351 <div class="olist"><ol>
1352 <li>
1354 the number of added lines;
1355 </p>
1356 </li>
1357 <li>
1359 a tab;
1360 </p>
1361 </li>
1362 <li>
1364 the number of deleted lines;
1365 </p>
1366 </li>
1367 <li>
1369 a tab;
1370 </p>
1371 </li>
1372 <li>
1374 a NUL (only exists if renamed/copied);
1375 </p>
1376 </li>
1377 <li>
1379 pathname in preimage;
1380 </p>
1381 </li>
1382 <li>
1384 a NUL (only exists if renamed/copied);
1385 </p>
1386 </li>
1387 <li>
1389 pathname in postimage (only exists if renamed/copied);
1390 </p>
1391 </li>
1392 <li>
1394 a NUL.
1395 </p>
1396 </li>
1397 </ol></div>
1398 <div class="para"><p>The extra <tt>NUL</tt> before the preimage path in renamed case is to allow
1399 scripts that read the output to tell if the current record being read is
1400 a single-path record or a rename/copy record without reading ahead.
1401 After reading added and deleted lines, reading up to <tt>NUL</tt> would yield
1402 the pathname, but if that is <tt>NUL</tt>, the record will show two paths.</p></div>
1403 </div>
1404 <h2 id="_operating_modes">Operating Modes</h2>
1405 <div class="sectionbody">
1406 <div class="para"><p>You can choose whether you want to trust the index file entirely
1407 (using the <em>--cached</em> flag) or ask the diff logic to show any files
1408 that don't match the stat state as being "tentatively changed". Both
1409 of these operations are very useful indeed.</p></div>
1410 </div>
1411 <h2 id="_cached_mode">Cached Mode</h2>
1412 <div class="sectionbody">
1413 <div class="para"><p>If <em>--cached</em> is specified, it allows you to ask:</p></div>
1414 <div class="literalblock">
1415 <div class="content">
1416 <pre><tt>show me the differences between HEAD and the current index
1417 contents (the ones I'd write using 'git write-tree')</tt></pre>
1418 </div></div>
1419 <div class="para"><p>For example, let's say that you have worked on your working directory, updated
1420 some files in the index and are ready to commit. You want to see exactly
1421 <strong>what</strong> you are going to commit, without having to write a new tree
1422 object and compare it that way, and to do that, you just do</p></div>
1423 <div class="literalblock">
1424 <div class="content">
1425 <pre><tt>git diff-index --cached HEAD</tt></pre>
1426 </div></div>
1427 <div class="para"><p>Example: let's say I had renamed <tt>commit.c</tt> to <tt>git-commit.c</tt>, and I had
1428 done an <tt>update-index</tt> to make that effective in the index file.
1429 <tt>git diff-files</tt> wouldn't show anything at all, since the index file
1430 matches my working directory. But doing a <em>git diff-index</em> does:</p></div>
1431 <div class="literalblock">
1432 <div class="content">
1433 <pre><tt>torvalds@ppc970:~/git&gt; git diff-index --cached HEAD
1434 -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1435 +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c</tt></pre>
1436 </div></div>
1437 <div class="para"><p>You can see easily that the above is a rename.</p></div>
1438 <div class="para"><p>In fact, <tt>git diff-index --cached</tt> <strong>should</strong> always be entirely equivalent to
1439 actually doing a <em>git write-tree</em> and comparing that. Except this one is much
1440 nicer for the case where you just want to check where you are.</p></div>
1441 <div class="para"><p>So doing a <tt>git diff-index --cached</tt> is basically very useful when you are
1442 asking yourself "what have I already marked for being committed, and
1443 what's the difference to a previous tree".</p></div>
1444 </div>
1445 <h2 id="_non_cached_mode">Non-cached Mode</h2>
1446 <div class="sectionbody">
1447 <div class="para"><p>The "non-cached" mode takes a different approach, and is potentially
1448 the more useful of the two in that what it does can't be emulated with
1449 a <em>git write-tree</em> + <em>git diff-tree</em>. Thus that's the default mode.
1450 The non-cached version asks the question:</p></div>
1451 <div class="literalblock">
1452 <div class="content">
1453 <pre><tt>show me the differences between HEAD and the currently checked out
1454 tree - index contents _and_ files that aren't up-to-date</tt></pre>
1455 </div></div>
1456 <div class="para"><p>which is obviously a very useful question too, since that tells you what
1457 you <strong>could</strong> commit. Again, the output matches the <em>git diff-tree -r</em>
1458 output to a tee, but with a twist.</p></div>
1459 <div class="para"><p>The twist is that if some file doesn't match the index, we don't have
1460 a backing store thing for it, and we use the magic "all-zero" sha1 to
1461 show that. So let's say that you have edited <tt>kernel/sched.c</tt>, but
1462 have not actually done a <em>git update-index</em> on it yet - there is no
1463 "object" associated with the new state, and you get:</p></div>
1464 <div class="literalblock">
1465 <div class="content">
1466 <pre><tt>torvalds@ppc970:~/v2.6/linux&gt; git diff-index HEAD
1467 *100644-&gt;100664 blob 7476bb......-&gt;000000...... kernel/sched.c</tt></pre>
1468 </div></div>
1469 <div class="para"><p>i.e., it shows that the tree has changed, and that <tt>kernel/sched.c</tt> has is
1470 not up-to-date and may contain new stuff. The all-zero sha1 means that to
1471 get the real diff, you need to look at the object in the working directory
1472 directly rather than do an object-to-object diff.</p></div>
1473 <div class="admonitionblock">
1474 <table><tr>
1475 <td class="icon">
1476 <div class="title">Note</div>
1477 </td>
1478 <td class="content">As with other commands of this type, <em>git diff-index</em> does not
1479 actually look at the contents of the file at all. So maybe
1480 <tt>kernel/sched.c</tt> hasn't actually changed, and it's just that you
1481 touched it. In either case, it's a note that you need to
1482 <em>git update-index</em> it to make the index be in sync.</td>
1483 </tr></table>
1484 </div>
1485 <div class="admonitionblock">
1486 <table><tr>
1487 <td class="icon">
1488 <div class="title">Note</div>
1489 </td>
1490 <td class="content">You can have a mixture of files show up as "has been updated"
1491 and "is still dirty in the working directory" together. You can always
1492 tell which file is in which state, since the "has been updated" ones
1493 show a valid sha1, and the "not in sync with the index" ones will
1494 always have the special all-zero sha1.</td>
1495 </tr></table>
1496 </div>
1497 </div>
1498 <h2 id="_author">Author</h2>
1499 <div class="sectionbody">
1500 <div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
1501 </div>
1502 <h2 id="_documentation">Documentation</h2>
1503 <div class="sectionbody">
1504 <div class="para"><p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
1505 </div>
1506 <h2 id="_git">GIT</h2>
1507 <div class="sectionbody">
1508 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1509 </div>
1510 <div id="footer">
1511 <div id="footer-text">
1512 Last updated 2010-04-24 02:55:52 UTC
1513 </div>
1514 </div>
1515 </body>
1516 </html>