blob: c3338948cb923a9dabea9265e6727cc237169123 [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>
Junio C Hamanoff979792007-11-16 10:11:30293 Generate patch (see section on generating patches).
294
Junio C Hamano1a4e8412005-12-27 08:17:23295</p>
296</dd>
297<dt>
298-u
299</dt>
300<dd>
301<p>
302 Synonym for "-p".
303</p>
304</dd>
305<dt>
Junio C Hamano69361562007-07-26 02:14:34306-U&lt;n&gt;
307</dt>
308<dd>
309<p>
310 Shorthand for "--unified=&lt;n&gt;".
311</p>
312</dd>
313<dt>
314--unified=&lt;n&gt;
315</dt>
316<dd>
317<p>
318 Generate diffs with &lt;n&gt; lines of context instead of
319 the usual three. Implies "-p".
320</p>
321</dd>
322<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34323--raw
324</dt>
325<dd>
326<p>
327 Generate the raw format.
Junio C Hamanoff979792007-11-16 10:11:30328 This is the default.
Junio C Hamano9ae1a062006-07-10 08:12:34329</p>
330</dd>
331<dt>
Junio C Hamano54559c82006-04-13 07:45:12332--patch-with-raw
333</dt>
334<dd>
335<p>
Junio C Hamano9ae1a062006-07-10 08:12:34336 Synonym for "-p --raw".
Junio C Hamano54559c82006-04-13 07:45:12337</p>
338</dd>
339<dt>
Junio C Hamano4a9a76a2006-10-01 05:40:29340--stat[=width[,name-width]]
Junio C Hamanoba7c8d82006-04-15 06:17:42341</dt>
342<dd>
343<p>
Junio C Hamano4a9a76a2006-10-01 05:40:29344 Generate a diffstat. You can override the default
345 output width for 80-column terminal by "--stat=width".
346 The width of the filename part can be controlled by
347 giving another width to it separated by a comma.
Junio C Hamanoba7c8d82006-04-15 06:17:42348</p>
349</dd>
350<dt>
Junio C Hamanofbe00522006-10-19 05:58:48351--numstat
352</dt>
353<dd>
354<p>
355 Similar to --stat, but shows number of added and
356 deleted lines in decimal notation and pathname without
Junio C Hamanod793de52006-12-26 09:11:43357 abbreviation, to make it more machine friendly. For
358 binary files, outputs two <tt>-</tt> instead of saying
359 <tt>0 0</tt>.
Junio C Hamanofbe00522006-10-19 05:58:48360</p>
361</dd>
362<dt>
Junio C Hamano7d23f5e2006-12-16 07:44:04363--shortstat
364</dt>
365<dd>
366<p>
367 Output only the last line of the --stat format containing total
368 number of modified files, as well as number of added and deleted
369 lines.
370</p>
371</dd>
372<dt>
Junio C Hamano6959c6c2006-05-17 10:34:11373--summary
374</dt>
375<dd>
376<p>
377 Output a condensed summary of extended header information
378 such as creations, renames and mode changes.
379</p>
380</dd>
381<dt>
Junio C Hamanod1308c92006-04-16 11:01:09382--patch-with-stat
383</dt>
384<dd>
385<p>
Junio C Hamano9ae1a062006-07-10 08:12:34386 Synonym for "-p --stat".
Junio C Hamanoff979792007-11-16 10:11:30387
Junio C Hamanod1308c92006-04-16 11:01:09388</p>
389</dd>
390<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23391-z
392</dt>
393<dd>
394<p>
Junio C Hamanob968dbb2007-07-27 07:26:40395 NUL-line termination on output. This affects the --raw
396 output field terminator. Also output from commands such
397 as "git-log" will be delimited with NUL between commits.
Junio C Hamano1a4e8412005-12-27 08:17:23398</p>
399</dd>
400<dt>
401--name-only
402</dt>
403<dd>
404<p>
405 Show only names of changed files.
406</p>
407</dd>
408<dt>
409--name-status
410</dt>
411<dd>
412<p>
413 Show only names and status of changed files.
414</p>
415</dd>
416<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34417--color
418</dt>
419<dd>
420<p>
421 Show colored diff.
422</p>
423</dd>
424<dt>
425--no-color
426</dt>
427<dd>
428<p>
429 Turn off colored diff, even when the configuration file
430 gives the default to color output.
431</p>
432</dd>
433<dt>
Junio C Hamano85e45fa2006-08-13 07:47:41434--color-words
435</dt>
436<dd>
437<p>
438 Show colored word diff, i.e. color words which have changed.
439</p>
440</dd>
441<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34442--no-renames
443</dt>
444<dd>
445<p>
446 Turn off rename detection, even when the configuration
447 file gives the default to do so.
448</p>
449</dd>
450<dt>
Junio C Hamanoa890c4f2007-01-28 10:29:21451--check
452</dt>
453<dd>
454<p>
455 Warn if changes introduce trailing whitespace
Junio C Hamano3dac5042007-12-15 08:40:54456 or an indent that uses a space before a tab. Exits with
457 non-zero status if problems are found. Not compatible with
458 --exit-code.
Junio C Hamanoa890c4f2007-01-28 10:29:21459</p>
460</dd>
461<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23462--full-index
463</dt>
464<dd>
465<p>
466 Instead of the first handful characters, show full
467 object name of pre- and post-image blob on the "index"
468 line when generating a patch format output.
469</p>
470</dd>
471<dt>
Junio C Hamano9ae1a062006-07-10 08:12:34472--binary
473</dt>
474<dd>
475<p>
476 In addition to --full-index, output "binary diff" that
477 can be applied with "git apply".
478</p>
479</dd>
480<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23481--abbrev[=&lt;n&gt;]
482</dt>
483<dd>
484<p>
485 Instead of showing the full 40-byte hexadecimal object
486 name in diff-raw format output and diff-tree header
Junio C Hamano235a91e2006-01-07 01:13:58487 lines, show only handful hexdigits prefix. This is
Junio C Hamano1a4e8412005-12-27 08:17:23488 independent of --full-index option above, which controls
489 the diff-patch output format. Non default number of
490 digits can be specified with --abbrev=&lt;n&gt;.
491</p>
492</dd>
493<dt>
494-B
495</dt>
496<dd>
497<p>
498 Break complete rewrite changes into pairs of delete and create.
499</p>
500</dd>
501<dt>
502-M
503</dt>
504<dd>
505<p>
506 Detect renames.
507</p>
508</dd>
509<dt>
510-C
511</dt>
512<dd>
513<p>
Junio C Hamano16f98872007-06-12 16:09:14514 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
Junio C Hamano1a4e8412005-12-27 08:17:23515</p>
516</dd>
517<dt>
Junio C Hamano6ec31b92006-02-10 05:52:01518--diff-filter=[ACDMRTUXB*]
519</dt>
520<dd>
521<p>
522 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
523 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
524 type (mode) changed (<tt>T</tt>), are Unmerged (<tt>U</tt>), are
525 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
526 Any combination of the filter characters may be used.
527 When <tt>*</tt> (All-or-none) is added to the combination, all
528 paths are selected if there is any file that matches
529 other criteria in the comparison; if there is no file
530 that matches other criteria, nothing is selected.
531</p>
532</dd>
533<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23534--find-copies-harder
535</dt>
536<dd>
537<p>
Junio C Hamano16f98872007-06-12 16:09:14538 For performance reasons, by default, <tt>-C</tt> option finds copies only
Junio C Hamano1a4e8412005-12-27 08:17:23539 if the original file of the copy was modified in the same
540 changeset. This flag makes the command
541 inspect unmodified files as candidates for the source of
542 copy. This is a very expensive operation for large
Junio C Hamano16f98872007-06-12 16:09:14543 projects, so use it with caution. Giving more than one
544 <tt>-C</tt> option has the same effect.
Junio C Hamano1a4e8412005-12-27 08:17:23545</p>
546</dd>
547<dt>
548-l&lt;num&gt;
549</dt>
550<dd>
551<p>
552 -M and -C options require O(n^2) processing time where n
553 is the number of potential rename/copy targets. This
554 option prevents rename/copy detection from running if
555 the number of rename/copy targets exceeds the specified
556 number.
557</p>
558</dd>
559<dt>
560-S&lt;string&gt;
561</dt>
562<dd>
563<p>
564 Look for differences that contain the change in &lt;string&gt;.
565</p>
566</dd>
567<dt>
568--pickaxe-all
569</dt>
570<dd>
571<p>
572 When -S finds a change, show all the changes in that
573 changeset, not just the files that contain the change
574 in &lt;string&gt;.
575</p>
576</dd>
577<dt>
Junio C Hamanobfe9e752006-04-05 21:43:28578--pickaxe-regex
579</dt>
580<dd>
581<p>
582 Make the &lt;string&gt; not a plain string but an extended POSIX
583 regex to match.
584</p>
585</dd>
586<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23587-O&lt;orderfile&gt;
588</dt>
589<dd>
590<p>
591 Output the patch in the order specified in the
592 &lt;orderfile&gt;, which has one shell glob pattern per line.
593</p>
594</dd>
595<dt>
596-R
597</dt>
598<dd>
599<p>
600 Swap two inputs; that is, show differences from index or
601 on-disk file to tree contents.
602</p>
603</dd>
Junio C Hamanoc26f5482006-07-09 09:38:14604<dt>
605--text
606</dt>
607<dd>
608<p>
609 Treat all files as text.
610</p>
611</dd>
612<dt>
613-a
614</dt>
615<dd>
616<p>
617 Shorthand for "--text".
618</p>
619</dd>
Junio C Hamanod9c2d2f2006-12-06 08:59:07620<dt>
Junio C Hamanofd468962007-02-14 23:45:04621--ignore-space-at-eol
622</dt>
623<dd>
624<p>
Junio C Hamano3a702342007-12-12 21:34:02625 Ignore changes in whitespace at EOL.
Junio C Hamanofd468962007-02-14 23:45:04626</p>
627</dd>
628<dt>
Junio C Hamanod9c2d2f2006-12-06 08:59:07629--ignore-space-change
630</dt>
631<dd>
632<p>
Junio C Hamano3a702342007-12-12 21:34:02633 Ignore changes in amount of whitespace. This ignores whitespace
634 at line end, and considers all other sequences of one or
635 more whitespace characters to be equivalent.
Junio C Hamanod9c2d2f2006-12-06 08:59:07636</p>
637</dd>
638<dt>
639-b
640</dt>
641<dd>
642<p>
643 Shorthand for "--ignore-space-change".
644</p>
645</dd>
646<dt>
647--ignore-all-space
648</dt>
649<dd>
650<p>
Junio C Hamano3a702342007-12-12 21:34:02651 Ignore whitespace when comparing lines. This ignores
652 differences even if one line has whitespace where the other
Junio C Hamanod9c2d2f2006-12-06 08:59:07653 line has none.
654</p>
655</dd>
656<dt>
657-w
658</dt>
659<dd>
660<p>
661 Shorthand for "--ignore-all-space".
662</p>
663</dd>
Junio C Hamano48fd2f62007-03-19 02:02:30664<dt>
665--exit-code
666</dt>
667<dd>
668<p>
669 Make the program exit with codes similar to diff(1).
670 That is, it exits with 1 if there were differences and
671 0 means no differences.
672</p>
673</dd>
Junio C Hamano35e57552007-03-25 07:54:35674<dt>
675--quiet
676</dt>
677<dd>
678<p>
679 Disable all output of the program. Implies --exit-code.
680</p>
681</dd>
Junio C Hamanobb0f4042007-07-04 06:41:40682<dt>
683--ext-diff
684</dt>
685<dd>
686<p>
687 Allow an external diff helper to be executed. If you set an
Junio C Hamano1b50ce92007-10-03 12:05:53688 external diff driver with <a href="gitattributes.html">gitattributes(5)</a>, you need
689 to use this option with <a href="git-log.html">git-log(1)</a> and friends.
Junio C Hamanobb0f4042007-07-04 06:41:40690</p>
691</dd>
692<dt>
693--no-ext-diff
694</dt>
695<dd>
696<p>
697 Disallow external diff drivers.
698</p>
699</dd>
Junio C Hamanoe27cbd22007-12-21 17:57:33700<dt>
701--src-prefix=&lt;prefix&gt;
702</dt>
703<dd>
704<p>
705 Show the given source prefix instead of "a/".
706</p>
707</dd>
708<dt>
709--dst-prefix=&lt;prefix&gt;
710</dt>
711<dd>
712<p>
713 Show the given destination prefix instead of "b/".
714</p>
715</dd>
716<dt>
717--no-prefix
718</dt>
719<dd>
720<p>
721 Do not show any source or destination prefix.
722</p>
723</dd>
Junio C Hamano1a4e8412005-12-27 08:17:23724</dl>
725<p>For more detailed explanation on these common options, see also
726<a href="diffcore.html">diffcore documentation</a>.</p>
727<dl>
728<dt>
729&lt;tree-ish&gt;
730</dt>
731<dd>
732<p>
733 The id of a tree object to diff against.
734</p>
735</dd>
736<dt>
737--cached
738</dt>
739<dd>
740<p>
741 do not consider the on-disk file at all
742</p>
743</dd>
744<dt>
745-m
746</dt>
747<dd>
748<p>
749 By default, files recorded in the index but not checked
750 out are reported as deleted. This flag makes
751 "git-diff-index" say that all non-checked-out files are up
752 to date.
753</p>
754</dd>
755</dl>
756</div>
757<h2>Output format</h2>
758<div class="sectionbody">
Junio C Hamano7ae0ab22007-11-03 02:46:46759<p>The output format from "git-diff-index", "git-diff-tree",
760"git-diff-files" and "git diff --raw" are very similar.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23761<p>These commands all compare two sets of things; what is
762compared differs:</p>
763<dl>
764<dt>
765git-diff-index &lt;tree-ish&gt;
766</dt>
767<dd>
768<p>
769 compares the &lt;tree-ish&gt; and the files on the filesystem.
770</p>
771</dd>
772<dt>
773git-diff-index --cached &lt;tree-ish&gt;
774</dt>
775<dd>
776<p>
777 compares the &lt;tree-ish&gt; and the index.
778</p>
779</dd>
780<dt>
781git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
782</dt>
783<dd>
784<p>
785 compares the trees named by the two arguments.
786</p>
787</dd>
788<dt>
789git-diff-files [&lt;pattern&gt;&#8230;]
790</dt>
791<dd>
792<p>
793 compares the index and the files on the filesystem.
794</p>
795</dd>
796</dl>
797<p>An output line is formatted this way:</p>
798<div class="listingblock">
799<div class="content">
800<pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
801copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
802rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
803create :000000 100644 0000000... 1234567... A file4
804delete :100644 000000 1234567... 0000000... D file5
805unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
806</div></div>
807<p>That is, from the left to the right:</p>
808<ol>
809<li>
810<p>
811a colon.
812</p>
813</li>
814<li>
815<p>
816mode for "src"; 000000 if creation or unmerged.
817</p>
818</li>
819<li>
820<p>
821a space.
822</p>
823</li>
824<li>
825<p>
826mode for "dst"; 000000 if deletion or unmerged.
827</p>
828</li>
829<li>
830<p>
831a space.
832</p>
833</li>
834<li>
835<p>
836sha1 for "src"; 0{40} if creation or unmerged.
837</p>
838</li>
839<li>
840<p>
841a space.
842</p>
843</li>
844<li>
845<p>
846sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
847</p>
848</li>
849<li>
850<p>
851a space.
852</p>
853</li>
854<li>
855<p>
856status, followed by optional "score" number.
857</p>
858</li>
859<li>
860<p>
861a tab or a NUL when <em>-z</em> option is used.
862</p>
863</li>
864<li>
865<p>
866path for "src"
867</p>
868</li>
869<li>
870<p>
871a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
872</p>
873</li>
874<li>
875<p>
876path for "dst"; only exists for C or R.
877</p>
878</li>
879<li>
880<p>
881an LF or a NUL when <em>-z</em> option is used, to terminate the record.
882</p>
883</li>
884</ol>
885<p>&lt;sha1&gt; is shown as all 0's if a file is new on the filesystem
886and it is out of sync with the index.</p>
887<p>Example:</p>
888<div class="listingblock">
889<div class="content">
890<pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
891</div></div>
892<p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
893in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
894respectively.</p>
895</div>
Junio C Hamano67fad6d2007-05-06 08:53:12896<h2>diff format for merges</h2>
897<div class="sectionbody">
Junio C Hamano7ae0ab22007-11-03 02:46:46898<p>"git-diff-tree", "git-diff-files" and "git-diff --raw"
899can take <em>-c</em> or <em>--cc</em> option
Junio C Hamano67fad6d2007-05-06 08:53:12900to generate diff output also for merge commits. The output differs
901from the format described above in the following way:</p>
902<ol>
903<li>
904<p>
905there is a colon for each parent
906</p>
907</li>
908<li>
909<p>
910there are more "src" modes and "src" sha1
911</p>
912</li>
913<li>
914<p>
915status is concatenated status characters for each parent
916</p>
917</li>
918<li>
919<p>
920no optional "score" number
921</p>
922</li>
923<li>
924<p>
925single path, only for "dst"
926</p>
927</li>
928</ol>
929<p>Example:</p>
930<div class="listingblock">
931<div class="content">
932<pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
933</div></div>
934<p>Note that <em>combined diff</em> lists only files which were modified from
935all parents.</p>
936</div>
Junio C Hamano1a4e8412005-12-27 08:17:23937<h2>Generating patches with -p</h2>
938<div class="sectionbody">
939<p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
Junio C Hamano00b8b632007-12-07 09:50:49940with a <em>-p</em> option, "git diff" without the <em>--raw</em> option, or
941"git log" with the "-p" option, they
Junio C Hamano7ae0ab22007-11-03 02:46:46942do not produce the output described above; instead they produce a
943patch file. You can customize the creation of such patches via the
944GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p>
Junio C Hamano1c437122006-11-28 02:22:25945<p>What the -p option produces is slightly different from the traditional
946diff format.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23947<ol>
948<li>
949<p>
Junio C Hamano235a91e2006-01-07 01:13:58950It is preceded with a "git diff" header, that looks like
Junio C Hamano1a4e8412005-12-27 08:17:23951 this:
952</p>
953<div class="literalblock">
954<div class="content">
955<pre><tt>diff --git a/file1 b/file2</tt></pre>
956</div></div>
957<p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
958involved. Especially, even for a creation or a deletion,
959<tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p>
960<p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
961name of the source file of the rename/copy and the name of
962the file that rename/copy produces, respectively.</p>
963</li>
964<li>
965<p>
966It is followed by one or more extended header lines:
967</p>
968<div class="literalblock">
969<div class="content">
970<pre><tt>old mode &lt;mode&gt;
971new mode &lt;mode&gt;
972deleted file mode &lt;mode&gt;
973new file mode &lt;mode&gt;
974copy from &lt;path&gt;
975copy to &lt;path&gt;
976rename from &lt;path&gt;
977rename to &lt;path&gt;
978similarity index &lt;number&gt;
979dissimilarity index &lt;number&gt;
980index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</tt></pre>
981</div></div>
982</li>
983<li>
984<p>
Junio C Hamanoa053d542006-10-27 09:29:13985TAB, LF, double quote and backslash characters in pathnames
986 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and <tt>\\</tt>, respectively.
987 If there is need for such substitution then the whole
988 pathname is put in double quotes.
Junio C Hamano1a4e8412005-12-27 08:17:23989</p>
990</li>
991</ol>
Junio C Hamanod526ba92007-07-02 00:17:42992<p>The similarity index is the percentage of unchanged lines, and
993the dissimilarity index is the percentage of changed lines. It
994is a rounded down integer, followed by a percent sign. The
995similarity index value of 100% is thus reserved for two equal
996files, while 100% dissimilarity means that no line from the old
997file made it into the new one.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23998</div>
Junio C Hamanofb56a962006-01-28 10:38:19999<h2>combined diff format</h2>
1000<div class="sectionbody">
Junio C Hamano7ae0ab22007-11-03 02:46:461001<p>"git-diff-tree", "git-diff-files" and "git-diff" can take <em>-c</em> or
Junio C Hamano00b8b632007-12-07 09:50:491002<em>--cc</em> option to produce <em>combined diff</em>. For showing a merge commit
1003with "git log -p", this is the default format.
1004A <em>combined diff</em> format looks like this:</p>
Junio C Hamanofb56a962006-01-28 10:38:191005<div class="listingblock">
1006<div class="content">
1007<pre><tt>diff --combined describe.c
Junio C Hamano29f14312006-10-26 08:47:291008index fabadb8,cc95eb0..4866510
1009--- a/describe.c
1010+++ b/describe.c
1011@@@ -98,20 -98,12 +98,20 @@@
1012 return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
Junio C Hamanofb56a962006-01-28 10:38:191013 }
1014
1015- static void describe(char *arg)
1016 -static void describe(struct commit *cmit, int last_one)
1017++static void describe(char *arg, int last_one)
1018 {
Junio C Hamano29f14312006-10-26 08:47:291019 + unsigned char sha1[20];
1020 + struct commit *cmit;
1021 struct commit_list *list;
1022 static int initialized = 0;
1023 struct commit_name *n;
1024
1025 + if (get_sha1(arg, sha1) &lt; 0)
1026 + usage(describe_usage);
1027 + cmit = lookup_commit_reference(sha1);
1028 + if (!cmit)
1029 + usage(describe_usage);
1030 +
1031 if (!initialized) {
1032 initialized = 1;
1033 for_each_ref(get_name);</tt></pre>
Junio C Hamanofb56a962006-01-28 10:38:191034</div></div>
Junio C Hamano29f14312006-10-26 08:47:291035<ol>
1036<li>
1037<p>
1038It is preceded with a "git diff" header, that looks like
1039 this (when <em>-c</em> option is used):
1040</p>
1041<div class="literalblock">
1042<div class="content">
1043<pre><tt>diff --combined file</tt></pre>
1044</div></div>
1045<p>or like this (when <em>--cc</em> option is used):</p>
1046<div class="literalblock">
1047<div class="content">
1048<pre><tt>diff --c file</tt></pre>
1049</div></div>
1050</li>
1051<li>
1052<p>
1053It is followed by one or more extended header lines
1054 (this example shows a merge with two parents):
1055</p>
1056<div class="literalblock">
1057<div class="content">
1058<pre><tt>index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;
1059mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;
1060new file mode &lt;mode&gt;
1061deleted file mode &lt;mode&gt;,&lt;mode&gt;</tt></pre>
1062</div></div>
1063<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:041064the &lt;mode&gt; is different from the rest. Extended headers with
Junio C Hamano29f14312006-10-26 08:47:291065information about detected contents movement (renames and
1066copying detection) are designed to work with diff of two
1067&lt;tree-ish&gt; and are not used by combined diff format.</p>
1068</li>
1069<li>
1070<p>
1071It is followed by two-line from-file/to-file header
1072</p>
1073<div class="literalblock">
1074<div class="content">
1075<pre><tt>--- a/file
1076+++ b/file</tt></pre>
1077</div></div>
1078<p>Similar to two-line header for traditional <em>unified</em> diff
1079format, <tt>/dev/null</tt> is used to signal created or deleted
1080files.</p>
1081</li>
1082<li>
1083<p>
1084Chunk header format is modified to prevent people from
1085 accidentally feeding it to <tt>patch -p1</tt>. Combined diff format
1086 was created for review of merge commit changes, and was not
1087 meant for apply. The change is similar to the change in the
1088 extended <em>index</em> header:
1089</p>
1090<div class="literalblock">
1091<div class="content">
1092<pre><tt>@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</tt></pre>
1093</div></div>
1094<p>There are (number of parents + 1) <tt>@</tt> characters in the chunk
1095header for combined diff format.</p>
1096</li>
1097</ol>
Junio C Hamanofb56a962006-01-28 10:38:191098<p>Unlike the traditional <em>unified</em> diff format, which shows two
1099files A and B with a single column that has <tt>-</tt> (minus &#8212;
1100appears in A but removed in B), <tt>+</tt> (plus &#8212; missing in A but
Junio C Hamano29f14312006-10-26 08:47:291101added to B), or <tt>" "</tt> (space &#8212; unchanged) prefix, this format
Junio C Hamanofb56a962006-01-28 10:38:191102compares two or more files file1, file2,&#8230; with one file X, and
1103shows how X differs from each of fileN. One column for each of
1104fileN is prepended to the output line to note how X's line is
1105different from it.</p>
1106<p>A <tt>-</tt> character in the column N means that the line appears in
Junio C Hamano29f14312006-10-26 08:47:291107fileN but it does not appear in the result. A <tt>+</tt> character
Junio C Hamanofb56a962006-01-28 10:38:191108in the column N means that the line appears in the last file,
Junio C Hamano29f14312006-10-26 08:47:291109and fileN does not have that line (in other words, the line was
1110added, from the point of view of that parent).</p>
Junio C Hamanofb56a962006-01-28 10:38:191111<p>In the above example output, the function signature was changed
1112from both files (hence two <tt>-</tt> removals from both file1 and
1113file2, plus <tt>++</tt> to mean one line that was added does not appear
1114in either file1 nor file2). Also two other lines are the same
1115from file1 but do not appear in file2 (hence prefixed with <tt> +</tt>).</p>
1116<p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
1117merge commit with the merge result (i.e. file1..fileN are the
1118parents). When shown by <tt>git diff-files -c</tt>, it compares the
1119two unresolved merge parents with the working tree file
1120(i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
1121"their version").</p>
1122</div>
Junio C Hamano3a702342007-12-12 21:34:021123<h2>other diff formats</h2>
1124<div class="sectionbody">
1125<p>The <tt>--summary</tt> option describes newly added, deleted, renamed and
1126copied files. The <tt>--stat</tt> option adds diffstat(1) graph to the
1127output. These options can be combined with other options, such as
1128<tt>-p</tt>, and are meant for human consumption.</p>
1129<p>When showing a change that involves a rename or a copy, <tt>--stat</tt> output
1130formats the pathnames compactly by combining common prefix and suffix of
1131the pathnames. For example, a change that moves <tt>arch/i386/Makefile</tt> to
1132<tt>arch/x86/Makefile</tt> while modifying 4 lines will be shown like this:</p>
1133<div class="listingblock">
1134<div class="content">
1135<pre><tt>arch/{i386 =&gt; x86}/Makefile | 4 +--</tt></pre>
1136</div></div>
1137<p>The <tt>--numstat</tt> option gives the diffstat(1) information but is designed
1138for easier machine consumption. An entry in <tt>--numstat</tt> output looks
1139like this:</p>
1140<div class="listingblock">
1141<div class="content">
1142<pre><tt>1 2 README
11433 1 arch/{i386 =&gt; x86}/Makefile</tt></pre>
1144</div></div>
1145<p>That is, from left to right:</p>
1146<ol>
1147<li>
1148<p>
1149the number of added lines;
1150</p>
1151</li>
1152<li>
1153<p>
1154a tab;
1155</p>
1156</li>
1157<li>
1158<p>
1159the number of deleted lines;
1160</p>
1161</li>
1162<li>
1163<p>
1164a tab;
1165</p>
1166</li>
1167<li>
1168<p>
1169pathname (possibly with rename/copy information);
1170</p>
1171</li>
1172<li>
1173<p>
1174a newline.
1175</p>
1176</li>
1177</ol>
1178<p>When <tt>-z</tt> output option is in effect, the output is formatted this way:</p>
1179<div class="listingblock">
1180<div class="content">
1181<pre><tt>1 2 README NUL
11823 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</tt></pre>
1183</div></div>
1184<p>That is:</p>
1185<ol>
1186<li>
1187<p>
1188the number of added lines;
1189</p>
1190</li>
1191<li>
1192<p>
1193a tab;
1194</p>
1195</li>
1196<li>
1197<p>
1198the number of deleted lines;
1199</p>
1200</li>
1201<li>
1202<p>
1203a tab;
1204</p>
1205</li>
1206<li>
1207<p>
1208a NUL (only exists if renamed/copied);
1209</p>
1210</li>
1211<li>
1212<p>
1213pathname in preimage;
1214</p>
1215</li>
1216<li>
1217<p>
1218a NUL (only exists if renamed/copied);
1219</p>
1220</li>
1221<li>
1222<p>
1223pathname in postimage (only exists if renamed/copied);
1224</p>
1225</li>
1226<li>
1227<p>
1228a NUL.
1229</p>
1230</li>
1231</ol>
1232<p>The extra <tt>NUL</tt> before the preimage path in renamed case is to allow
1233scripts that read the output to tell if the current record being read is
1234a single-path record or a rename/copy record without reading ahead.
1235After reading added and deleted lines, reading up to <tt>NUL</tt> would yield
1236the pathname, but if that is <tt>NUL</tt>, the record will show two paths.</p>
1237</div>
Junio C Hamano1a4e8412005-12-27 08:17:231238<h2>Operating Modes</h2>
1239<div class="sectionbody">
1240<p>You can choose whether you want to trust the index file entirely
1241(using the <em>--cached</em> flag) or ask the diff logic to show any files
1242that don't match the stat state as being "tentatively changed". Both
1243of these operations are very useful indeed.</p>
1244</div>
1245<h2>Cached Mode</h2>
1246<div class="sectionbody">
1247<p>If <em>--cached</em> is specified, it allows you to ask:</p>
1248<div class="literalblock">
1249<div class="content">
1250<pre><tt>show me the differences between HEAD and the current index
1251contents (the ones I'd write with a "git-write-tree")</tt></pre>
1252</div></div>
1253<p>For example, let's say that you have worked on your working directory, updated
Junio C Hamano235a91e2006-01-07 01:13:581254some files in the index and are ready to commit. You want to see exactly
Junio C Hamanodcc22ee2006-11-03 02:40:131255<strong>what</strong> you are going to commit, without having to write a new tree
Junio C Hamano1a4e8412005-12-27 08:17:231256object and compare it that way, and to do that, you just do</p>
1257<div class="literalblock">
1258<div class="content">
1259<pre><tt>git-diff-index --cached HEAD</tt></pre>
1260</div></div>
1261<p>Example: let's say I had renamed <tt>commit.c</tt> to <tt>git-commit.c</tt>, and I had
1262done an "git-update-index" to make that effective in the index file.
1263"git-diff-files" wouldn't show anything at all, since the index file
1264matches my working directory. But doing a "git-diff-index" does:</p>
1265<div class="literalblock">
1266<div class="content">
1267<pre><tt>torvalds@ppc970:~/git&gt; git-diff-index --cached HEAD
1268-100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1269+100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c</tt></pre>
1270</div></div>
Junio C Hamanodcc22ee2006-11-03 02:40:131271<p>You can see easily that the above is a rename.</p>
Junio C Hamano1a4e8412005-12-27 08:17:231272<p>In fact, "git-diff-index --cached" <strong>should</strong> always be entirely equivalent to
1273actually doing a "git-write-tree" and comparing that. Except this one is much
1274nicer for the case where you just want to check where you are.</p>
1275<p>So doing a "git-diff-index --cached" is basically very useful when you are
1276asking yourself "what have I already marked for being committed, and
1277what's the difference to a previous tree".</p>
1278</div>
1279<h2>Non-cached Mode</h2>
1280<div class="sectionbody">
1281<p>The "non-cached" mode takes a different approach, and is potentially
1282the more useful of the two in that what it does can't be emulated with
1283a "git-write-tree" + "git-diff-tree". Thus that's the default mode.
1284The non-cached version asks the question:</p>
1285<div class="literalblock">
1286<div class="content">
1287<pre><tt>show me the differences between HEAD and the currently checked out
1288tree - index contents _and_ files that aren't up-to-date</tt></pre>
1289</div></div>
1290<p>which is obviously a very useful question too, since that tells you what
1291you <strong>could</strong> commit. Again, the output matches the "git-diff-tree -r"
1292output to a tee, but with a twist.</p>
1293<p>The twist is that if some file doesn't match the index, we don't have
1294a backing store thing for it, and we use the magic "all-zero" sha1 to
1295show that. So let's say that you have edited <tt>kernel/sched.c</tt>, but
1296have not actually done a "git-update-index" on it yet - there is no
1297"object" associated with the new state, and you get:</p>
1298<div class="literalblock">
1299<div class="content">
1300<pre><tt>torvalds@ppc970:~/v2.6/linux&gt; git-diff-index HEAD
1301*100644-&gt;100664 blob 7476bb......-&gt;000000...... kernel/sched.c</tt></pre>
1302</div></div>
Junio C Hamano341071d2006-06-04 07:24:481303<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:231304not up-to-date and may contain new stuff. The all-zero sha1 means that to
1305get the real diff, you need to look at the object in the working directory
1306directly rather than do an object-to-object diff.</p>
1307<div class="admonitionblock">
1308<table><tr>
1309<td class="icon">
1310<div class="title">Note</div>
1311</td>
1312<td class="content">As with other commands of this type, "git-diff-index" does not
1313actually look at the contents of the file at all. So maybe
1314<tt>kernel/sched.c</tt> hasn't actually changed, and it's just that you
1315touched it. In either case, it's a note that you need to
Junio C Hamano235a91e2006-01-07 01:13:581316"git-update-index" it to make the index be in sync.</td>
Junio C Hamano1a4e8412005-12-27 08:17:231317</tr></table>
1318</div>
1319<div class="admonitionblock">
1320<table><tr>
1321<td class="icon">
1322<div class="title">Note</div>
1323</td>
1324<td class="content">You can have a mixture of files show up as "has been updated"
1325and "is still dirty in the working directory" together. You can always
1326tell which file is in which state, since the "has been updated" ones
1327show a valid sha1, and the "not in sync with the index" ones will
1328always have the special all-zero sha1.</td>
1329</tr></table>
1330</div>
1331</div>
1332<h2>Author</h2>
1333<div class="sectionbody">
1334<p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>
1335</div>
1336<h2>Documentation</h2>
1337<div class="sectionbody">
1338<p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
1339</div>
1340<h2>GIT</h2>
1341<div class="sectionbody">
1342<p>Part of the <a href="git.html">git(7)</a> suite</p>
1343</div>
1344<div id="footer">
1345<div id="footer-text">
Junio C Hamano35738e82008-01-07 07:55:461346Last updated 07-Jan-2008 07:50:13 UTC
Junio C Hamano1a4e8412005-12-27 08:17:231347</div>
1348</div>
1349</body>
1350</html>