blob: 83f7c15ae541d7328f788f8a4ecd2fa925d9c7aa [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 Hamanoba4b9282008-07-06 05:20:316<meta name="generator" content="AsciiDoc 8.2.5" />
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
Junio C Hamanoba4b9282008-07-06 05:20:3119a {
20 color: blue;
21 text-decoration: underline;
22}
23a:visited {
24 color: fuchsia;
25}
Junio C Hamano1a4e8412005-12-27 08:17:2326
27em {
28 font-style: italic;
29}
30
31strong {
32 font-weight: bold;
33}
34
35tt {
36 color: navy;
37}
38
39h1, 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;
45}
46
Junio C Hamanoba4b9282008-07-06 05:20:3147h1, h2, h3 {
Junio C Hamano1a4e8412005-12-27 08:17:2348 border-bottom: 2px solid silver;
49}
50h2 {
Junio C Hamano1a4e8412005-12-27 08:17:2351 padding-top: 0.5em;
52}
Junio C Hamanoba4b9282008-07-06 05:20:3153h3 {
54 float: left;
55}
56h3 + * {
57 clear: left;
58}
Junio C Hamano1a4e8412005-12-27 08:17:2359
60div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
63}
64
65hr {
66 border: 1px solid silver;
67}
68
69p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
72}
73
74pre {
75 padding: 0;
76 margin: 0;
77}
78
79span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
Junio C Hamanoba4b9282008-07-06 05:20:3183 font-size: 1.1em;
Junio C Hamano1a4e8412005-12-27 08:17:2384}
85span#email {
86}
87span#revision {
88 font-family: sans-serif;
89}
90
91div#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;
97}
98div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
101}
102div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
105}
106
107div#preamble,
108div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
114}
115div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
118}
119
120div.content { /* Block element content. */
121 padding: 0;
122}
123
124/* Block element titles. */
125div.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;
131}
132div.title + * {
133 margin-top: 0;
134}
135
136td div.title:first-child {
137 margin-top: 0.0em;
138}
139div.content div.title:first-child {
140 margin-top: 0.0em;
141}
142div.content + div.title {
143 margin-top: 0.0em;
144}
145
146div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
150}
151
Junio C Hamanoba4b9282008-07-06 05:20:31152div.listingblock {
153 margin-right: 0%;
154}
Junio C Hamano1a4e8412005-12-27 08:17:23155div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
159}
160
161div.quoteblock > div.content {
162 padding-left: 2.0em;
163}
Junio C Hamanoba4b9282008-07-06 05:20:31164
165div.attribution {
Junio C Hamano1a4e8412005-12-27 08:17:23166 text-align: right;
167}
Junio C Hamanoba4b9282008-07-06 05:20:31168div.verseblock + div.attribution {
169 text-align: left;
170}
Junio C Hamano1a4e8412005-12-27 08:17:23171
172div.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;
179}
180div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
183}
184
185div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
188}
189
190div.verseblock div.content {
191 white-space: pre;
192}
193
194div.imageblock div.content { padding-left: 0; }
195div.imageblock img { border: 1px solid silver; }
196span.image img { border-style: none; }
197
198dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
201}
202dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
206}
207dd > *:first-child {
208 margin-top: 0;
209}
210
211ul, ol {
212 list-style-position: outside;
213}
Junio C Hamanoba4b9282008-07-06 05:20:31214div.olist2 ol {
Junio C Hamano1a4e8412005-12-27 08:17:23215 list-style-type: lower-alpha;
216}
217
218div.tableblock > table {
Junio C Hamanoba4b9282008-07-06 05:20:31219 border: 3px solid #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23220}
221thead {
222 font-family: sans-serif;
223 font-weight: bold;
224}
225tfoot {
226 font-weight: bold;
227}
228
229div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
232}
Junio C Hamanoba4b9282008-07-06 05:20:31233div.hlist td {
234 padding-bottom: 5px;
235}
Junio C Hamano1a4e8412005-12-27 08:17:23236td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
240}
241td.hlist2 {
242 vertical-align: top;
243}
244
245@media print {
246 div#footer-badges { display: none; }
247}
Junio C Hamanoba4b9282008-07-06 05:20:31248
249div#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;
256}
257
258div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
261}
262div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
265}
266div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
269}
270div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
273}
274include1::./stylesheets/xhtml11-manpage.css[]
Junio C Hamano1a4e8412005-12-27 08:17:23275/* Workarounds for IE6's broken and incomplete CSS2. */
276
277div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
281}
282div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
287}
288
289div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
293}
294
295div.quoteblock-content {
296 padding-left: 2.0em;
297}
298
299div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
302}
Junio C Hamanoba4b9282008-07-06 05:20:31303
304/* IE6 sets dynamically generated links as visited. */
305div#toc a:visited { color: blue; }
Junio C Hamano1a4e8412005-12-27 08:17:23306</style>
307<title>git-diff-index(1)</title>
308</head>
309<body>
310<div id="header">
311<h1>
312git-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">
Junio C Hamanoba4b9282008-07-06 05:20:31323<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>
Junio C Hamano1a4e8412005-12-27 08:17:23324</div>
Junio C Hamanoba4b9282008-07-06 05:20:31325<h2 id="_description">DESCRIPTION</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23326<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31327<div class="para"><p>Compares the content and mode of the blobs found via a tree
Junio C Hamano1a4e8412005-12-27 08:17:23328object with the content of the current index and, optionally
329ignoring the stat state of the file on disk. When paths are
330specified, compares only those named paths. Otherwise all
Junio C Hamanoba4b9282008-07-06 05:20:31331entries in the index are compared.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23332</div>
Junio C Hamanoba4b9282008-07-06 05:20:31333<h2 id="_options">OPTIONS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23334<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31335<div class="vlist"><dl>
Junio C Hamano1a4e8412005-12-27 08:17:23336<dt>
337-p
338</dt>
339<dd>
340<p>
Junio C Hamanoff979792007-11-16 10:11:30341 Generate patch (see section on generating patches).
342
Junio C Hamano1a4e8412005-12-27 08:17:23343</p>
344</dd>
345<dt>
346-u
347</dt>
348<dd>
349<p>
350 Synonym for "-p".
351</p>
352</dd>
353<dt>
Junio C Hamano69361562007-07-26 02:14:34354-U&lt;n&gt;
355</dt>
356<dd>
357<p>
358 Shorthand for "--unified=&lt;n&gt;".
359</p>
360</dd>
361<dt>
362--unified=&lt;n&gt;
363</dt>
364<dd>
365<p>
366 Generate diffs with &lt;n&gt; lines of context instead of
367 the usual three. Implies "-p".
368</p>
369</dd>
370<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34371--raw
372</dt>
373<dd>
374<p>
375 Generate the raw format.
Junio C Hamanoff979792007-11-16 10:11:30376 This is the default.
Junio C Hamano9ae1a062006-07-10 08:12:34377</p>
378</dd>
379<dt>
Junio C Hamano54559c82006-04-13 07:45:12380--patch-with-raw
381</dt>
382<dd>
383<p>
Junio C Hamano9ae1a062006-07-10 08:12:34384 Synonym for "-p --raw".
Junio C Hamano54559c82006-04-13 07:45:12385</p>
386</dd>
387<dt>
Junio C Hamano4a9a76a2006-10-01 05:40:29388--stat[=width[,name-width]]
Junio C Hamanoba7c8d82006-04-15 06:17:42389</dt>
390<dd>
391<p>
Junio C Hamano4a9a76a2006-10-01 05:40:29392 Generate a diffstat. You can override the default
393 output width for 80-column terminal by "--stat=width".
394 The width of the filename part can be controlled by
395 giving another width to it separated by a comma.
Junio C Hamanoba7c8d82006-04-15 06:17:42396</p>
397</dd>
398<dt>
Junio C Hamanofbe00522006-10-19 05:58:48399--numstat
400</dt>
401<dd>
402<p>
403 Similar to --stat, but shows number of added and
404 deleted lines in decimal notation and pathname without
Junio C Hamanod793de52006-12-26 09:11:43405 abbreviation, to make it more machine friendly. For
406 binary files, outputs two <tt>-</tt> instead of saying
407 <tt>0 0</tt>.
Junio C Hamanofbe00522006-10-19 05:58:48408</p>
409</dd>
410<dt>
Junio C Hamano7d23f5e2006-12-16 07:44:04411--shortstat
412</dt>
413<dd>
414<p>
415 Output only the last line of the --stat format containing total
416 number of modified files, as well as number of added and deleted
417 lines.
418</p>
419</dd>
420<dt>
Junio C Hamano6a45be92008-04-22 08:19:03421--dirstat[=limit]
422</dt>
423<dd>
424<p>
425 Output only the sub-directories that are impacted by a diff,
426 and to what degree they are impacted. You can override the
427 default cut-off in percent (3) by "--dirstat=limit". If you
428 want to enable "cumulative" directory statistics, you can use
429 the "--cumulative" flag, which adds up percentages recursively
430 even when they have been already reported for a sub-directory.
431</p>
432</dd>
433<dt>
Junio C Hamano6959c6c2006-05-17 10:34:11434--summary
435</dt>
436<dd>
437<p>
438 Output a condensed summary of extended header information
439 such as creations, renames and mode changes.
440</p>
441</dd>
442<dt>
Junio C Hamanod1308c92006-04-16 11:01:09443--patch-with-stat
444</dt>
445<dd>
446<p>
Junio C Hamano9ae1a062006-07-10 08:12:34447 Synonym for "-p --stat".
Junio C Hamanoff979792007-11-16 10:11:30448
Junio C Hamanod1308c92006-04-16 11:01:09449</p>
450</dd>
451<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23452-z
453</dt>
454<dd>
455<p>
Junio C Hamanob968dbb2007-07-27 07:26:40456 NUL-line termination on output. This affects the --raw
457 output field terminator. Also output from commands such
458 as "git-log" will be delimited with NUL between commits.
Junio C Hamano1a4e8412005-12-27 08:17:23459</p>
460</dd>
461<dt>
462--name-only
463</dt>
464<dd>
465<p>
466 Show only names of changed files.
467</p>
468</dd>
469<dt>
470--name-status
471</dt>
472<dd>
473<p>
Junio C Hamanoa9aee782008-04-23 16:09:20474 Show only names and status of changed files. See the description
475 of the <tt>--diff-filter</tt> option on what the status letters mean.
Junio C Hamano1a4e8412005-12-27 08:17:23476</p>
477</dd>
478<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34479--color
480</dt>
481<dd>
482<p>
483 Show colored diff.
484</p>
485</dd>
486<dt>
487--no-color
488</dt>
489<dd>
490<p>
491 Turn off colored diff, even when the configuration file
492 gives the default to color output.
493</p>
494</dd>
495<dt>
Junio C Hamano85e45fa2006-08-13 07:47:41496--color-words
497</dt>
498<dd>
499<p>
500 Show colored word diff, i.e. color words which have changed.
501</p>
502</dd>
503<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34504--no-renames
505</dt>
506<dd>
507<p>
508 Turn off rename detection, even when the configuration
509 file gives the default to do so.
510</p>
511</dd>
512<dt>
Junio C Hamanoa890c4f2007-01-28 10:29:21513--check
514</dt>
515<dd>
516<p>
517 Warn if changes introduce trailing whitespace
Junio C Hamano3dac5042007-12-15 08:40:54518 or an indent that uses a space before a tab. Exits with
519 non-zero status if problems are found. Not compatible with
520 --exit-code.
Junio C Hamanoa890c4f2007-01-28 10:29:21521</p>
522</dd>
523<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23524--full-index
525</dt>
526<dd>
527<p>
528 Instead of the first handful characters, show full
529 object name of pre- and post-image blob on the "index"
530 line when generating a patch format output.
531</p>
532</dd>
533<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34534--binary
535</dt>
536<dd>
537<p>
538 In addition to --full-index, output "binary diff" that
539 can be applied with "git apply".
540</p>
541</dd>
542<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23543--abbrev[=&lt;n&gt;]
544</dt>
545<dd>
546<p>
547 Instead of showing the full 40-byte hexadecimal object
548 name in diff-raw format output and diff-tree header
Junio C Hamano235a91e2006-01-07 01:13:58549 lines, show only handful hexdigits prefix. This is
Junio C Hamano1a4e8412005-12-27 08:17:23550 independent of --full-index option above, which controls
551 the diff-patch output format. Non default number of
552 digits can be specified with --abbrev=&lt;n&gt;.
553</p>
554</dd>
555<dt>
556-B
557</dt>
558<dd>
559<p>
560 Break complete rewrite changes into pairs of delete and create.
561</p>
562</dd>
563<dt>
564-M
565</dt>
566<dd>
567<p>
568 Detect renames.
569</p>
570</dd>
571<dt>
572-C
573</dt>
574<dd>
575<p>
Junio C Hamano16f98872007-06-12 16:09:14576 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
Junio C Hamano1a4e8412005-12-27 08:17:23577</p>
578</dd>
579<dt>
Junio C Hamano6ec31b92006-02-10 05:52:01580--diff-filter=[ACDMRTUXB*]
581</dt>
582<dd>
583<p>
584 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
585 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
586 type (mode) changed (<tt>T</tt>), are Unmerged (<tt>U</tt>), are
587 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
588 Any combination of the filter characters may be used.
589 When <tt>*</tt> (All-or-none) is added to the combination, all
590 paths are selected if there is any file that matches
591 other criteria in the comparison; if there is no file
592 that matches other criteria, nothing is selected.
593</p>
594</dd>
595<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23596--find-copies-harder
597</dt>
598<dd>
599<p>
Junio C Hamano16f98872007-06-12 16:09:14600 For performance reasons, by default, <tt>-C</tt> option finds copies only
Junio C Hamano1a4e8412005-12-27 08:17:23601 if the original file of the copy was modified in the same
602 changeset. This flag makes the command
603 inspect unmodified files as candidates for the source of
604 copy. This is a very expensive operation for large
Junio C Hamano16f98872007-06-12 16:09:14605 projects, so use it with caution. Giving more than one
606 <tt>-C</tt> option has the same effect.
Junio C Hamano1a4e8412005-12-27 08:17:23607</p>
608</dd>
609<dt>
610-l&lt;num&gt;
611</dt>
612<dd>
613<p>
614 -M and -C options require O(n^2) processing time where n
615 is the number of potential rename/copy targets. This
616 option prevents rename/copy detection from running if
617 the number of rename/copy targets exceeds the specified
618 number.
619</p>
620</dd>
621<dt>
622-S&lt;string&gt;
623</dt>
624<dd>
625<p>
626 Look for differences that contain the change in &lt;string&gt;.
627</p>
628</dd>
629<dt>
630--pickaxe-all
631</dt>
632<dd>
633<p>
634 When -S finds a change, show all the changes in that
635 changeset, not just the files that contain the change
636 in &lt;string&gt;.
637</p>
638</dd>
639<dt>
Junio C Hamanobfe9e752006-04-05 21:43:28640--pickaxe-regex
641</dt>
642<dd>
643<p>
644 Make the &lt;string&gt; not a plain string but an extended POSIX
645 regex to match.
646</p>
647</dd>
648<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23649-O&lt;orderfile&gt;
650</dt>
651<dd>
652<p>
653 Output the patch in the order specified in the
654 &lt;orderfile&gt;, which has one shell glob pattern per line.
655</p>
656</dd>
657<dt>
658-R
659</dt>
660<dd>
661<p>
662 Swap two inputs; that is, show differences from index or
663 on-disk file to tree contents.
664</p>
665</dd>
Junio C Hamanoc26f5482006-07-09 09:38:14666<dt>
Junio C Hamano24bc09a2008-02-28 00:27:44667--relative[=&lt;path&gt;]
668</dt>
669<dd>
670<p>
671 When run from a subdirectory of the project, it can be
672 told to exclude changes outside the directory and show
673 pathnames relative to it with this option. When you are
674 not in a subdirectory (e.g. in a bare repository), you
675 can name which subdirectory to make the output relative
676 to by giving a &lt;path&gt; as an argument.
677</p>
678</dd>
679<dt>
Junio C Hamanoc26f5482006-07-09 09:38:14680--text
681</dt>
682<dd>
683<p>
684 Treat all files as text.
685</p>
686</dd>
687<dt>
688-a
689</dt>
690<dd>
691<p>
692 Shorthand for "--text".
693</p>
694</dd>
Junio C Hamanod9c2d2f2006-12-06 08:59:07695<dt>
Junio C Hamanofd468962007-02-14 23:45:04696--ignore-space-at-eol
697</dt>
698<dd>
699<p>
Junio C Hamano3a702342007-12-12 21:34:02700 Ignore changes in whitespace at EOL.
Junio C Hamanofd468962007-02-14 23:45:04701</p>
702</dd>
703<dt>
Junio C Hamanod9c2d2f2006-12-06 08:59:07704--ignore-space-change
705</dt>
706<dd>
707<p>
Junio C Hamano3a702342007-12-12 21:34:02708 Ignore changes in amount of whitespace. This ignores whitespace
709 at line end, and considers all other sequences of one or
710 more whitespace characters to be equivalent.
Junio C Hamanod9c2d2f2006-12-06 08:59:07711</p>
712</dd>
713<dt>
714-b
715</dt>
716<dd>
717<p>
718 Shorthand for "--ignore-space-change".
719</p>
720</dd>
721<dt>
722--ignore-all-space
723</dt>
724<dd>
725<p>
Junio C Hamano3a702342007-12-12 21:34:02726 Ignore whitespace when comparing lines. This ignores
727 differences even if one line has whitespace where the other
Junio C Hamanod9c2d2f2006-12-06 08:59:07728 line has none.
729</p>
730</dd>
731<dt>
732-w
733</dt>
734<dd>
735<p>
736 Shorthand for "--ignore-all-space".
737</p>
738</dd>
Junio C Hamano48fd2f62007-03-19 02:02:30739<dt>
740--exit-code
741</dt>
742<dd>
743<p>
744 Make the program exit with codes similar to diff(1).
745 That is, it exits with 1 if there were differences and
746 0 means no differences.
747</p>
748</dd>
Junio C Hamano35e57552007-03-25 07:54:35749<dt>
750--quiet
751</dt>
752<dd>
753<p>
754 Disable all output of the program. Implies --exit-code.
755</p>
756</dd>
Junio C Hamanobb0f4042007-07-04 06:41:40757<dt>
758--ext-diff
759</dt>
760<dd>
761<p>
762 Allow an external diff helper to be executed. If you set an
Junio C Hamano1b50ce92007-10-03 12:05:53763 external diff driver with <a href="gitattributes.html">gitattributes(5)</a>, you need
764 to use this option with <a href="git-log.html">git-log(1)</a> and friends.
Junio C Hamanobb0f4042007-07-04 06:41:40765</p>
766</dd>
767<dt>
768--no-ext-diff
769</dt>
770<dd>
771<p>
772 Disallow external diff drivers.
773</p>
774</dd>
Junio C Hamanoe27cbd22007-12-21 17:57:33775<dt>
Junio C Hamanodfccbb02008-05-26 01:16:14776--ignore-submodules
777</dt>
778<dd>
779<p>
780 Ignore changes to submodules in the diff generation.
781</p>
782</dd>
783<dt>
Junio C Hamanoe27cbd22007-12-21 17:57:33784--src-prefix=&lt;prefix&gt;
785</dt>
786<dd>
787<p>
788 Show the given source prefix instead of "a/".
789</p>
790</dd>
791<dt>
792--dst-prefix=&lt;prefix&gt;
793</dt>
794<dd>
795<p>
796 Show the given destination prefix instead of "b/".
797</p>
798</dd>
799<dt>
800--no-prefix
801</dt>
802<dd>
803<p>
804 Do not show any source or destination prefix.
805</p>
806</dd>
Junio C Hamanoba4b9282008-07-06 05:20:31807</dl></div>
808<div class="para"><p>For more detailed explanation on these common options, see also
809<a href="gitdiffcore.html">gitdiffcore(7)</a>.</p></div>
810<div class="vlist"><dl>
Junio C Hamano1a4e8412005-12-27 08:17:23811<dt>
812&lt;tree-ish&gt;
813</dt>
814<dd>
815<p>
816 The id of a tree object to diff against.
817</p>
818</dd>
819<dt>
820--cached
821</dt>
822<dd>
823<p>
824 do not consider the on-disk file at all
825</p>
826</dd>
827<dt>
828-m
829</dt>
830<dd>
831<p>
832 By default, files recorded in the index but not checked
833 out are reported as deleted. This flag makes
Junio C Hamanoba4b9282008-07-06 05:20:31834 <em>git-diff-index</em> say that all non-checked-out files are up
Junio C Hamano1a4e8412005-12-27 08:17:23835 to date.
836</p>
837</dd>
Junio C Hamanoba4b9282008-07-06 05:20:31838</dl></div>
Junio C Hamano1a4e8412005-12-27 08:17:23839</div>
Junio C Hamanoba4b9282008-07-06 05:20:31840<h2 id="_output_format">Output format</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23841<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31842<div class="para"><p>The output format from "git-diff-index", "git-diff-tree",
843"git-diff-files" and "git diff --raw" are very similar.</p></div>
844<div class="para"><p>These commands all compare two sets of things; what is
845compared differs:</p></div>
846<div class="vlist"><dl>
Junio C Hamano1a4e8412005-12-27 08:17:23847<dt>
848git-diff-index &lt;tree-ish&gt;
849</dt>
850<dd>
851<p>
852 compares the &lt;tree-ish&gt; and the files on the filesystem.
853</p>
854</dd>
855<dt>
856git-diff-index --cached &lt;tree-ish&gt;
857</dt>
858<dd>
859<p>
860 compares the &lt;tree-ish&gt; and the index.
861</p>
862</dd>
863<dt>
864git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
865</dt>
866<dd>
867<p>
868 compares the trees named by the two arguments.
869</p>
870</dd>
871<dt>
872git-diff-files [&lt;pattern&gt;&#8230;]
873</dt>
874<dd>
875<p>
876 compares the index and the files on the filesystem.
877</p>
878</dd>
Junio C Hamanoba4b9282008-07-06 05:20:31879</dl></div>
880<div class="para"><p>An output line is formatted this way:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23881<div class="listingblock">
882<div class="content">
883<pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
884copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
885rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
886create :000000 100644 0000000... 1234567... A file4
887delete :100644 000000 1234567... 0000000... D file5
888unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
889</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31890<div class="para"><p>That is, from the left to the right:</p></div>
891<div class="olist"><ol>
Junio C Hamano1a4e8412005-12-27 08:17:23892<li>
893<p>
894a colon.
895</p>
896</li>
897<li>
898<p>
899mode for "src"; 000000 if creation or unmerged.
900</p>
901</li>
902<li>
903<p>
904a space.
905</p>
906</li>
907<li>
908<p>
909mode for "dst"; 000000 if deletion or unmerged.
910</p>
911</li>
912<li>
913<p>
914a space.
915</p>
916</li>
917<li>
918<p>
919sha1 for "src"; 0{40} if creation or unmerged.
920</p>
921</li>
922<li>
923<p>
924a space.
925</p>
926</li>
927<li>
928<p>
929sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
930</p>
931</li>
932<li>
933<p>
934a space.
935</p>
936</li>
937<li>
938<p>
939status, followed by optional "score" number.
940</p>
941</li>
942<li>
943<p>
944a tab or a NUL when <em>-z</em> option is used.
945</p>
946</li>
947<li>
948<p>
949path for "src"
950</p>
951</li>
952<li>
953<p>
954a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
955</p>
956</li>
957<li>
958<p>
959path for "dst"; only exists for C or R.
960</p>
961</li>
962<li>
963<p>
964an LF or a NUL when <em>-z</em> option is used, to terminate the record.
965</p>
966</li>
Junio C Hamanoba4b9282008-07-06 05:20:31967</ol></div>
968<div class="para"><p>&lt;sha1&gt; is shown as all 0's if a file is new on the filesystem
969and it is out of sync with the index.</p></div>
970<div class="para"><p>Example:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23971<div class="listingblock">
972<div class="content">
973<pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
974</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31975<div class="para"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
Junio C Hamano1a4e8412005-12-27 08:17:23976in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
Junio C Hamanoba4b9282008-07-06 05:20:31977respectively.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23978</div>
Junio C Hamanoba4b9282008-07-06 05:20:31979<h2 id="_diff_format_for_merges">diff format for merges</h2>
Junio C Hamano67fad6d2007-05-06 08:53:12980<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31981<div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff --raw"
Junio C Hamano7ae0ab22007-11-03 02:46:46982can take <em>-c</em> or <em>--cc</em> option
Junio C Hamano67fad6d2007-05-06 08:53:12983to generate diff output also for merge commits. The output differs
Junio C Hamanoba4b9282008-07-06 05:20:31984from the format described above in the following way:</p></div>
985<div class="olist"><ol>
Junio C Hamano67fad6d2007-05-06 08:53:12986<li>
987<p>
988there is a colon for each parent
989</p>
990</li>
991<li>
992<p>
993there are more "src" modes and "src" sha1
994</p>
995</li>
996<li>
997<p>
998status is concatenated status characters for each parent
999</p>
1000</li>
1001<li>
1002<p>
1003no optional "score" number
1004</p>
1005</li>
1006<li>
1007<p>
1008single path, only for "dst"
1009</p>
1010</li>
Junio C Hamanoba4b9282008-07-06 05:20:311011</ol></div>
1012<div class="para"><p>Example:</p></div>
Junio C Hamano67fad6d2007-05-06 08:53:121013<div class="listingblock">
1014<div class="content">
1015<pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1016</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311017<div class="para"><p>Note that <em>combined diff</em> lists only files which were modified from
1018all parents.</p></div>
Junio C Hamano67fad6d2007-05-06 08:53:121019</div>
Junio C Hamanoba4b9282008-07-06 05:20:311020<h2 id="_generating_patches_with_p">Generating patches with -p</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231021<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311022<div class="para"><p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
Junio C Hamano00b8b632007-12-07 09:50:491023with a <em>-p</em> option, "git diff" without the <em>--raw</em> option, or
1024"git log" with the "-p" option, they
Junio C Hamano7ae0ab22007-11-03 02:46:461025do not produce the output described above; instead they produce a
1026patch file. You can customize the creation of such patches via the
Junio C Hamanoba4b9282008-07-06 05:20:311027GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1028<div class="para"><p>What the -p option produces is slightly different from the traditional
1029diff format.</p></div>
1030<div class="olist"><ol>
Junio C Hamano1a4e8412005-12-27 08:17:231031<li>
1032<p>
Junio C Hamano235a91e2006-01-07 01:13:581033It is preceded with a "git diff" header, that looks like
Junio C Hamano1a4e8412005-12-27 08:17:231034 this:
1035</p>
1036<div class="literalblock">
1037<div class="content">
1038<pre><tt>diff --git a/file1 b/file2</tt></pre>
1039</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311040<div class="para"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
Junio C Hamano1a4e8412005-12-27 08:17:231041involved. Especially, even for a creation or a deletion,
Junio C Hamanoba4b9282008-07-06 05:20:311042<tt>/dev/null</tt> is <em>not</em> used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1043<div class="para"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
Junio C Hamano1a4e8412005-12-27 08:17:231044name of the source file of the rename/copy and the name of
Junio C Hamanoba4b9282008-07-06 05:20:311045the file that rename/copy produces, respectively.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231046</li>
1047<li>
1048<p>
1049It is followed by one or more extended header lines:
1050</p>
1051<div class="literalblock">
1052<div class="content">
1053<pre><tt>old mode &lt;mode&gt;
1054new mode &lt;mode&gt;
1055deleted file mode &lt;mode&gt;
1056new file mode &lt;mode&gt;
1057copy from &lt;path&gt;
1058copy to &lt;path&gt;
1059rename from &lt;path&gt;
1060rename to &lt;path&gt;
1061similarity index &lt;number&gt;
1062dissimilarity index &lt;number&gt;
1063index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</tt></pre>
1064</div></div>
1065</li>
1066<li>
1067<p>
Junio C Hamanoa053d542006-10-27 09:29:131068TAB, LF, double quote and backslash characters in pathnames
1069 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and <tt>\\</tt>, respectively.
1070 If there is need for such substitution then the whole
1071 pathname is put in double quotes.
Junio C Hamano1a4e8412005-12-27 08:17:231072</p>
1073</li>
Junio C Hamanoba4b9282008-07-06 05:20:311074</ol></div>
1075<div class="para"><p>The similarity index is the percentage of unchanged lines, and
Junio C Hamanod526ba92007-07-02 00:17:421076the dissimilarity index is the percentage of changed lines. It
1077is a rounded down integer, followed by a percent sign. The
1078similarity index value of 100% is thus reserved for two equal
1079files, while 100% dissimilarity means that no line from the old
Junio C Hamanoba4b9282008-07-06 05:20:311080file made it into the new one.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231081</div>
Junio C Hamanoba4b9282008-07-06 05:20:311082<h2 id="_combined_diff_format">combined diff format</h2>
Junio C Hamanofb56a962006-01-28 10:38:191083<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311084<div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff" can take <em>-c</em> or
Junio C Hamano00b8b632007-12-07 09:50:491085<em>--cc</em> option to produce <em>combined diff</em>. For showing a merge commit
1086with "git log -p", this is the default format.
Junio C Hamanoba4b9282008-07-06 05:20:311087A <em>combined diff</em> format looks like this:</p></div>
Junio C Hamanofb56a962006-01-28 10:38:191088<div class="listingblock">
1089<div class="content">
1090<pre><tt>diff --combined describe.c
Junio C Hamano29f14312006-10-26 08:47:291091index fabadb8,cc95eb0..4866510
1092--- a/describe.c
1093+++ b/describe.c
1094@@@ -98,20 -98,12 +98,20 @@@
1095 return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
Junio C Hamanofb56a962006-01-28 10:38:191096 }
1097
1098- static void describe(char *arg)
1099 -static void describe(struct commit *cmit, int last_one)
1100++static void describe(char *arg, int last_one)
1101 {
Junio C Hamano29f14312006-10-26 08:47:291102 + unsigned char sha1[20];
1103 + struct commit *cmit;
1104 struct commit_list *list;
1105 static int initialized = 0;
1106 struct commit_name *n;
1107
1108 + if (get_sha1(arg, sha1) &lt; 0)
1109 + usage(describe_usage);
1110 + cmit = lookup_commit_reference(sha1);
1111 + if (!cmit)
1112 + usage(describe_usage);
1113 +
1114 if (!initialized) {
1115 initialized = 1;
1116 for_each_ref(get_name);</tt></pre>
Junio C Hamanofb56a962006-01-28 10:38:191117</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311118<div class="olist"><ol>
Junio C Hamano29f14312006-10-26 08:47:291119<li>
1120<p>
1121It is preceded with a "git diff" header, that looks like
1122 this (when <em>-c</em> option is used):
1123</p>
1124<div class="literalblock">
1125<div class="content">
1126<pre><tt>diff --combined file</tt></pre>
1127</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311128<div class="para"><p>or like this (when <em>--cc</em> option is used):</p></div>
Junio C Hamano29f14312006-10-26 08:47:291129<div class="literalblock">
1130<div class="content">
1131<pre><tt>diff --c file</tt></pre>
1132</div></div>
1133</li>
1134<li>
1135<p>
1136It is followed by one or more extended header lines
1137 (this example shows a merge with two parents):
1138</p>
1139<div class="literalblock">
1140<div class="content">
1141<pre><tt>index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;
1142mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;
1143new file mode &lt;mode&gt;
1144deleted file mode &lt;mode&gt;,&lt;mode&gt;</tt></pre>
1145</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311146<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
Junio C Hamanoee1e4282007-02-04 08:32:041147the &lt;mode&gt; is different from the rest. Extended headers with
Junio C Hamano29f14312006-10-26 08:47:291148information about detected contents movement (renames and
1149copying detection) are designed to work with diff of two
Junio C Hamanoba4b9282008-07-06 05:20:311150&lt;tree-ish&gt; and are not used by combined diff format.</p></div>
Junio C Hamano29f14312006-10-26 08:47:291151</li>
1152<li>
1153<p>
1154It is followed by two-line from-file/to-file header
1155</p>
1156<div class="literalblock">
1157<div class="content">
1158<pre><tt>--- a/file
1159+++ b/file</tt></pre>
1160</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311161<div class="para"><p>Similar to two-line header for traditional <em>unified</em> diff
Junio C Hamano29f14312006-10-26 08:47:291162format, <tt>/dev/null</tt> is used to signal created or deleted
Junio C Hamanoba4b9282008-07-06 05:20:311163files.</p></div>
Junio C Hamano29f14312006-10-26 08:47:291164</li>
1165<li>
1166<p>
1167Chunk header format is modified to prevent people from
1168 accidentally feeding it to <tt>patch -p1</tt>. Combined diff format
1169 was created for review of merge commit changes, and was not
1170 meant for apply. The change is similar to the change in the
1171 extended <em>index</em> header:
1172</p>
1173<div class="literalblock">
1174<div class="content">
1175<pre><tt>@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</tt></pre>
1176</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311177<div class="para"><p>There are (number of parents + 1) <tt>@</tt> characters in the chunk
1178header for combined diff format.</p></div>
Junio C Hamano29f14312006-10-26 08:47:291179</li>
Junio C Hamanoba4b9282008-07-06 05:20:311180</ol></div>
1181<div class="para"><p>Unlike the traditional <em>unified</em> diff format, which shows two
Junio C Hamanofb56a962006-01-28 10:38:191182files A and B with a single column that has <tt>-</tt> (minus &#8212;
1183appears in A but removed in B), <tt>+</tt> (plus &#8212; missing in A but
Junio C Hamano29f14312006-10-26 08:47:291184added to B), or <tt>" "</tt> (space &#8212; unchanged) prefix, this format
Junio C Hamanofb56a962006-01-28 10:38:191185compares two or more files file1, file2,&#8230; with one file X, and
1186shows how X differs from each of fileN. One column for each of
1187fileN is prepended to the output line to note how X's line is
Junio C Hamanoba4b9282008-07-06 05:20:311188different from it.</p></div>
1189<div class="para"><p>A <tt>-</tt> character in the column N means that the line appears in
Junio C Hamano29f14312006-10-26 08:47:291190fileN but it does not appear in the result. A <tt>+</tt> character
Junio C Hamanofb56a962006-01-28 10:38:191191in the column N means that the line appears in the last file,
Junio C Hamano29f14312006-10-26 08:47:291192and fileN does not have that line (in other words, the line was
Junio C Hamanoba4b9282008-07-06 05:20:311193added, from the point of view of that parent).</p></div>
1194<div class="para"><p>In the above example output, the function signature was changed
Junio C Hamanofb56a962006-01-28 10:38:191195from both files (hence two <tt>-</tt> removals from both file1 and
Junio C Hamanoba4b9282008-07-06 05:20:311196file2, plus <tt><tt>+</tt> to mean one line that was added does not appear
Junio C Hamanofb56a962006-01-28 10:38:191197in either file1 nor file2). Also two other lines are the same
Junio C Hamanoba4b9282008-07-06 05:20:311198from file1 but do not appear in file2 (hence prefixed with <tt> </tt></tt>).</p></div>
1199<div class="para"><p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
Junio C Hamanofb56a962006-01-28 10:38:191200merge commit with the merge result (i.e. file1..fileN are the
1201parents). When shown by <tt>git diff-files -c</tt>, it compares the
1202two unresolved merge parents with the working tree file
1203(i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
Junio C Hamanoba4b9282008-07-06 05:20:311204"their version").</p></div>
Junio C Hamanofb56a962006-01-28 10:38:191205</div>
Junio C Hamanoba4b9282008-07-06 05:20:311206<h2 id="_other_diff_formats">other diff formats</h2>
Junio C Hamano3a702342007-12-12 21:34:021207<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311208<div class="para"><p>The <tt>--summary</tt> option describes newly added, deleted, renamed and
Junio C Hamano3a702342007-12-12 21:34:021209copied files. The <tt>--stat</tt> option adds diffstat(1) graph to the
1210output. These options can be combined with other options, such as
Junio C Hamanoba4b9282008-07-06 05:20:311211<tt>-p</tt>, and are meant for human consumption.</p></div>
1212<div class="para"><p>When showing a change that involves a rename or a copy, <tt>--stat</tt> output
Junio C Hamano3a702342007-12-12 21:34:021213formats the pathnames compactly by combining common prefix and suffix of
1214the pathnames. For example, a change that moves <tt>arch/i386/Makefile</tt> to
Junio C Hamanoba4b9282008-07-06 05:20:311215<tt>arch/x86/Makefile</tt> while modifying 4 lines will be shown like this:</p></div>
Junio C Hamano3a702342007-12-12 21:34:021216<div class="listingblock">
1217<div class="content">
1218<pre><tt>arch/{i386 =&gt; x86}/Makefile | 4 +--</tt></pre>
1219</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311220<div class="para"><p>The <tt>--numstat</tt> option gives the diffstat(1) information but is designed
Junio C Hamano3a702342007-12-12 21:34:021221for easier machine consumption. An entry in <tt>--numstat</tt> output looks
Junio C Hamanoba4b9282008-07-06 05:20:311222like this:</p></div>
Junio C Hamano3a702342007-12-12 21:34:021223<div class="listingblock">
1224<div class="content">
1225<pre><tt>1 2 README
12263 1 arch/{i386 =&gt; x86}/Makefile</tt></pre>
1227</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311228<div class="para"><p>That is, from left to right:</p></div>
1229<div class="olist"><ol>
Junio C Hamano3a702342007-12-12 21:34:021230<li>
1231<p>
1232the number of added lines;
1233</p>
1234</li>
1235<li>
1236<p>
1237a tab;
1238</p>
1239</li>
1240<li>
1241<p>
1242the number of deleted lines;
1243</p>
1244</li>
1245<li>
1246<p>
1247a tab;
1248</p>
1249</li>
1250<li>
1251<p>
1252pathname (possibly with rename/copy information);
1253</p>
1254</li>
1255<li>
1256<p>
1257a newline.
1258</p>
1259</li>
Junio C Hamanoba4b9282008-07-06 05:20:311260</ol></div>
1261<div class="para"><p>When <tt>-z</tt> output option is in effect, the output is formatted this way:</p></div>
Junio C Hamano3a702342007-12-12 21:34:021262<div class="listingblock">
1263<div class="content">
1264<pre><tt>1 2 README NUL
12653 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</tt></pre>
1266</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311267<div class="para"><p>That is:</p></div>
1268<div class="olist"><ol>
Junio C Hamano3a702342007-12-12 21:34:021269<li>
1270<p>
1271the number of added lines;
1272</p>
1273</li>
1274<li>
1275<p>
1276a tab;
1277</p>
1278</li>
1279<li>
1280<p>
1281the number of deleted lines;
1282</p>
1283</li>
1284<li>
1285<p>
1286a tab;
1287</p>
1288</li>
1289<li>
1290<p>
1291a NUL (only exists if renamed/copied);
1292</p>
1293</li>
1294<li>
1295<p>
1296pathname in preimage;
1297</p>
1298</li>
1299<li>
1300<p>
1301a NUL (only exists if renamed/copied);
1302</p>
1303</li>
1304<li>
1305<p>
1306pathname in postimage (only exists if renamed/copied);
1307</p>
1308</li>
1309<li>
1310<p>
1311a NUL.
1312</p>
1313</li>
Junio C Hamanoba4b9282008-07-06 05:20:311314</ol></div>
1315<div class="para"><p>The extra <tt>NUL</tt> before the preimage path in renamed case is to allow
Junio C Hamano3a702342007-12-12 21:34:021316scripts that read the output to tell if the current record being read is
1317a single-path record or a rename/copy record without reading ahead.
1318After reading added and deleted lines, reading up to <tt>NUL</tt> would yield
Junio C Hamanoba4b9282008-07-06 05:20:311319the pathname, but if that is <tt>NUL</tt>, the record will show two paths.</p></div>
Junio C Hamano3a702342007-12-12 21:34:021320</div>
Junio C Hamanoba4b9282008-07-06 05:20:311321<h2 id="_operating_modes">Operating Modes</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231322<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311323<div class="para"><p>You can choose whether you want to trust the index file entirely
Junio C Hamano1a4e8412005-12-27 08:17:231324(using the <em>--cached</em> flag) or ask the diff logic to show any files
1325that don't match the stat state as being "tentatively changed". Both
Junio C Hamanoba4b9282008-07-06 05:20:311326of these operations are very useful indeed.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231327</div>
Junio C Hamanoba4b9282008-07-06 05:20:311328<h2 id="_cached_mode">Cached Mode</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231329<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311330<div class="para"><p>If <em>--cached</em> is specified, it allows you to ask:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231331<div class="literalblock">
1332<div class="content">
1333<pre><tt>show me the differences between HEAD and the current index
Junio C Hamanoba4b9282008-07-06 05:20:311334contents (the ones I'd write using 'git-write-tree')</tt></pre>
Junio C Hamano1a4e8412005-12-27 08:17:231335</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311336<div class="para"><p>For example, let's say that you have worked on your working directory, updated
Junio C Hamano235a91e2006-01-07 01:13:581337some files in the index and are ready to commit. You want to see exactly
Junio C Hamanodcc22ee2006-11-03 02:40:131338<strong>what</strong> you are going to commit, without having to write a new tree
Junio C Hamanoba4b9282008-07-06 05:20:311339object and compare it that way, and to do that, you just do</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231340<div class="literalblock">
1341<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:381342<pre><tt>git diff-index --cached HEAD</tt></pre>
Junio C Hamano1a4e8412005-12-27 08:17:231343</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311344<div class="para"><p>Example: let's say I had renamed <tt>commit.c</tt> to <tt>git-commit.c</tt>, and I had
Junio C Hamanofce7c7e2008-07-02 03:06:381345done an <tt>update-index</tt> to make that effective in the index file.
1346<tt>git diff-files</tt> wouldn't show anything at all, since the index file
Junio C Hamanoba4b9282008-07-06 05:20:311347matches my working directory. But doing a <em>git-diff-index</em> does:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231348<div class="literalblock">
1349<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:381350<pre><tt>torvalds@ppc970:~/git&gt; git diff-index --cached HEAD
Junio C Hamano1a4e8412005-12-27 08:17:231351-100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1352+100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c</tt></pre>
1353</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311354<div class="para"><p>You can see easily that the above is a rename.</p></div>
1355<div class="para"><p>In fact, <tt>git diff-index --cached</tt> <strong>should</strong> always be entirely equivalent to
1356actually doing a <em>git-write-tree</em> and comparing that. Except this one is much
1357nicer for the case where you just want to check where you are.</p></div>
1358<div class="para"><p>So doing a <em>git-diff-index --cached</em> is basically very useful when you are
Junio C Hamano1a4e8412005-12-27 08:17:231359asking yourself "what have I already marked for being committed, and
Junio C Hamanoba4b9282008-07-06 05:20:311360what's the difference to a previous tree".</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231361</div>
Junio C Hamanoba4b9282008-07-06 05:20:311362<h2 id="_non_cached_mode">Non-cached Mode</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231363<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311364<div class="para"><p>The "non-cached" mode takes a different approach, and is potentially
Junio C Hamano1a4e8412005-12-27 08:17:231365the more useful of the two in that what it does can't be emulated with
Junio C Hamanoba4b9282008-07-06 05:20:311366a <em>git-write-tree</em> + <em>git-diff-tree</em>. Thus that's the default mode.
1367The non-cached version asks the question:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231368<div class="literalblock">
1369<div class="content">
1370<pre><tt>show me the differences between HEAD and the currently checked out
1371tree - index contents _and_ files that aren't up-to-date</tt></pre>
1372</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311373<div class="para"><p>which is obviously a very useful question too, since that tells you what
1374you <strong>could</strong> commit. Again, the output matches the <em>git-diff-tree -r</em>
1375output to a tee, but with a twist.</p></div>
1376<div class="para"><p>The twist is that if some file doesn't match the index, we don't have
Junio C Hamano1a4e8412005-12-27 08:17:231377a backing store thing for it, and we use the magic "all-zero" sha1 to
1378show that. So let's say that you have edited <tt>kernel/sched.c</tt>, but
Junio C Hamanoba4b9282008-07-06 05:20:311379have not actually done a <em>git-update-index</em> on it yet - there is no
1380"object" associated with the new state, and you get:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231381<div class="literalblock">
1382<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:381383<pre><tt>torvalds@ppc970:~/v2.6/linux&gt; git diff-index HEAD
Junio C Hamano1a4e8412005-12-27 08:17:231384*100644-&gt;100664 blob 7476bb......-&gt;000000...... kernel/sched.c</tt></pre>
1385</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:311386<div class="para"><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:231387not up-to-date and may contain new stuff. The all-zero sha1 means that to
1388get the real diff, you need to look at the object in the working directory
Junio C Hamanoba4b9282008-07-06 05:20:311389directly rather than do an object-to-object diff.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231390<div class="admonitionblock">
1391<table><tr>
1392<td class="icon">
1393<div class="title">Note</div>
1394</td>
Junio C Hamanoba4b9282008-07-06 05:20:311395<td class="content">As with other commands of this type, <em>git-diff-index</em> does not
Junio C Hamano1a4e8412005-12-27 08:17:231396actually look at the contents of the file at all. So maybe
1397<tt>kernel/sched.c</tt> hasn't actually changed, and it's just that you
1398touched it. In either case, it's a note that you need to
Junio C Hamanoba4b9282008-07-06 05:20:311399<em>git-update-index</em> it to make the index be in sync.</td>
Junio C Hamano1a4e8412005-12-27 08:17:231400</tr></table>
1401</div>
1402<div class="admonitionblock">
1403<table><tr>
1404<td class="icon">
1405<div class="title">Note</div>
1406</td>
1407<td class="content">You can have a mixture of files show up as "has been updated"
1408and "is still dirty in the working directory" together. You can always
1409tell which file is in which state, since the "has been updated" ones
1410show a valid sha1, and the "not in sync with the index" ones will
1411always have the special all-zero sha1.</td>
1412</tr></table>
1413</div>
1414</div>
Junio C Hamanoba4b9282008-07-06 05:20:311415<h2 id="_author">Author</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231416<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311417<div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231418</div>
Junio C Hamanoba4b9282008-07-06 05:20:311419<h2 id="_documentation">Documentation</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231420<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311421<div class="para"><p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231422</div>
Junio C Hamanoba4b9282008-07-06 05:20:311423<h2 id="_git">GIT</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231424<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:311425<div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231426</div>
1427<div id="footer">
1428<div id="footer-text">
Junio C Hamanoba4b9282008-07-06 05:20:311429Last updated 2008-07-06 05:16:43 UTC
Junio C Hamano1a4e8412005-12-27 08:17:231430</div>
1431</div>
1432</body>
1433</html>