blob: 7548db1c51aae28504d93e57b8d8079bbdb5466d [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!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" />
Junio C Hamano6ec31b92006-02-10 05:52:016<meta name="generator" content="AsciiDoc 7.0.2" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229include::./stylesheets/xhtml11-manpage.css[]
230/* Workarounds for IE6's broken and incomplete CSS2. */
231
232div.sidebar-content {
233 background: #ffffee;
234 border: 1px solid silver;
235 padding: 0.5em;
236}
237div.sidebar-title, div.image-title {
238 font-family: sans-serif;
239 font-weight: bold;
240 margin-top: 0.0em;
241 margin-bottom: 0.5em;
242}
243
244div.listingblock div.content {
245 border: 1px solid silver;
246 background: #f4f4f4;
247 padding: 0.5em;
248}
249
250div.quoteblock-content {
251 padding-left: 2.0em;
252}
253
254div.exampleblock-content {
255 border-left: 2px solid silver;
256 padding-left: 0.5em;
257}
258</style>
259<title>git-diff-index(1)</title>
260</head>
261<body>
262<div id="header">
263<h1>
264git-diff-index(1) Manual Page
265</h1>
266<h2>NAME</h2>
267<div class="sectionbody">
268<p>git-diff-index -
269 Compares content and mode of blobs between the index and repository
270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
275<p><em>git-diff-index</em> [-m] [--cached] [&lt;common diff options&gt;] &lt;tree-ish&gt; [&lt;path&gt;&#8230;]</p>
276</div>
277<h2>DESCRIPTION</h2>
278<div class="sectionbody">
279<p>Compares the content and mode of the blobs found via a tree
280object with the content of the current index and, optionally
281ignoring the stat state of the file on disk. When paths are
282specified, compares only those named paths. Otherwise all
283entries in the index are compared.</p>
284</div>
285<h2>OPTIONS</h2>
286<div class="sectionbody">
287<dl>
288<dt>
289-p
290</dt>
291<dd>
292<p>
293 Generate patch (see section on generating patches)
294</p>
295</dd>
296<dt>
297-u
298</dt>
299<dd>
300<p>
301 Synonym for "-p".
302</p>
303</dd>
304<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34305--raw
306</dt>
307<dd>
308<p>
309 Generate the raw format.
310</p>
311</dd>
312<dt>
Junio C Hamano54559c82006-04-13 07:45:12313--patch-with-raw
314</dt>
315<dd>
316<p>
Junio C Hamano9ae1a062006-07-10 08:12:34317 Synonym for "-p --raw".
Junio C Hamano54559c82006-04-13 07:45:12318</p>
319</dd>
320<dt>
Junio C Hamanoba7c8d82006-04-15 06:17:42321--stat
322</dt>
323<dd>
324<p>
Junio C Hamano9ae1a062006-07-10 08:12:34325 Generate a diffstat.
Junio C Hamanoba7c8d82006-04-15 06:17:42326</p>
327</dd>
328<dt>
Junio C Hamano6959c6c2006-05-17 10:34:11329--summary
330</dt>
331<dd>
332<p>
333 Output a condensed summary of extended header information
334 such as creations, renames and mode changes.
335</p>
336</dd>
337<dt>
Junio C Hamanod1308c92006-04-16 11:01:09338--patch-with-stat
339</dt>
340<dd>
341<p>
Junio C Hamano9ae1a062006-07-10 08:12:34342 Synonym for "-p --stat".
Junio C Hamanod1308c92006-04-16 11:01:09343</p>
344</dd>
345<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23346-z
347</dt>
348<dd>
349<p>
350 \0 line termination on output
351</p>
352</dd>
353<dt>
354--name-only
355</dt>
356<dd>
357<p>
358 Show only names of changed files.
359</p>
360</dd>
361<dt>
362--name-status
363</dt>
364<dd>
365<p>
366 Show only names and status of changed files.
367</p>
368</dd>
369<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34370--color
371</dt>
372<dd>
373<p>
374 Show colored diff.
375</p>
376</dd>
377<dt>
378--no-color
379</dt>
380<dd>
381<p>
382 Turn off colored diff, even when the configuration file
383 gives the default to color output.
384</p>
385</dd>
386<dt>
387--no-renames
388</dt>
389<dd>
390<p>
391 Turn off rename detection, even when the configuration
392 file gives the default to do so.
393</p>
394</dd>
395<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23396--full-index
397</dt>
398<dd>
399<p>
400 Instead of the first handful characters, show full
401 object name of pre- and post-image blob on the "index"
402 line when generating a patch format output.
403</p>
404</dd>
405<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34406--binary
407</dt>
408<dd>
409<p>
410 In addition to --full-index, output "binary diff" that
411 can be applied with "git apply".
412</p>
413</dd>
414<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23415--abbrev[=&lt;n&gt;]
416</dt>
417<dd>
418<p>
419 Instead of showing the full 40-byte hexadecimal object
420 name in diff-raw format output and diff-tree header
Junio C Hamano235a91e2006-01-07 01:13:58421 lines, show only handful hexdigits prefix. This is
Junio C Hamano1a4e8412005-12-27 08:17:23422 independent of --full-index option above, which controls
423 the diff-patch output format. Non default number of
424 digits can be specified with --abbrev=&lt;n&gt;.
425</p>
426</dd>
427<dt>
428-B
429</dt>
430<dd>
431<p>
432 Break complete rewrite changes into pairs of delete and create.
433</p>
434</dd>
435<dt>
436-M
437</dt>
438<dd>
439<p>
440 Detect renames.
441</p>
442</dd>
443<dt>
444-C
445</dt>
446<dd>
447<p>
448 Detect copies as well as renames.
449</p>
450</dd>
451<dt>
Junio C Hamano6ec31b92006-02-10 05:52:01452--diff-filter=[ACDMRTUXB*]
453</dt>
454<dd>
455<p>
456 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
457 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
458 type (mode) changed (<tt>T</tt>), are Unmerged (<tt>U</tt>), are
459 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
460 Any combination of the filter characters may be used.
461 When <tt>*</tt> (All-or-none) is added to the combination, all
462 paths are selected if there is any file that matches
463 other criteria in the comparison; if there is no file
464 that matches other criteria, nothing is selected.
465</p>
466</dd>
467<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23468--find-copies-harder
469</dt>
470<dd>
471<p>
472 For performance reasons, by default, -C option finds copies only
473 if the original file of the copy was modified in the same
474 changeset. This flag makes the command
475 inspect unmodified files as candidates for the source of
476 copy. This is a very expensive operation for large
477 projects, so use it with caution.
478</p>
479</dd>
480<dt>
481-l&lt;num&gt;
482</dt>
483<dd>
484<p>
485 -M and -C options require O(n^2) processing time where n
486 is the number of potential rename/copy targets. This
487 option prevents rename/copy detection from running if
488 the number of rename/copy targets exceeds the specified
489 number.
490</p>
491</dd>
492<dt>
493-S&lt;string&gt;
494</dt>
495<dd>
496<p>
497 Look for differences that contain the change in &lt;string&gt;.
498</p>
499</dd>
500<dt>
501--pickaxe-all
502</dt>
503<dd>
504<p>
505 When -S finds a change, show all the changes in that
506 changeset, not just the files that contain the change
507 in &lt;string&gt;.
508</p>
509</dd>
510<dt>
Junio C Hamanobfe9e752006-04-05 21:43:28511--pickaxe-regex
512</dt>
513<dd>
514<p>
515 Make the &lt;string&gt; not a plain string but an extended POSIX
516 regex to match.
517</p>
518</dd>
519<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23520-O&lt;orderfile&gt;
521</dt>
522<dd>
523<p>
524 Output the patch in the order specified in the
525 &lt;orderfile&gt;, which has one shell glob pattern per line.
526</p>
527</dd>
528<dt>
529-R
530</dt>
531<dd>
532<p>
533 Swap two inputs; that is, show differences from index or
534 on-disk file to tree contents.
535</p>
536</dd>
Junio C Hamanoc26f5482006-07-09 09:38:14537<dt>
538--text
539</dt>
540<dd>
541<p>
542 Treat all files as text.
543</p>
544</dd>
545<dt>
546-a
547</dt>
548<dd>
549<p>
550 Shorthand for "--text".
551</p>
552</dd>
Junio C Hamano1a4e8412005-12-27 08:17:23553</dl>
554<p>For more detailed explanation on these common options, see also
555<a href="diffcore.html">diffcore documentation</a>.</p>
556<dl>
557<dt>
558&lt;tree-ish&gt;
559</dt>
560<dd>
561<p>
562 The id of a tree object to diff against.
563</p>
564</dd>
565<dt>
566--cached
567</dt>
568<dd>
569<p>
570 do not consider the on-disk file at all
571</p>
572</dd>
573<dt>
574-m
575</dt>
576<dd>
577<p>
578 By default, files recorded in the index but not checked
579 out are reported as deleted. This flag makes
580 "git-diff-index" say that all non-checked-out files are up
581 to date.
582</p>
583</dd>
584</dl>
585</div>
586<h2>Output format</h2>
587<div class="sectionbody">
588<p>The output format from "git-diff-index", "git-diff-tree" and
589"git-diff-files" are very similar.</p>
590<p>These commands all compare two sets of things; what is
591compared differs:</p>
592<dl>
593<dt>
594git-diff-index &lt;tree-ish&gt;
595</dt>
596<dd>
597<p>
598 compares the &lt;tree-ish&gt; and the files on the filesystem.
599</p>
600</dd>
601<dt>
602git-diff-index --cached &lt;tree-ish&gt;
603</dt>
604<dd>
605<p>
606 compares the &lt;tree-ish&gt; and the index.
607</p>
608</dd>
609<dt>
610git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
611</dt>
612<dd>
613<p>
614 compares the trees named by the two arguments.
615</p>
616</dd>
617<dt>
618git-diff-files [&lt;pattern&gt;&#8230;]
619</dt>
620<dd>
621<p>
622 compares the index and the files on the filesystem.
623</p>
624</dd>
625</dl>
626<p>An output line is formatted this way:</p>
627<div class="listingblock">
628<div class="content">
629<pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
630copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
631rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
632create :000000 100644 0000000... 1234567... A file4
633delete :100644 000000 1234567... 0000000... D file5
634unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
635</div></div>
636<p>That is, from the left to the right:</p>
637<ol>
638<li>
639<p>
640a colon.
641</p>
642</li>
643<li>
644<p>
645mode for "src"; 000000 if creation or unmerged.
646</p>
647</li>
648<li>
649<p>
650a space.
651</p>
652</li>
653<li>
654<p>
655mode for "dst"; 000000 if deletion or unmerged.
656</p>
657</li>
658<li>
659<p>
660a space.
661</p>
662</li>
663<li>
664<p>
665sha1 for "src"; 0{40} if creation or unmerged.
666</p>
667</li>
668<li>
669<p>
670a space.
671</p>
672</li>
673<li>
674<p>
675sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
676</p>
677</li>
678<li>
679<p>
680a space.
681</p>
682</li>
683<li>
684<p>
685status, followed by optional "score" number.
686</p>
687</li>
688<li>
689<p>
690a tab or a NUL when <em>-z</em> option is used.
691</p>
692</li>
693<li>
694<p>
695path for "src"
696</p>
697</li>
698<li>
699<p>
700a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
701</p>
702</li>
703<li>
704<p>
705path for "dst"; only exists for C or R.
706</p>
707</li>
708<li>
709<p>
710an LF or a NUL when <em>-z</em> option is used, to terminate the record.
711</p>
712</li>
713</ol>
714<p>&lt;sha1&gt; is shown as all 0's if a file is new on the filesystem
715and it is out of sync with the index.</p>
716<p>Example:</p>
717<div class="listingblock">
718<div class="content">
719<pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
720</div></div>
721<p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
722in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
723respectively.</p>
724</div>
725<h2>Generating patches with -p</h2>
726<div class="sectionbody">
727<p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
728with a <em>-p</em> option, they do not produce the output described above;
729instead they produce a patch file.</p>
730<p>The patch generation can be customized at two levels.</p>
731<ol>
732<li>
733<p>
734When the environment variable <em>GIT_EXTERNAL_DIFF</em> is not set,
735 these commands internally invoke "diff" like this:
736</p>
737<div class="literalblock">
738<div class="content">
739<pre><tt>diff -L a/&lt;path&gt; -L b/&lt;path&gt; -pu &lt;old&gt; &lt;new&gt;</tt></pre>
740</div></div>
741<p>For added files, <tt>/dev/null</tt> is used for &lt;old&gt;. For removed
742files, <tt>/dev/null</tt> is used for &lt;new&gt;</p>
743<p>The "diff" formatting options can be customized via the
744environment variable <em>GIT_DIFF_OPTS</em>. For example, if you
745prefer context diff:</p>
746<div class="literalblock">
747<div class="content">
748<pre><tt>GIT_DIFF_OPTS=-c git-diff-index -p HEAD</tt></pre>
749</div></div>
750</li>
751<li>
752<p>
753When the environment variable <em>GIT_EXTERNAL_DIFF</em> is set, the
754 program named by it is called, instead of the diff invocation
755 described above.
756</p>
757<p>For a path that is added, removed, or modified,
758<em>GIT_EXTERNAL_DIFF</em> is called with 7 parameters:</p>
759<div class="literalblock">
760<div class="content">
761<pre><tt>path old-file old-hex old-mode new-file new-hex new-mode</tt></pre>
762</div></div>
763<p>where:</p>
764<div class="hlist"><table>
765<tr>
766<td class="hlist1">
767&lt;old|new&gt;-file
768</td>
769<td class="hlist2">
770are files GIT_EXTERNAL_DIFF can use to read the
771 contents of &lt;old|new&gt;,
772</td>
773</tr>
774<tr>
775<td class="hlist1">
776&lt;old|new&gt;-hex
777</td>
778<td class="hlist2">
779are the 40-hexdigit SHA1 hashes,
780</td>
781</tr>
782<tr>
783<td class="hlist1">
784&lt;old|new&gt;-mode
785</td>
786<td class="hlist2">
787are the octal representation of the file modes.
788</td>
789</tr>
790</table></div>
791<p>The file parameters can point at the user's working file
792(e.g. <tt>new-file</tt> in "git-diff-files"), <tt>/dev/null</tt> (e.g. <tt>old-file</tt>
793when a new file is added), or a temporary file (e.g. <tt>old-file</tt> in the
794index). <em>GIT_EXTERNAL_DIFF</em> should not worry about unlinking the
795temporary file --- it is removed when <em>GIT_EXTERNAL_DIFF</em> exits.</p>
796</li>
797</ol>
798<p>For a path that is unmerged, <em>GIT_EXTERNAL_DIFF</em> is called with 1
799parameter, &lt;path&gt;.</p>
800</div>
801<h2>git specific extension to diff format</h2>
802<div class="sectionbody">
803<p>What -p option produces is slightly different from the
804traditional diff format.</p>
805<ol>
806<li>
807<p>
Junio C Hamano235a91e2006-01-07 01:13:58808It is preceded with a "git diff" header, that looks like
Junio C Hamano1a4e8412005-12-27 08:17:23809 this:
810</p>
811<div class="literalblock">
812<div class="content">
813<pre><tt>diff --git a/file1 b/file2</tt></pre>
814</div></div>
815<p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
816involved. Especially, even for a creation or a deletion,
817<tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p>
818<p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
819name of the source file of the rename/copy and the name of
820the file that rename/copy produces, respectively.</p>
821</li>
822<li>
823<p>
824It is followed by one or more extended header lines:
825</p>
826<div class="literalblock">
827<div class="content">
828<pre><tt>old mode &lt;mode&gt;
829new mode &lt;mode&gt;
830deleted file mode &lt;mode&gt;
831new file mode &lt;mode&gt;
832copy from &lt;path&gt;
833copy to &lt;path&gt;
834rename from &lt;path&gt;
835rename to &lt;path&gt;
836similarity index &lt;number&gt;
837dissimilarity index &lt;number&gt;
838index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</tt></pre>
839</div></div>
840</li>
841<li>
842<p>
843TAB, LF, and backslash characters in pathnames are
844 represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>, respectively.
845</p>
846</li>
847</ol>
848</div>
Junio C Hamanofb56a962006-01-28 10:38:19849<h2>combined diff format</h2>
850<div class="sectionbody">
851<p>git-diff-tree and git-diff-files can take <em>-c</em> or <em>--cc</em> option
852to produce <em>combined diff</em>, which looks like this:</p>
853<div class="listingblock">
854<div class="content">
855<pre><tt>diff --combined describe.c
856@@@ +98,7 @@@
857 return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
858 }
859
860- static void describe(char *arg)
861 -static void describe(struct commit *cmit, int last_one)
862++static void describe(char *arg, int last_one)
863 {
864 + unsigned char sha1[20];
865 + struct commit *cmit;</tt></pre>
866</div></div>
867<p>Unlike the traditional <em>unified</em> diff format, which shows two
868files A and B with a single column that has <tt>-</tt> (minus &#8212;
869appears in A but removed in B), <tt>+</tt> (plus &#8212; missing in A but
870added to B), or <tt> </tt> (space &#8212; unchanged) prefix, this format
871compares two or more files file1, file2,&#8230; with one file X, and
872shows how X differs from each of fileN. One column for each of
873fileN is prepended to the output line to note how X's line is
874different from it.</p>
875<p>A <tt>-</tt> character in the column N means that the line appears in
876fileN but it does not appear in the last file. A <tt>+</tt> character
877in the column N means that the line appears in the last file,
878and fileN does not have that line.</p>
879<p>In the above example output, the function signature was changed
880from both files (hence two <tt>-</tt> removals from both file1 and
881file2, plus <tt>++</tt> to mean one line that was added does not appear
882in either file1 nor file2). Also two other lines are the same
883from file1 but do not appear in file2 (hence prefixed with <tt> +</tt>).</p>
884<p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
885merge commit with the merge result (i.e. file1..fileN are the
886parents). When shown by <tt>git diff-files -c</tt>, it compares the
887two unresolved merge parents with the working tree file
888(i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
889"their version").</p>
890</div>
Junio C Hamano1a4e8412005-12-27 08:17:23891<h2>Operating Modes</h2>
892<div class="sectionbody">
893<p>You can choose whether you want to trust the index file entirely
894(using the <em>--cached</em> flag) or ask the diff logic to show any files
895that don't match the stat state as being "tentatively changed". Both
896of these operations are very useful indeed.</p>
897</div>
898<h2>Cached Mode</h2>
899<div class="sectionbody">
900<p>If <em>--cached</em> is specified, it allows you to ask:</p>
901<div class="literalblock">
902<div class="content">
903<pre><tt>show me the differences between HEAD and the current index
904contents (the ones I'd write with a "git-write-tree")</tt></pre>
905</div></div>
906<p>For example, let's say that you have worked on your working directory, updated
Junio C Hamano235a91e2006-01-07 01:13:58907some files in the index and are ready to commit. You want to see exactly
Junio C Hamano1a4e8412005-12-27 08:17:23908<strong>what</strong> you are going to commit is without having to write a new tree
909object and compare it that way, and to do that, you just do</p>
910<div class="literalblock">
911<div class="content">
912<pre><tt>git-diff-index --cached HEAD</tt></pre>
913</div></div>
914<p>Example: let's say I had renamed <tt>commit.c</tt> to <tt>git-commit.c</tt>, and I had
915done an "git-update-index" to make that effective in the index file.
916"git-diff-files" wouldn't show anything at all, since the index file
917matches my working directory. But doing a "git-diff-index" does:</p>
918<div class="literalblock">
919<div class="content">
920<pre><tt>torvalds@ppc970:~/git&gt; git-diff-index --cached HEAD
921-100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
922+100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c</tt></pre>
923</div></div>
924<p>You can trivially see that the above is a rename.</p>
925<p>In fact, "git-diff-index --cached" <strong>should</strong> always be entirely equivalent to
926actually doing a "git-write-tree" and comparing that. Except this one is much
927nicer for the case where you just want to check where you are.</p>
928<p>So doing a "git-diff-index --cached" is basically very useful when you are
929asking yourself "what have I already marked for being committed, and
930what's the difference to a previous tree".</p>
931</div>
932<h2>Non-cached Mode</h2>
933<div class="sectionbody">
934<p>The "non-cached" mode takes a different approach, and is potentially
935the more useful of the two in that what it does can't be emulated with
936a "git-write-tree" + "git-diff-tree". Thus that's the default mode.
937The non-cached version asks the question:</p>
938<div class="literalblock">
939<div class="content">
940<pre><tt>show me the differences between HEAD and the currently checked out
941tree - index contents _and_ files that aren't up-to-date</tt></pre>
942</div></div>
943<p>which is obviously a very useful question too, since that tells you what
944you <strong>could</strong> commit. Again, the output matches the "git-diff-tree -r"
945output to a tee, but with a twist.</p>
946<p>The twist is that if some file doesn't match the index, we don't have
947a backing store thing for it, and we use the magic "all-zero" sha1 to
948show that. So let's say that you have edited <tt>kernel/sched.c</tt>, but
949have not actually done a "git-update-index" on it yet - there is no
950"object" associated with the new state, and you get:</p>
951<div class="literalblock">
952<div class="content">
953<pre><tt>torvalds@ppc970:~/v2.6/linux&gt; git-diff-index HEAD
954*100644-&gt;100664 blob 7476bb......-&gt;000000...... kernel/sched.c</tt></pre>
955</div></div>
Junio C Hamano341071d2006-06-04 07:24:48956<p>i.e., it shows that the tree has changed, and that <tt>kernel/sched.c</tt> has is
Junio C Hamano1a4e8412005-12-27 08:17:23957not up-to-date and may contain new stuff. The all-zero sha1 means that to
958get the real diff, you need to look at the object in the working directory
959directly rather than do an object-to-object diff.</p>
960<div class="admonitionblock">
961<table><tr>
962<td class="icon">
963<div class="title">Note</div>
964</td>
965<td class="content">As with other commands of this type, "git-diff-index" does not
966actually look at the contents of the file at all. So maybe
967<tt>kernel/sched.c</tt> hasn't actually changed, and it's just that you
968touched it. In either case, it's a note that you need to
Junio C Hamano235a91e2006-01-07 01:13:58969"git-update-index" it to make the index be in sync.</td>
Junio C Hamano1a4e8412005-12-27 08:17:23970</tr></table>
971</div>
972<div class="admonitionblock">
973<table><tr>
974<td class="icon">
975<div class="title">Note</div>
976</td>
977<td class="content">You can have a mixture of files show up as "has been updated"
978and "is still dirty in the working directory" together. You can always
979tell which file is in which state, since the "has been updated" ones
980show a valid sha1, and the "not in sync with the index" ones will
981always have the special all-zero sha1.</td>
982</tr></table>
983</div>
984</div>
985<h2>Author</h2>
986<div class="sectionbody">
987<p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>
988</div>
989<h2>Documentation</h2>
990<div class="sectionbody">
991<p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
992</div>
993<h2>GIT</h2>
994<div class="sectionbody">
995<p>Part of the <a href="git.html">git(7)</a> suite</p>
996</div>
997<div id="footer">
998<div id="footer-text">
Junio C Hamano7ccb9fd2006-07-15 01:38:40999Last updated 15-Jul-2006 01:37:42 UTC
Junio C Hamano1a4e8412005-12-27 08:17:231000</div>
1001</div>
1002</body>
1003</html>