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, -u
21           Generate patch (see section on generating patches).
22
23       -U<n>, --unified=<n>
24           Generate diffs with <n> lines of context instead of the usual
25           three. Implies -p.
26
27       --raw
28           Generate the raw format. This is the default.
29
30       --patch-with-raw
31           Synonym for -p --raw.
32
33       --patience
34           Generate a diff using the "patience diff" algorithm.
35
36       --stat[=width[,name-width]]
37           Generate a diffstat. You can override the default output width for
38           80-column terminal by --stat=width. The width of the filename part
39           can be controlled by giving another width to it separated by a
40           comma.
41
42       --numstat
43           Similar to --stat, but shows number of added and deleted lines in
44           decimal notation and pathname without abbreviation, to make it more
45           machine friendly. For binary files, outputs two - instead of saying
46           0 0.
47
48       --shortstat
49           Output only the last line of the --stat format containing total
50           number of modified files, as well as number of added and deleted
51           lines.
52
53       --dirstat[=limit]
54           Output the distribution of relative amount of changes (number of
55           lines added or removed) for each sub-directory. Directories with
56           changes below a cut-off percent (3% by default) are not shown. The
57           cut-off percent can be set with --dirstat=limit. Changes in a child
58           directory is not counted for the parent directory, unless
59           --cumulative is used.
60
61       --dirstat-by-file[=limit]
62           Same as --dirstat, but counts changed files instead of lines.
63
64       --summary
65           Output a condensed summary of extended header information such as
66           creations, renames and mode changes.
67
68       --patch-with-stat
69           Synonym for -p --stat.
70
71       -z
72           When --raw, --numstat, --name-only or --name-status has been given,
73           do not munge pathnames and use NULs as output field terminators.
74
75           Without this option, each pathname output will have TAB, LF, double
76           quotes, and backslash characters replaced with \t, \n, \", and \\,
77           respectively, and the pathname will be enclosed in double quotes if
78           any of those replacements occurred.
79
80       --name-only
81           Show only names of changed files.
82
83       --name-status
84           Show only names and status of changed files. See the description of
85           the --diff-filter option on what the status letters mean.
86
87       --submodule[=<format>]
88           Chose the output format for submodule differences. <format> can be
89           one of short and log.  short just shows pairs of commit names, this
90           format is used when this option is not given.  log is the default
91           value for this option and lists the commits in that commit range
92           like the summary option of git-submodule(1) does.
93
94       --color[=<when>]
95           Show colored diff. The value must be always (the default), never,
96           or auto.
97
98       --no-color
99           Turn off colored diff, even when the configuration file gives the
100           default to color output. Same as --color=never.
101
102       --color-words[=<regex>]
103           Show colored word diff, i.e., color words which have changed. By
104           default, words are separated by whitespace.
105
106           When a <regex> is specified, every non-overlapping match of the
107           <regex> is considered a word. Anything between these matches is
108           considered whitespace and ignored(!) for the purposes of finding
109           differences. You may want to append |[^[:space:]] to your regular
110           expression to make sure that it matches all non-whitespace
111           characters. A match that contains a newline is silently
112           truncated(!) at the newline.
113
114           The regex can also be set via a diff driver or configuration
115           option, see gitattributes(1) or git-config(1). Giving it explicitly
116           overrides any diff driver or configuration setting. Diff drivers
117           override configuration settings.
118
119       --no-renames
120           Turn off rename detection, even when the configuration file gives
121           the default to do so.
122
123       --check
124           Warn if changes introduce trailing whitespace or an indent that
125           uses a space before a tab. Exits with non-zero status if problems
126           are found. Not compatible with --exit-code.
127
128       --full-index
129           Instead of the first handful of characters, show the full pre- and
130           post-image blob object names on the "index" line when generating
131           patch format output.
132
133       --binary
134           In addition to --full-index, output a binary diff that can be
135           applied with git-apply.
136
137       --abbrev[=<n>]
138           Instead of showing the full 40-byte hexadecimal object name in
139           diff-raw format output and diff-tree header lines, show only a
140           partial prefix. This is independent of the --full-index option
141           above, which controls the diff-patch output format. Non default
142           number of digits can be specified with --abbrev=<n>.
143
144       -B
145           Break complete rewrite changes into pairs of delete and create.
146
147       -M
148           Detect renames.
149
150       -C
151           Detect copies as well as renames. See also --find-copies-harder.
152
153       --diff-filter=[ACDMRTUXB*]
154           Select only files that are Added (A), Copied (C), Deleted (D),
155           Modified (M), Renamed (R), have their type (i.e. regular file,
156           symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
157           (X), or have had their pairing Broken (B). Any combination of the
158           filter characters may be used. When * (All-or-none) is added to the
159           combination, all paths are selected if there is any file that
160           matches other criteria in the comparison; if there is no file that
161           matches other criteria, nothing is selected.
162
163       --find-copies-harder
164           For performance reasons, by default, -C option finds copies only if
165           the original file of the copy was modified in the same changeset.
166           This flag makes the command inspect unmodified files as candidates
167           for the source of copy. This is a very expensive operation for
168           large projects, so use it with caution. Giving more than one -C
169           option has the same effect.
170
171       -l<num>
172           The -M and -C options require O(n^2) processing time where n is the
173           number of potential rename/copy targets. This option prevents
174           rename/copy detection from running if the number of rename/copy
175           targets exceeds the specified number.
176
177       -S<string>
178           Look for differences that introduce or remove an instance of
179           <string>. Note that this is different than the string simply
180           appearing in diff output; see the pickaxe entry in gitdiffcore(7)
181           for more details.
182
183       --pickaxe-all
184           When -S finds a change, show all the changes in that changeset, not
185           just the files that contain the change in <string>.
186
187       --pickaxe-regex
188           Make the <string> not a plain string but an extended POSIX regex to
189           match.
190
191       -O<orderfile>
192           Output the patch in the order specified in the <orderfile>, which
193           has one shell glob pattern per line.
194
195       -R
196           Swap two inputs; that is, show differences from index or on-disk
197           file to tree contents.
198
199       --relative[=<path>]
200           When run from a subdirectory of the project, it can be told to
201           exclude changes outside the directory and show pathnames relative
202           to it with this option. When you are not in a subdirectory (e.g. in
203           a bare repository), you can name which subdirectory to make the
204           output relative to by giving a <path> as an argument.
205
206       -a, --text
207           Treat all files as text.
208
209       --ignore-space-at-eol
210           Ignore changes in whitespace at EOL.
211
212       -b, --ignore-space-change
213           Ignore changes in amount of whitespace. This ignores whitespace at
214           line end, and considers all other sequences of one or more
215           whitespace characters to be equivalent.
216
217       -w, --ignore-all-space
218           Ignore whitespace when comparing lines. This ignores differences
219           even if one line has whitespace where the other line has none.
220
221       --inter-hunk-context=<lines>
222           Show the context between diff hunks, up to the specified number of
223           lines, thereby fusing hunks that are close to each other.
224
225       --exit-code
226           Make the program exit with codes similar to diff(1). That is, it
227           exits with 1 if there were differences and 0 means no differences.
228
229       --quiet
230           Disable all output of the program. Implies --exit-code.
231
232       --ext-diff
233           Allow an external diff helper to be executed. If you set an
234           external diff driver with gitattributes(5), you need to use this
235           option with git-log(1) and friends.
236
237       --no-ext-diff
238           Disallow external diff drivers.
239
240       --ignore-submodules
241           Ignore changes to submodules in the diff generation.
242
243       --src-prefix=<prefix>
244           Show the given source prefix instead of "a/".
245
246       --dst-prefix=<prefix>
247           Show the given destination prefix instead of "b/".
248
249       --no-prefix
250           Do not show any source or destination prefix.
251
252       For more detailed explanation on these common options, see also
253       gitdiffcore(7).
254
255       <tree-ish>
256           The id of a tree object to diff against.
257
258       --cached
259           do not consider the on-disk file at all
260
261       -m
262           By default, files recorded in the index but not checked out are
263           reported as deleted. This flag makes git diff-index say that all
264           non-checked-out files are up to date.
265

RAW OUTPUT FORMAT

267       The raw output format from "git-diff-index", "git-diff-tree",
268       "git-diff-files" and "git diff --raw" are very similar.
269
270       These commands all compare two sets of things; what is compared
271       differs:
272
273       git-diff-index <tree-ish>
274           compares the <tree-ish> and the files on the filesystem.
275
276       git-diff-index --cached <tree-ish>
277           compares the <tree-ish> and the index.
278
279       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
280           compares the trees named by the two arguments.
281
282       git-diff-files [<pattern>...]
283           compares the index and the files on the filesystem.
284
285       The "git-diff-tree" command begins its output by printing the hash of
286       what is being compared. After that, all the commands print one output
287       line per changed file.
288
289       An output line is formatted this way:
290
291           in-place edit  :100644 100644 bcd1234... 0123456... M file0
292           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
293           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
294           create         :000000 100644 0000000... 1234567... A file4
295           delete         :100644 000000 1234567... 0000000... D file5
296           unmerged       :000000 000000 0000000... 0000000... U file6
297
298
299       That is, from the left to the right:
300
301        1. a colon.
302
303        2. mode for "src"; 000000 if creation or unmerged.
304
305        3. a space.
306
307        4. mode for "dst"; 000000 if deletion or unmerged.
308
309        5. a space.
310
311        6. sha1 for "src"; 0{40} if creation or unmerged.
312
313        7. a space.
314
315        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
316
317        9. a space.
318
319       10. status, followed by optional "score" number.
320
321       11. a tab or a NUL when -z option is used.
322
323       12. path for "src"
324
325       13. a tab or a NUL when -z option is used; only exists for C or R.
326
327       14. path for "dst"; only exists for C or R.
328
329       15. an LF or a NUL when -z option is used, to terminate the record.
330
331       Possible status letters are:
332
333       ·   A: addition of a file
334
335       ·   C: copy of a file into a new one
336
337       ·   D: deletion of a file
338
339       ·   M: modification of the contents or mode of a file
340
341       ·   R: renaming of a file
342
343       ·   T: change in the type of the file
344
345       ·   U: file is unmerged (you must complete the merge before it can be
346           committed)
347
348       ·   X: "unknown" change type (most probably a bug, please report it)
349
350       Status letters C and R are always followed by a score (denoting the
351       percentage of similarity between the source and target of the move or
352       copy), and are the only ones to be so.
353
354       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
355       out of sync with the index.
356
357       Example:
358
359           :100644 100644 5be4a4...... 000000...... M file.c
360
361
362       When -z option is not used, TAB, LF, and backslash characters in
363       pathnames are represented as \t, \n, and \\, respectively.
364

DIFF FORMAT FOR MERGES

366       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
367       --cc option to generate diff output also for merge commits. The output
368       differs from the format described above in the following way:
369
370        1. there is a colon for each parent
371
372        2. there are more "src" modes and "src" sha1
373
374        3. status is concatenated status characters for each parent
375
376        4. no optional "score" number
377
378        5. single path, only for "dst"
379
380       Example:
381
382           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
383
384
385       Note that combined diff lists only files which were modified from all
386       parents.
387

GENERATING PATCHES WITH -P

389       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
390       with a -p option, "git diff" without the --raw option, or "git log"
391       with the "-p" option, they do not produce the output described above;
392       instead they produce a patch file. You can customize the creation of
393       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
394       environment variables.
395
396       What the -p option produces is slightly different from the traditional
397       diff format.
398
399        1. It is preceded with a "git diff" header, that looks like this:
400
401               diff --git a/file1 b/file2
402
403           The a/ and b/ filenames are the same unless rename/copy is
404           involved. Especially, even for a creation or a deletion, /dev/null
405           is not used in place of a/ or b/ filenames.
406
407           When rename/copy is involved, file1 and file2 show the name of the
408           source file of the rename/copy and the name of the file that
409           rename/copy produces, respectively.
410
411        2. It is followed by one or more extended header lines:
412
413               old mode <mode>
414               new mode <mode>
415               deleted file mode <mode>
416               new file mode <mode>
417               copy from <path>
418               copy to <path>
419               rename from <path>
420               rename to <path>
421               similarity index <number>
422               dissimilarity index <number>
423               index <hash>..<hash> <mode>
424
425        3. TAB, LF, double quote and backslash characters in pathnames are
426           represented as \t, \n, \" and \\, respectively. If there is need
427           for such substitution then the whole pathname is put in double
428           quotes.
429
430       The similarity index is the percentage of unchanged lines, and the
431       dissimilarity index is the percentage of changed lines. It is a rounded
432       down integer, followed by a percent sign. The similarity index value of
433       100% is thus reserved for two equal files, while 100% dissimilarity
434       means that no line from the old file made it into the new one.
435

COMBINED DIFF FORMAT

437       "git-diff-tree", "git-diff-files" and "git-diff" can take -c or --cc
438       option to produce combined diff. For showing a merge commit with "git
439       log -p", this is the default format; you can force showing full diff
440       with the -m option. A combined diff format looks like this:
441
442           diff --combined describe.c
443           index fabadb8,cc95eb0..4866510
444           --- a/describe.c
445           +++ b/describe.c
446           @@@ -98,20 -98,12 +98,20 @@@
447                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
448             }
449
450           - static void describe(char *arg)
451            -static void describe(struct commit *cmit, int last_one)
452           ++static void describe(char *arg, int last_one)
453             {
454            +      unsigned char sha1[20];
455            +      struct commit *cmit;
456                   struct commit_list *list;
457                   static int initialized = 0;
458                   struct commit_name *n;
459
460            +      if (get_sha1(arg, sha1) < 0)
461            +              usage(describe_usage);
462            +      cmit = lookup_commit_reference(sha1);
463            +      if (!cmit)
464            +              usage(describe_usage);
465            +
466                   if (!initialized) {
467                           initialized = 1;
468                           for_each_ref(get_name);
469
470
471
472        1. It is preceded with a "git diff" header, that looks like this (when
473           -c option is used):
474
475               diff --combined file
476
477           or like this (when --cc option is used):
478
479               diff --cc file
480
481        2. It is followed by one or more extended header lines (this example
482           shows a merge with two parents):
483
484               index <hash>,<hash>..<hash>
485               mode <mode>,<mode>..<mode>
486               new file mode <mode>
487               deleted file mode <mode>,<mode>
488
489           The mode <mode>,<mode>..<mode> line appears only if at least one of
490           the <mode> is different from the rest. Extended headers with
491           information about detected contents movement (renames and copying
492           detection) are designed to work with diff of two <tree-ish> and are
493           not used by combined diff format.
494
495        3. It is followed by two-line from-file/to-file header
496
497               --- a/file
498               +++ b/file
499
500           Similar to two-line header for traditional unified diff format,
501           /dev/null is used to signal created or deleted files.
502
503        4. Chunk header format is modified to prevent people from accidentally
504           feeding it to patch -p1. Combined diff format was created for
505           review of merge commit changes, and was not meant for apply. The
506           change is similar to the change in the extended index header:
507
508               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
509
510           There are (number of parents + 1) @ characters in the chunk header
511           for combined diff format.
512
513       Unlike the traditional unified diff format, which shows two files A and
514       B with a single column that has - (minus — appears in A but removed in
515       B), + (plus — missing in A but added to B), or " " (space — unchanged)
516       prefix, this format compares two or more files file1, file2,... with
517       one file X, and shows how X differs from each of fileN. One column for
518       each of fileN is prepended to the output line to note how X’s line is
519       different from it.
520
521       A - character in the column N means that the line appears in fileN but
522       it does not appear in the result. A + character in the column N means
523       that the line appears in the result, and fileN does not have that line
524       (in other words, the line was added, from the point of view of that
525       parent).
526
527       In the above example output, the function signature was changed from
528       both files (hence two - removals from both file1 and file2, plus ++ to
529       mean one line that was added does not appear in either file1 nor
530       file2). Also eight other lines are the same from file1 but do not
531       appear in file2 (hence prefixed with +).
532
533       When shown by git diff-tree -c, it compares the parents of a merge
534       commit with the merge result (i.e. file1..fileN are the parents). When
535       shown by git diff-files -c, it compares the two unresolved merge
536       parents with the working tree file (i.e. file1 is stage 2 aka "our
537       version", file2 is stage 3 aka "their version").
538

OTHER DIFF FORMATS

540       The --summary option describes newly added, deleted, renamed and copied
541       files. The --stat option adds diffstat(1) graph to the output. These
542       options can be combined with other options, such as -p, and are meant
543       for human consumption.
544
545       When showing a change that involves a rename or a copy, --stat output
546       formats the pathnames compactly by combining common prefix and suffix
547       of the pathnames. For example, a change that moves arch/i386/Makefile
548       to arch/x86/Makefile while modifying 4 lines will be shown like this:
549
550           arch/{i386 => x86}/Makefile    |   4 +--
551
552
553       The --numstat option gives the diffstat(1) information but is designed
554       for easier machine consumption. An entry in --numstat output looks like
555       this:
556
557           1       2       README
558           3       1       arch/{i386 => x86}/Makefile
559
560
561       That is, from left to right:
562
563        1. the number of added lines;
564
565        2. a tab;
566
567        3. the number of deleted lines;
568
569        4. a tab;
570
571        5. pathname (possibly with rename/copy information);
572
573        6. a newline.
574
575       When -z output option is in effect, the output is formatted this way:
576
577           1       2       README NUL
578           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
579
580
581       That is:
582
583        1. the number of added lines;
584
585        2. a tab;
586
587        3. the number of deleted lines;
588
589        4. a tab;
590
591        5. a NUL (only exists if renamed/copied);
592
593        6. pathname in preimage;
594
595        7. a NUL (only exists if renamed/copied);
596
597        8. pathname in postimage (only exists if renamed/copied);
598
599        9. a NUL.
600
601       The extra NUL before the preimage path in renamed case is to allow
602       scripts that read the output to tell if the current record being read
603       is a single-path record or a rename/copy record without reading ahead.
604       After reading added and deleted lines, reading up to NUL would yield
605       the pathname, but if that is NUL, the record will show two paths.
606

OPERATING MODES

608       You can choose whether you want to trust the index file entirely (using
609       the --cached flag) or ask the diff logic to show any files that don’t
610       match the stat state as being "tentatively changed". Both of these
611       operations are very useful indeed.
612

CACHED MODE

614       If --cached is specified, it allows you to ask:
615
616           show me the differences between HEAD and the current index
617           contents (the ones I´d write using ´git write-tree´)
618
619       For example, let’s say that you have worked on your working directory,
620       updated some files in the index and are ready to commit. You want to
621       see exactly what you are going to commit, without having to write a new
622       tree object and compare it that way, and to do that, you just do
623
624           git diff-index --cached HEAD
625
626       Example: let’s say I had renamed commit.c to git-commit.c, and I had
627       done an update-index to make that effective in the index file. git
628       diff-files wouldn’t show anything at all, since the index file matches
629       my working directory. But doing a git diff-index does:
630
631           torvalds@ppc970:~/git> git diff-index --cached HEAD
632           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
633           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
634
635       You can see easily that the above is a rename.
636
637       In fact, git diff-index --cached should always be entirely equivalent
638       to actually doing a git write-tree and comparing that. Except this one
639       is much nicer for the case where you just want to check where you are.
640
641       So doing a git diff-index --cached is basically very useful when you
642       are asking yourself "what have I already marked for being committed,
643       and what’s the difference to a previous tree".
644

NON-CACHED MODE

646       The "non-cached" mode takes a different approach, and is potentially
647       the more useful of the two in that what it does can’t be emulated with
648       a git write-tree + git diff-tree. Thus that’s the default mode. The
649       non-cached version asks the question:
650
651           show me the differences between HEAD and the currently checked out
652           tree - index contents _and_ files that aren´t up-to-date
653
654       which is obviously a very useful question too, since that tells you
655       what you could commit. Again, the output matches the git diff-tree -r
656       output to a tee, but with a twist.
657
658       The twist is that if some file doesn’t match the index, we don’t have a
659       backing store thing for it, and we use the magic "all-zero" sha1 to
660       show that. So let’s say that you have edited kernel/sched.c, but have
661       not actually done a git update-index on it yet - there is no "object"
662       associated with the new state, and you get:
663
664           torvalds@ppc970:~/v2.6/linux> git diff-index HEAD
665           *100644->100664 blob    7476bb......->000000......      kernel/sched.c
666
667       i.e., it shows that the tree has changed, and that kernel/sched.c has
668       is not up-to-date and may contain new stuff. The all-zero sha1 means
669       that to get the real diff, you need to look at the object in the
670       working directory directly rather than do an object-to-object diff.
671
672           Note
673           As with other commands of this type, git diff-index does not
674           actually look at the contents of the file at all. So maybe
675           kernel/sched.c hasn’t actually changed, and it’s just that you
676           touched it. In either case, it’s a note that you need to git
677           update-index it to make the index be in sync.
678
679           Note
680           You can have a mixture of files show up as "has been updated" and
681           "is still dirty in the working directory" together. You can always
682           tell which file is in which state, since the "has been updated"
683           ones show a valid sha1, and the "not in sync with the index" ones
684           will always have the special all-zero sha1.
685

AUTHOR

687       Written by Linus Torvalds <torvalds@osdl.org[1]>
688

DOCUMENTATION

690       Documentation by David Greaves, Junio C Hamano and the git-list
691       <git@vger.kernel.org[2]>.
692

GIT

694       Part of the git(1) suite
695

NOTES

697        1. torvalds@osdl.org
698           mailto:torvalds@osdl.org
699
700        2. git@vger.kernel.org
701           mailto:git@vger.kernel.org
702
703
704
705Git 1.7.1                         08/16/2017                 GIT-DIFF-INDEX(1)
Impressum