1GIT-DIFF-INDEX(1)                 Git Manual                 GIT-DIFF-INDEX(1)
2
3
4

NAME

6       git-diff-index - Compares content and mode of blobs between the index
7       and repository
8

SYNOPSIS

10       git-diff-index [-m] [--cached] [<common diff options>] <tree-ish>
11       [<path>...]
12

DESCRIPTION

14       Compares the content and mode of the blobs found via a tree object with
15       the content of the current index and, optionally ignoring the stat
16       state of the file on disk. When paths are specified, compares only
17       those named paths. Otherwise all entries in the index are compared.
18

OPTIONS

20       -p
21           Generate patch (see section on generating patches)
22
23       -u
24           Synonym for "-p".
25
26       -U<n>
27           Shorthand for "--unified=<n>".
28
29       --unified=<n>
30           Generate diffs with <n> lines of context instead of the usual
31           three. Implies "-p".
32
33       --raw
34           Generate the raw format.
35
36       --patch-with-raw
37           Synonym for "-p --raw".
38
39       --stat[=width[,name-width]]
40           Generate a diffstat. You can override the default output width for
41           80-column terminal by "--stat=width". The width of the filename
42           part can be controlled by giving another width to it separated by a
43           comma.
44
45       --numstat
46           Similar to --stat, but shows number of added and deleted lines in
47           decimal notation and pathname without abbreviation, to make it more
48           machine friendly. For binary files, outputs two - instead of saying
49           0 0.
50
51       --shortstat
52           Output only the last line of the --stat format containing total
53           number of modified files, as well as number of added and deleted
54           lines.
55
56       --summary
57           Output a condensed summary of extended header information such as
58           creations, renames and mode changes.
59
60       --patch-with-stat
61           Synonym for "-p --stat".
62
63       -z
64           NUL-line termination on output. This affects the --raw output field
65           terminator. Also output from commands such as "git-log" will be
66           delimited with NUL between commits.
67
68       --name-only
69           Show only names of changed files.
70
71       --name-status
72           Show only names and status of changed files.
73
74       --color
75           Show colored diff.
76
77       --no-color
78           Turn off colored diff, even when the configuration file gives the
79           default to color output.
80
81       --color-words
82           Show colored word diff, i.e. color words which have changed.
83
84       --no-renames
85           Turn off rename detection, even when the configuration file gives
86           the default to do so.
87
88       --check
89           Warn if changes introduce trailing whitespace or an indent that
90           uses a space before a tab.
91
92       --full-index
93           Instead of the first handful characters, show full object name of
94           pre- and post-image blob on the "index" line when generating a
95           patch format output.
96
97       --binary
98           In addition to --full-index, output "binary diff" that can be
99           applied with "git apply".
100
101       --abbrev[=<n>]
102           Instead of showing the full 40-byte hexadecimal object name in
103           diff-raw format output and diff-tree header lines, show only
104           handful hexdigits prefix. This is independent of --full-index
105           option above, which controls the diff-patch output format. Non
106           default number of digits can be specified with --abbrev=<n>.
107
108       -B
109           Break complete rewrite changes into pairs of delete and create.
110
111       -M
112           Detect renames.
113
114       -C
115           Detect copies as well as renames. See also --find-copies-harder.
116
117       --diff-filter=[ACDMRTUXB*]
118           Select only files that are Added (A), Copied (C), Deleted (D),
119           Modified (M), Renamed (R), have their type (mode) changed (T), are
120           Unmerged (U), are Unknown (X), or have had their pairing Broken
121           (B). Any combination of the filter characters may be used. When *
122           (All-or-none) is added to the combination, all paths are selected
123           if there is any file that matches other criteria in the comparison;
124           if there is no file that matches other criteria, nothing is
125           selected.
126
127       --find-copies-harder
128           For performance reasons, by default, -C option finds copies only if
129           the original file of the copy was modified in the same changeset.
130           This flag makes the command inspect unmodified files as candidates
131           for the source of copy. This is a very expensive operation for
132           large projects, so use it with caution. Giving more than one -C
133           option has the same effect.
134
135       -l<num>
136           -M and -C options require O(n^2) processing time where n is the
137           number of potential rename/copy targets. This option prevents
138           rename/copy detection from running if the number of rename/copy
139           targets exceeds the specified number.
140
141       -S<string>
142           Look for differences that contain the change in <string>.
143
144       --pickaxe-all
145           When -S finds a change, show all the changes in that changeset, not
146           just the files that contain the change in <string>.
147
148       --pickaxe-regex
149           Make the <string> not a plain string but an extended POSIX regex to
150           match.
151
152       -O<orderfile>
153           Output the patch in the order specified in the <orderfile>, which
154           has one shell glob pattern per line.
155
156       -R
157           Swap two inputs; that is, show differences from index or on-disk
158           file to tree contents.
159
160       --text
161           Treat all files as text.
162
163       -a
164           Shorthand for "--text".
165
166       --ignore-space-at-eol
167           Ignore changes in white spaces at EOL.
168
169       --ignore-space-change
170           Ignore changes in amount of white space. This ignores white space
171           at line end, and consider all other sequences of one or more white
172           space characters to be equivalent.
173
174       -b
175           Shorthand for "--ignore-space-change".
176
177       --ignore-all-space
178           Ignore white space when comparing lines. This ignores difference
179           even if one line has white space where the other line has none.
180
181       -w
182           Shorthand for "--ignore-all-space".
183
184       --exit-code
185           Make the program exit with codes similar to diff(1). That is, it
186           exits with 1 if there were differences and 0 means no differences.
187
188       --quiet
189           Disable all output of the program. Implies --exit-code.
190
191       --ext-diff
192           Allow an external diff helper to be executed. If you set an
193           external diff driver with gitlink:gitattributes(5), you need to use
194           this option with gitlink:git-log(1) and friends.
195
196       --no-ext-diff
197           Disallow external diff drivers.
198       For more detailed explanation on these common options, see also
199       diffcore documentation[1].
200
201       <tree-ish>
202           The id of a tree object to diff against.
203
204       --cached
205           do not consider the on-disk file at all
206
207       -m
208           By default, files recorded in the index but not checked out are
209           reported as deleted. This flag makes "git-diff-index" say that all
210           non-checked-out files are up to date.
211

OUTPUT FORMAT

213       The output format from "git-diff-index", "git-diff-tree" and
214       "git-diff-files" are very similar.
215
216       These commands all compare two sets of things; what is compared
217       differs:
218
219       git-diff-index <tree-ish>
220           compares the <tree-ish> and the files on the filesystem.
221
222       git-diff-index --cached <tree-ish>
223           compares the <tree-ish> and the index.
224
225       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
226           compares the trees named by the two arguments.
227
228       git-diff-files [<pattern>...]
229           compares the index and the files on the filesystem.
230       An output line is formatted this way:
231
232
233
234           in-place edit  :100644 100644 bcd1234... 0123456... M file0
235           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
236           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
237           create         :000000 100644 0000000... 1234567... A file4
238           delete         :100644 000000 1234567... 0000000... D file5
239           unmerged       :000000 000000 0000000... 0000000... U file6
240
241       That is, from the left to the right:
242
243
244        1.  a colon.
245
246        2.  mode for "src"; 000000 if creation or unmerged.
247
248        3.  a space.
249
250        4.  mode for "dst"; 000000 if deletion or unmerged.
251
252        5.  a space.
253
254        6.  sha1 for "src"; 0{40} if creation or unmerged.
255
256        7.  a space.
257
258        8.  sha1 for "dst"; 0{40} if creation, unmerged or "look at work
259           tree".
260
261        9.  a space.
262
263       10.  status, followed by optional "score" number.
264
265       11.  a tab or a NUL when -z option is used.
266
267       12.  path for "src"
268
269       13.  a tab or a NUL when -z option is used; only exists for C or R.
270
271       14.  path for "dst"; only exists for C or R.
272
273       15.  an LF or a NUL when -z option is used, to terminate the record.
274       <sha1> is shown as all 0´s if a file is new on the filesystem and it is
275       out of sync with the index.
276
277       Example:
278
279
280
281           :100644 100644 5be4a4...... 000000...... M file.c
282
283       When -z option is not used, TAB, LF, and backslash characters in
284       pathnames are represented as \t, \n, and \\, respectively.
285

DIFF FORMAT FOR MERGES

287       "git-diff-tree" and "git-diff-files" can take -c or --cc option to
288       generate diff output also for merge commits. The output differs from
289       the format described above in the following way:
290
291
292        1.  there is a colon for each parent
293
294        2.  there are more "src" modes and "src" sha1
295
296        3.  status is concatenated status characters for each parent
297
298        4.  no optional "score" number
299
300        5.  single path, only for "dst"
301       Example:
302
303
304
305           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
306
307       Note that combined diff lists only files which were modified from all
308       parents.
309

GENERATING PATCHES WITH -P

311       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
312       with a -p option, they do not produce the output described above;
313       instead they produce a patch file. You can customize the creation of
314       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
315       environment variables.
316
317       What the -p option produces is slightly different from the traditional
318       diff format.
319
320
321        1.  It is preceded with a "git diff" header, that looks like this:
322
323
324               diff --git a/file1 b/file2
325           The a/ and b/ filenames are the same unless rename/copy is
326           involved. Especially, even for a creation or a deletion, /dev/null
327           is not used in place of a/ or b/ filenames.
328
329           When rename/copy is involved, file1 and file2 show the name of the
330           source file of the rename/copy and the name of the file that
331           rename/copy produces, respectively.
332
333        2.  It is followed by one or more extended header lines:
334
335
336               old mode <mode>
337               new mode <mode>
338               deleted file mode <mode>
339               new file mode <mode>
340               copy from <path>
341               copy to <path>
342               rename from <path>
343               rename to <path>
344               similarity index <number>
345               dissimilarity index <number>
346               index <hash>..<hash> <mode>
347
348        3.  TAB, LF, double quote and backslash characters in pathnames are
349           represented as \t, \n, \" and \\, respectively. If there is need
350           for such substitution then the whole pathname is put in double
351           quotes.
352       The similarity index is the percentage of unchanged lines, and the
353       dissimilarity index is the percentage of changed lines. It is a rounded
354       down integer, followed by a percent sign. The similarity index value of
355       100% is thus reserved for two equal files, while 100% dissimilarity
356       means that no line from the old file made it into the new one.
357

COMBINED DIFF FORMAT

359       git-diff-tree and git-diff-files can take -c or --cc option to produce
360       combined diff, which looks like this:
361
362
363
364           diff --combined describe.c
365           index fabadb8,cc95eb0..4866510
366           --- a/describe.c
367           +++ b/describe.c
368           @@@ -98,20 -98,12 +98,20 @@@
369                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
370             }
371
372           - static void describe(char *arg)
373            -static void describe(struct commit *cmit, int last_one)
374           ++static void describe(char *arg, int last_one)
375             {
376            +      unsigned char sha1[20];
377            +      struct commit *cmit;
378                   struct commit_list *list;
379                   static int initialized = 0;
380                   struct commit_name *n;
381
382            +      if (get_sha1(arg, sha1) < 0)
383            +              usage(describe_usage);
384            +      cmit = lookup_commit_reference(sha1);
385            +      if (!cmit)
386            +              usage(describe_usage);
387            +
388                   if (!initialized) {
389                           initialized = 1;
390                           for_each_ref(get_name);
391
392
393        1.  It is preceded with a "git diff" header, that looks like this
394           (when -c option is used):
395
396
397               diff --combined file
398           or like this (when --cc option is used):
399
400
401               diff --c file
402
403        2.  It is followed by one or more extended header lines (this example
404           shows a merge with two parents):
405
406
407               index <hash>,<hash>..<hash>
408               mode <mode>,<mode>..<mode>
409               new file mode <mode>
410               deleted file mode <mode>,<mode>
411           The mode <mode>,<mode>..<mode> line appears only if at least one of
412           the <mode> is different from the rest. Extended headers with
413           information about detected contents movement (renames and copying
414           detection) are designed to work with diff of two <tree-ish> and are
415           not used by combined diff format.
416
417        3.  It is followed by two-line from-file/to-file header
418
419
420               --- a/file
421               +++ b/file
422           Similar to two-line header for traditional unified diff format,
423           /dev/null is used to signal created or deleted files.
424
425        4.  Chunk header format is modified to prevent people from
426           accidentally feeding it to patch -p1. Combined diff format was
427           created for review of merge commit changes, and was not meant for
428           apply. The change is similar to the change in the extended index
429           header:
430
431
432               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
433           There are (number of parents + 1) @ characters in the chunk header
434           for combined diff format.
435       Unlike the traditional unified diff format, which shows two files A and
436       B with a single column that has - (minus — appears in A but removed in
437       B), + (plus — missing in A but added to B), or " " (space — unchanged)
438       prefix, this format compares two or more files file1, file2,... with
439       one file X, and shows how X differs from each of fileN. One column for
440       each of fileN is prepended to the output line to note how X´s line is
441       different from it.
442
443       A - character in the column N means that the line appears in fileN but
444       it does not appear in the result. A + character in the column N means
445       that the line appears in the last file, and fileN does not have that
446       line (in other words, the line was added, from the point of view of
447       that parent).
448
449       In the above example output, the function signature was changed from
450       both files (hence two - removals from both file1 and file2, plus + to
451       mean one line that was added does not appear in either file1 nor
452       file2). Also two other lines are the same from file1 but do not appear
453       in file2 (hence prefixed with ).
454
455       When shown by git diff-tree -c, it compares the parents of a merge
456       commit with the merge result (i.e. file1..fileN are the parents). When
457       shown by git diff-files -c, it compares the two unresolved merge
458       parents with the working tree file (i.e. file1 is stage 2 aka "our
459       version", file2 is stage 3 aka "their version").
460

OPERATING MODES

462       You can choose whether you want to trust the index file entirely (using
463       the --cached flag) or ask the diff logic to show any files that don´t
464       match the stat state as being "tentatively changed". Both of these
465       operations are very useful indeed.
466

CACHED MODE

468       If --cached is specified, it allows you to ask:
469
470
471           show me the differences between HEAD and the current index
472           contents (the ones I´d write with a "git-write-tree")
473       For example, let´s say that you have worked on your working directory,
474       updated some files in the index and are ready to commit. You want to
475       see exactly what you are going to commit, without having to write a new
476       tree object and compare it that way, and to do that, you just do
477
478
479           git-diff-index --cached HEAD
480       Example: let´s say I had renamed commit.c to git-commit.c, and I had
481       done an "git-update-index" to make that effective in the index file.
482       "git-diff-files" wouldn´t show anything at all, since the index file
483       matches my working directory. But doing a "git-diff-index" does:
484
485
486           torvalds@ppc970:~/git> git-diff-index --cached HEAD
487           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
488           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
489       You can see easily that the above is a rename.
490
491       In fact, "git-diff-index --cached" should always be entirely equivalent
492       to actually doing a "git-write-tree" and comparing that. Except this
493       one is much nicer for the case where you just want to check where you
494       are.
495
496       So doing a "git-diff-index --cached" is basically very useful when you
497       are asking yourself "what have I already marked for being committed,
498       and what´s the difference to a previous tree".
499

NON-CACHED MODE

501       The "non-cached" mode takes a different approach, and is potentially
502       the more useful of the two in that what it does can´t be emulated with
503       a "git-write-tree" + "git-diff-tree". Thus that´s the default mode. The
504       non-cached version asks the question:
505
506
507           show me the differences between HEAD and the currently checked out
508           tree - index contents _and_ files that aren´t up-to-date
509       which is obviously a very useful question too, since that tells you
510       what you could commit. Again, the output matches the "git-diff-tree -r"
511       output to a tee, but with a twist.
512
513       The twist is that if some file doesn´t match the index, we don´t have a
514       backing store thing for it, and we use the magic "all-zero" sha1 to
515       show that. So let´s say that you have edited kernel/sched.c, but have
516       not actually done a "git-update-index" on it yet - there is no "object"
517       associated with the new state, and you get:
518
519
520           torvalds@ppc970:~/v2.6/linux> git-diff-index HEAD
521           *100644->100664 blob    7476bb......->000000......      kernel/sched.c
522       i.e., it shows that the tree has changed, and that kernel/sched.c has
523       is not up-to-date and may contain new stuff. The all-zero sha1 means
524       that to get the real diff, you need to look at the object in the
525       working directory directly rather than do an object-to-object diff.
526
527       Note
528       As with other commands of this type, "git-diff-index" does not actually
529       look at the contents of the file at all. So maybe kernel/sched.c hasn´t
530       actually changed, and it´s just that you touched it. In either case,
531       it´s a note that you need to "git-update-index" it to make the index be
532       in sync.
533
534
535       Note
536       You can have a mixture of files show up as "has been updated" and "is
537       still dirty in the working directory" together. You can always tell
538       which file is in which state, since the "has been updated" ones show a
539       valid sha1, and the "not in sync with the index" ones will always have
540       the special all-zero sha1.
541
542

AUTHOR

544       Written by Linus Torvalds <torvalds@osdl.org>
545

DOCUMENTATION

547       Documentation by David Greaves, Junio C Hamano and the git-list
548       <git@vger.kernel.org>.
549

GIT

551       Part of the git(7) suite
552

NOTES

554        1. diffcore documentation
555           diffcore.html
556
557
558
559Git 1.5.3.3                       10/09/2007                 GIT-DIFF-INDEX(1)
Impressum