1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\r
6 <meta name="generator" content="AsciiDoc 7.0.2" />
\r
7 <style type="text/css">
\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
\r
11 border: 1px solid red;
\r
16 margin: 1em 5% 1em 5%;
\r
20 a:visited { color: fuchsia; }
\r
34 h1, h2, h3, h4, h5, h6 {
\r
36 font-family: sans-serif;
\r
38 margin-bottom: 0.5em;
\r
43 border-bottom: 2px solid silver;
\r
46 border-bottom: 2px solid silver;
\r
56 border: 1px solid silver;
\r
61 margin-bottom: 0.5em;
\r
71 font-family: sans-serif;
\r
78 font-family: sans-serif;
\r
82 font-family: sans-serif;
\r
84 border-top: 2px solid silver;
\r
90 padding-bottom: 0.5em;
\r
94 padding-bottom: 0.5em;
\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
100 div.admonitionblock {
\r
103 margin-bottom: 1.5em;
\r
105 div.admonitionblock {
\r
107 margin-bottom: 2.5em;
\r
110 div.content { /* Block element content. */
\r
114 /* Block element titles. */
\r
115 div.title, caption.title {
\r
116 font-family: sans-serif;
\r
120 margin-bottom: 0.5em;
\r
126 td div.title:first-child {
\r
129 div.content div.title:first-child {
\r
132 div.content + div.title {
\r
136 div.sidebarblock > div.content {
\r
137 background: #ffffee;
\r
138 border: 1px solid silver;
\r
142 div.listingblock > div.content {
\r
143 border: 1px solid silver;
\r
144 background: #f4f4f4;
\r
148 div.quoteblock > div.content {
\r
149 padding-left: 2.0em;
\r
151 div.quoteblock .attribution {
\r
155 div.admonitionblock .icon {
\r
156 vertical-align: top;
\r
159 text-decoration: underline;
\r
161 padding-right: 0.5em;
\r
163 div.admonitionblock td.content {
\r
164 padding-left: 0.5em;
\r
165 border-left: 2px solid silver;
\r
168 div.exampleblock > div.content {
\r
169 border-left: 2px solid silver;
\r
173 div.verseblock div.content {
\r
177 div.imageblock div.content { padding-left: 0; }
\r
178 div.imageblock img { border: 1px solid silver; }
\r
179 span.image img { border-style: none; }
\r
183 margin-bottom: 0.8em;
\r
188 font-style: italic;
\r
190 dd > *:first-child {
\r
195 list-style-position: outside;
\r
198 list-style-type: lower-alpha;
\r
201 div.tableblock > table {
\r
202 border-color: #527bbd;
\r
206 font-family: sans-serif;
\r
215 margin-bottom: 0.8em;
\r
218 vertical-align: top;
\r
219 font-style: italic;
\r
220 padding-right: 0.8em;
\r
223 vertical-align: top;
\r
227 div#footer-badges { display: none; }
\r
229 include::./stylesheets/xhtml11-manpage.css[]
\r
230 /* Workarounds for IE6's broken and incomplete CSS2. */
\r
232 div.sidebar-content {
\r
233 background: #ffffee;
\r
234 border: 1px solid silver;
\r
237 div.sidebar-title, div.image-title {
\r
238 font-family: sans-serif;
\r
241 margin-bottom: 0.5em;
\r
244 div.listingblock div.content {
\r
245 border: 1px solid silver;
\r
246 background: #f4f4f4;
\r
250 div.quoteblock-content {
\r
251 padding-left: 2.0em;
\r
254 div.exampleblock-content {
\r
255 border-left: 2px solid silver;
\r
256 padding-left: 0.5em;
\r
259 <title>git-diff-index(1)</title>
\r
264 git-diff-index(1) Manual Page
\r
267 <div class="sectionbody">
\r
268 <p>git-diff-index -
\r
269 Compares content and mode of blobs between the index and repository
\r
274 <div class="sectionbody">
\r
275 <p><em>git-diff-index</em> [-m] [--cached] [<common diff options>] <tree-ish> [<path>…]</p>
\r
277 <h2>DESCRIPTION</h2>
\r
278 <div class="sectionbody">
\r
279 <p>Compares the content and mode of the blobs found via a tree
\r
280 object with the content of the current index and, optionally
\r
281 ignoring the stat state of the file on disk. When paths are
\r
282 specified, compares only those named paths. Otherwise all
\r
283 entries in the index are compared.</p>
\r
286 <div class="sectionbody">
\r
293 Generate patch (see section on generating patches)
\r
309 Generate patch but keep also the default raw diff output.
\r
317 Generate a diffstat instead of a patch.
\r
325 Generate patch and prepend its diffstat.
\r
333 \0 line termination on output
\r
341 Show only names of changed files.
\r
349 Show only names and status of changed files.
\r
357 Instead of the first handful characters, show full
\r
358 object name of pre- and post-image blob on the "index"
\r
359 line when generating a patch format output.
\r
363 --abbrev[=<n>]
\r
367 Instead of showing the full 40-byte hexadecimal object
\r
368 name in diff-raw format output and diff-tree header
\r
369 lines, show only handful hexdigits prefix. This is
\r
370 independent of --full-index option above, which controls
\r
371 the diff-patch output format. Non default number of
\r
372 digits can be specified with --abbrev=<n>.
\r
380 Break complete rewrite changes into pairs of delete and create.
\r
396 Detect copies as well as renames.
\r
400 --diff-filter=[ACDMRTUXB*]
\r
404 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
\r
405 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
\r
406 type (mode) changed (<tt>T</tt>), are Unmerged (<tt>U</tt>), are
\r
407 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
\r
408 Any combination of the filter characters may be used.
\r
409 When <tt>*</tt> (All-or-none) is added to the combination, all
\r
410 paths are selected if there is any file that matches
\r
411 other criteria in the comparison; if there is no file
\r
412 that matches other criteria, nothing is selected.
\r
416 --find-copies-harder
\r
420 For performance reasons, by default, -C option finds copies only
\r
421 if the original file of the copy was modified in the same
\r
422 changeset. This flag makes the command
\r
423 inspect unmodified files as candidates for the source of
\r
424 copy. This is a very expensive operation for large
\r
425 projects, so use it with caution.
\r
433 -M and -C options require O(n^2) processing time where n
\r
434 is the number of potential rename/copy targets. This
\r
435 option prevents rename/copy detection from running if
\r
436 the number of rename/copy targets exceeds the specified
\r
445 Look for differences that contain the change in <string>.
\r
453 When -S finds a change, show all the changes in that
\r
454 changeset, not just the files that contain the change
\r
463 Make the <string> not a plain string but an extended POSIX
\r
468 -O<orderfile>
\r
472 Output the patch in the order specified in the
\r
473 <orderfile>, which has one shell glob pattern per line.
\r
481 Swap two inputs; that is, show differences from index or
\r
482 on-disk file to tree contents.
\r
486 <p>For more detailed explanation on these common options, see also
\r
487 <a href="diffcore.html">diffcore documentation</a>.</p>
\r
494 The id of a tree object to diff against.
\r
502 do not consider the on-disk file at all
\r
510 By default, files recorded in the index but not checked
\r
511 out are reported as deleted. This flag makes
\r
512 "git-diff-index" say that all non-checked-out files are up
\r
518 <h2>Output format</h2>
\r
519 <div class="sectionbody">
\r
520 <p>The output format from "git-diff-index", "git-diff-tree" and
\r
521 "git-diff-files" are very similar.</p>
\r
522 <p>These commands all compare two sets of things; what is
\r
523 compared differs:</p>
\r
526 git-diff-index <tree-ish>
\r
530 compares the <tree-ish> and the files on the filesystem.
\r
534 git-diff-index --cached <tree-ish>
\r
538 compares the <tree-ish> and the index.
\r
542 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
\r
546 compares the trees named by the two arguments.
\r
550 git-diff-files [<pattern>…]
\r
554 compares the index and the files on the filesystem.
\r
558 <p>An output line is formatted this way:</p>
\r
559 <div class="listingblock">
\r
560 <div class="content">
\r
561 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
\r
562 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
\r
563 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
\r
564 create :000000 100644 0000000... 1234567... A file4
\r
565 delete :100644 000000 1234567... 0000000... D file5
\r
566 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
\r
568 <p>That is, from the left to the right:</p>
\r
577 mode for "src"; 000000 if creation or unmerged.
\r
587 mode for "dst"; 000000 if deletion or unmerged.
\r
597 sha1 for "src"; 0{40} if creation or unmerged.
\r
607 sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
\r
617 status, followed by optional "score" number.
\r
622 a tab or a NUL when <em>-z</em> option is used.
\r
632 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
\r
637 path for "dst"; only exists for C or R.
\r
642 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
\r
646 <p><sha1> is shown as all 0's if a file is new on the filesystem
\r
647 and it is out of sync with the index.</p>
\r
649 <div class="listingblock">
\r
650 <div class="content">
\r
651 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
\r
653 <p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
\r
654 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
\r
657 <h2>Generating patches with -p</h2>
\r
658 <div class="sectionbody">
\r
659 <p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
\r
660 with a <em>-p</em> option, they do not produce the output described above;
\r
661 instead they produce a patch file.</p>
\r
662 <p>The patch generation can be customized at two levels.</p>
\r
666 When the environment variable <em>GIT_EXTERNAL_DIFF</em> is not set,
\r
667 these commands internally invoke "diff" like this:
\r
669 <div class="literalblock">
\r
670 <div class="content">
\r
671 <pre><tt>diff -L a/<path> -L b/<path> -pu <old> <new></tt></pre>
\r
673 <p>For added files, <tt>/dev/null</tt> is used for <old>. For removed
\r
674 files, <tt>/dev/null</tt> is used for <new></p>
\r
675 <p>The "diff" formatting options can be customized via the
\r
676 environment variable <em>GIT_DIFF_OPTS</em>. For example, if you
\r
677 prefer context diff:</p>
\r
678 <div class="literalblock">
\r
679 <div class="content">
\r
680 <pre><tt>GIT_DIFF_OPTS=-c git-diff-index -p HEAD</tt></pre>
\r
685 When the environment variable <em>GIT_EXTERNAL_DIFF</em> is set, the
\r
686 program named by it is called, instead of the diff invocation
\r
689 <p>For a path that is added, removed, or modified,
\r
690 <em>GIT_EXTERNAL_DIFF</em> is called with 7 parameters:</p>
\r
691 <div class="literalblock">
\r
692 <div class="content">
\r
693 <pre><tt>path old-file old-hex old-mode new-file new-hex new-mode</tt></pre>
\r
696 <div class="hlist"><table>
\r
698 <td class="hlist1">
\r
699 <old|new>-file
\r
701 <td class="hlist2">
\r
702 are files GIT_EXTERNAL_DIFF can use to read the
\r
703 contents of <old|new>,
\r
707 <td class="hlist1">
\r
708 <old|new>-hex
\r
710 <td class="hlist2">
\r
711 are the 40-hexdigit SHA1 hashes,
\r
715 <td class="hlist1">
\r
716 <old|new>-mode
\r
718 <td class="hlist2">
\r
719 are the octal representation of the file modes.
\r
723 <p>The file parameters can point at the user's working file
\r
724 (e.g. <tt>new-file</tt> in "git-diff-files"), <tt>/dev/null</tt> (e.g. <tt>old-file</tt>
\r
725 when a new file is added), or a temporary file (e.g. <tt>old-file</tt> in the
\r
726 index). <em>GIT_EXTERNAL_DIFF</em> should not worry about unlinking the
\r
727 temporary file --- it is removed when <em>GIT_EXTERNAL_DIFF</em> exits.</p>
\r
730 <p>For a path that is unmerged, <em>GIT_EXTERNAL_DIFF</em> is called with 1
\r
731 parameter, <path>.</p>
\r
733 <h2>git specific extension to diff format</h2>
\r
734 <div class="sectionbody">
\r
735 <p>What -p option produces is slightly different from the
\r
736 traditional diff format.</p>
\r
740 It is preceded with a "git diff" header, that looks like
\r
743 <div class="literalblock">
\r
744 <div class="content">
\r
745 <pre><tt>diff --git a/file1 b/file2</tt></pre>
\r
747 <p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
\r
748 involved. Especially, even for a creation or a deletion,
\r
749 <tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p>
\r
750 <p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
\r
751 name of the source file of the rename/copy and the name of
\r
752 the file that rename/copy produces, respectively.</p>
\r
756 It is followed by one or more extended header lines:
\r
758 <div class="literalblock">
\r
759 <div class="content">
\r
760 <pre><tt>old mode <mode>
\r
761 new mode <mode>
\r
762 deleted file mode <mode>
\r
763 new file mode <mode>
\r
764 copy from <path>
\r
765 copy to <path>
\r
766 rename from <path>
\r
767 rename to <path>
\r
768 similarity index <number>
\r
769 dissimilarity index <number>
\r
770 index <hash>..<hash> <mode></tt></pre>
\r
775 TAB, LF, and backslash characters in pathnames are
\r
776 represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>, respectively.
\r
781 <h2>combined diff format</h2>
\r
782 <div class="sectionbody">
\r
783 <p>git-diff-tree and git-diff-files can take <em>-c</em> or <em>--cc</em> option
\r
784 to produce <em>combined diff</em>, which looks like this:</p>
\r
785 <div class="listingblock">
\r
786 <div class="content">
\r
787 <pre><tt>diff --combined describe.c
\r
789 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
\r
792 - static void describe(char *arg)
\r
793 -static void describe(struct commit *cmit, int last_one)
\r
794 ++static void describe(char *arg, int last_one)
\r
796 + unsigned char sha1[20];
\r
797 + struct commit *cmit;</tt></pre>
\r
799 <p>Unlike the traditional <em>unified</em> diff format, which shows two
\r
800 files A and B with a single column that has <tt>-</tt> (minus —
\r
801 appears in A but removed in B), <tt>+</tt> (plus — missing in A but
\r
802 added to B), or <tt> </tt> (space — unchanged) prefix, this format
\r
803 compares two or more files file1, file2,… with one file X, and
\r
804 shows how X differs from each of fileN. One column for each of
\r
805 fileN is prepended to the output line to note how X's line is
\r
806 different from it.</p>
\r
807 <p>A <tt>-</tt> character in the column N means that the line appears in
\r
808 fileN but it does not appear in the last file. A <tt>+</tt> character
\r
809 in the column N means that the line appears in the last file,
\r
810 and fileN does not have that line.</p>
\r
811 <p>In the above example output, the function signature was changed
\r
812 from both files (hence two <tt>-</tt> removals from both file1 and
\r
813 file2, plus <tt>++</tt> to mean one line that was added does not appear
\r
814 in either file1 nor file2). Also two other lines are the same
\r
815 from file1 but do not appear in file2 (hence prefixed with <tt> +</tt>).</p>
\r
816 <p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
\r
817 merge commit with the merge result (i.e. file1..fileN are the
\r
818 parents). When shown by <tt>git diff-files -c</tt>, it compares the
\r
819 two unresolved merge parents with the working tree file
\r
820 (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
\r
821 "their version").</p>
\r
823 <h2>Operating Modes</h2>
\r
824 <div class="sectionbody">
\r
825 <p>You can choose whether you want to trust the index file entirely
\r
826 (using the <em>--cached</em> flag) or ask the diff logic to show any files
\r
827 that don't match the stat state as being "tentatively changed". Both
\r
828 of these operations are very useful indeed.</p>
\r
830 <h2>Cached Mode</h2>
\r
831 <div class="sectionbody">
\r
832 <p>If <em>--cached</em> is specified, it allows you to ask:</p>
\r
833 <div class="literalblock">
\r
834 <div class="content">
\r
835 <pre><tt>show me the differences between HEAD and the current index
\r
836 contents (the ones I'd write with a "git-write-tree")</tt></pre>
\r
838 <p>For example, let's say that you have worked on your working directory, updated
\r
839 some files in the index and are ready to commit. You want to see exactly
\r
840 <strong>what</strong> you are going to commit is without having to write a new tree
\r
841 object and compare it that way, and to do that, you just do</p>
\r
842 <div class="literalblock">
\r
843 <div class="content">
\r
844 <pre><tt>git-diff-index --cached HEAD</tt></pre>
\r
846 <p>Example: let's say I had renamed <tt>commit.c</tt> to <tt>git-commit.c</tt>, and I had
\r
847 done an "git-update-index" to make that effective in the index file.
\r
848 "git-diff-files" wouldn't show anything at all, since the index file
\r
849 matches my working directory. But doing a "git-diff-index" does:</p>
\r
850 <div class="literalblock">
\r
851 <div class="content">
\r
852 <pre><tt>torvalds@ppc970:~/git> git-diff-index --cached HEAD
\r
853 -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
\r
854 +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c</tt></pre>
\r
856 <p>You can trivially see that the above is a rename.</p>
\r
857 <p>In fact, "git-diff-index --cached" <strong>should</strong> always be entirely equivalent to
\r
858 actually doing a "git-write-tree" and comparing that. Except this one is much
\r
859 nicer for the case where you just want to check where you are.</p>
\r
860 <p>So doing a "git-diff-index --cached" is basically very useful when you are
\r
861 asking yourself "what have I already marked for being committed, and
\r
862 what's the difference to a previous tree".</p>
\r
864 <h2>Non-cached Mode</h2>
\r
865 <div class="sectionbody">
\r
866 <p>The "non-cached" mode takes a different approach, and is potentially
\r
867 the more useful of the two in that what it does can't be emulated with
\r
868 a "git-write-tree" + "git-diff-tree". Thus that's the default mode.
\r
869 The non-cached version asks the question:</p>
\r
870 <div class="literalblock">
\r
871 <div class="content">
\r
872 <pre><tt>show me the differences between HEAD and the currently checked out
\r
873 tree - index contents _and_ files that aren't up-to-date</tt></pre>
\r
875 <p>which is obviously a very useful question too, since that tells you what
\r
876 you <strong>could</strong> commit. Again, the output matches the "git-diff-tree -r"
\r
877 output to a tee, but with a twist.</p>
\r
878 <p>The twist is that if some file doesn't match the index, we don't have
\r
879 a backing store thing for it, and we use the magic "all-zero" sha1 to
\r
880 show that. So let's say that you have edited <tt>kernel/sched.c</tt>, but
\r
881 have not actually done a "git-update-index" on it yet - there is no
\r
882 "object" associated with the new state, and you get:</p>
\r
883 <div class="literalblock">
\r
884 <div class="content">
\r
885 <pre><tt>torvalds@ppc970:~/v2.6/linux> git-diff-index HEAD
\r
886 *100644->100664 blob 7476bb......->000000...... kernel/sched.c</tt></pre>
\r
888 <p>ie it shows that the tree has changed, and that <tt>kernel/sched.c</tt> has is
\r
889 not up-to-date and may contain new stuff. The all-zero sha1 means that to
\r
890 get the real diff, you need to look at the object in the working directory
\r
891 directly rather than do an object-to-object diff.</p>
\r
892 <div class="admonitionblock">
\r
895 <div class="title">Note</div>
\r
897 <td class="content">As with other commands of this type, "git-diff-index" does not
\r
898 actually look at the contents of the file at all. So maybe
\r
899 <tt>kernel/sched.c</tt> hasn't actually changed, and it's just that you
\r
900 touched it. In either case, it's a note that you need to
\r
901 "git-update-index" it to make the index be in sync.</td>
\r
904 <div class="admonitionblock">
\r
907 <div class="title">Note</div>
\r
909 <td class="content">You can have a mixture of files show up as "has been updated"
\r
910 and "is still dirty in the working directory" together. You can always
\r
911 tell which file is in which state, since the "has been updated" ones
\r
912 show a valid sha1, and the "not in sync with the index" ones will
\r
913 always have the special all-zero sha1.</td>
\r
918 <div class="sectionbody">
\r
919 <p>Written by Linus Torvalds <torvalds@osdl.org></p>
\r
921 <h2>Documentation</h2>
\r
922 <div class="sectionbody">
\r
923 <p>Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.</p>
\r
926 <div class="sectionbody">
\r
927 <p>Part of the <a href="git.html">git(7)</a> suite</p>
\r
930 <div id="footer-text">
\r
931 Last updated 16-Apr-2006 11:00:56 UTC
\r