1GIT-DIFF-INDEX(1) Git Manual GIT-DIFF-INDEX(1)
2
3
4
6 git-diff-index - Compares content and mode of blobs between the index
7 and repository
8
10 git diff-index [-m] [--cached] [<common diff options>] <tree-ish> [<path>...]
11
12
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
20 -p, -u, --patch
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 --minimal
34 Spend extra time to make sure the smallest possible diff is
35 produced.
36
37 --patience
38 Generate a diff using the "patience diff" algorithm.
39
40 --histogram
41 Generate a diff using the "histogram diff" algorithm.
42
43 --diff-algorithm={patience|minimal|histogram|myers}
44 Choose a diff algorithm. The variants are as follows:
45
46 default, myers
47 The basic greedy diff algorithm. Currently, this is the
48 default.
49
50 minimal
51 Spend extra time to make sure the smallest possible diff is
52 produced.
53
54 patience
55 Use "patience diff" algorithm when generating patches.
56
57 histogram
58 This algorithm extends the patience algorithm to "support
59 low-occurrence common elements".
60
61 For instance, if you configured diff.algorithm variable to a
62 non-default value and want to use the default one, then you have to
63 use --diff-algorithm=default option.
64
65 --stat[=<width>[,<name-width>[,<count>]]]
66 Generate a diffstat. By default, as much space as necessary will be
67 used for the filename part, and the rest for the graph part.
68 Maximum width defaults to terminal width, or 80 columns if not
69 connected to a terminal, and can be overridden by <width>. The
70 width of the filename part can be limited by giving another width
71 <name-width> after a comma. The width of the graph part can be
72 limited by using --stat-graph-width=<width> (affects all commands
73 generating a stat graph) or by setting diff.statGraphWidth=<width>
74 (does not affect git format-patch). By giving a third parameter
75 <count>, you can limit the output to the first <count> lines,
76 followed by ... if there are more.
77
78 These parameters can also be set individually with
79 --stat-width=<width>, --stat-name-width=<name-width> and
80 --stat-count=<count>.
81
82 --numstat
83 Similar to --stat, but shows number of added and deleted lines in
84 decimal notation and pathname without abbreviation, to make it more
85 machine friendly. For binary files, outputs two - instead of saying
86 0 0.
87
88 --shortstat
89 Output only the last line of the --stat format containing total
90 number of modified files, as well as number of added and deleted
91 lines.
92
93 --dirstat[=<param1,param2,...>]
94 Output the distribution of relative amount of changes for each
95 sub-directory. The behavior of --dirstat can be customized by
96 passing it a comma separated list of parameters. The defaults are
97 controlled by the diff.dirstat configuration variable (see git-
98 config(1)). The following parameters are available:
99
100 changes
101 Compute the dirstat numbers by counting the lines that have
102 been removed from the source, or added to the destination. This
103 ignores the amount of pure code movements within a file. In
104 other words, rearranging lines in a file is not counted as much
105 as other changes. This is the default behavior when no
106 parameter is given.
107
108 lines
109 Compute the dirstat numbers by doing the regular line-based
110 diff analysis, and summing the removed/added line counts. (For
111 binary files, count 64-byte chunks instead, since binary files
112 have no natural concept of lines). This is a more expensive
113 --dirstat behavior than the changes behavior, but it does count
114 rearranged lines within a file as much as other changes. The
115 resulting output is consistent with what you get from the other
116 --*stat options.
117
118 files
119 Compute the dirstat numbers by counting the number of files
120 changed. Each changed file counts equally in the dirstat
121 analysis. This is the computationally cheapest --dirstat
122 behavior, since it does not have to look at the file contents
123 at all.
124
125 cumulative
126 Count changes in a child directory for the parent directory as
127 well. Note that when using cumulative, the sum of the
128 percentages reported may exceed 100%. The default
129 (non-cumulative) behavior can be specified with the
130 noncumulative parameter.
131
132 <limit>
133 An integer parameter specifies a cut-off percent (3% by
134 default). Directories contributing less than this percentage of
135 the changes are not shown in the output.
136
137 Example: The following will count changed files, while ignoring
138 directories with less than 10% of the total amount of changed
139 files, and accumulating child directory counts in the parent
140 directories: --dirstat=files,10,cumulative.
141
142 --summary
143 Output a condensed summary of extended header information such as
144 creations, renames and mode changes.
145
146 --patch-with-stat
147 Synonym for -p --stat.
148
149 -z
150 When --raw, --numstat, --name-only or --name-status has been given,
151 do not munge pathnames and use NULs as output field terminators.
152
153 Without this option, each pathname output will have TAB, LF, double
154 quotes, and backslash characters replaced with \t, \n, \", and \\,
155 respectively, and the pathname will be enclosed in double quotes if
156 any of those replacements occurred.
157
158 --name-only
159 Show only names of changed files.
160
161 --name-status
162 Show only names and status of changed files. See the description of
163 the --diff-filter option on what the status letters mean.
164
165 --submodule[=<format>]
166 Specify how differences in submodules are shown. When --submodule
167 or --submodule=log is given, the log format is used. This format
168 lists the commits in the range like git-submodule(1)summary does.
169 Omitting the --submodule option or specifying --submodule=short,
170 uses the short format. This format just shows the names of the
171 commits at the beginning and end of the range. Can be tweaked via
172 the diff.submodule configuration variable.
173
174 --color[=<when>]
175 Show colored diff. --color (i.e. without =<when>) is the same as
176 --color=always. <when> can be one of always, never, or auto.
177
178 --no-color
179 Turn off colored diff. It is the same as --color=never.
180
181 --word-diff[=<mode>]
182 Show a word diff, using the <mode> to delimit changed words. By
183 default, words are delimited by whitespace; see --word-diff-regex
184 below. The <mode> defaults to plain, and must be one of:
185
186 color
187 Highlight changed words using only colors. Implies --color.
188
189 plain
190 Show words as [-removed-] and {+added+}. Makes no attempts to
191 escape the delimiters if they appear in the input, so the
192 output may be ambiguous.
193
194 porcelain
195 Use a special line-based format intended for script
196 consumption. Added/removed/unchanged runs are printed in the
197 usual unified diff format, starting with a +/-/` ` character at
198 the beginning of the line and extending to the end of the line.
199 Newlines in the input are represented by a tilde ~ on a line of
200 its own.
201
202 none
203 Disable word diff again.
204
205 Note that despite the name of the first mode, color is used to
206 highlight the changed parts in all modes if enabled.
207
208 --word-diff-regex=<regex>
209 Use <regex> to decide what a word is, instead of considering runs
210 of non-whitespace to be a word. Also implies --word-diff unless it
211 was already enabled.
212
213 Every non-overlapping match of the <regex> is considered a word.
214 Anything between these matches is considered whitespace and
215 ignored(!) for the purposes of finding differences. You may want to
216 append |[^[:space:]] to your regular expression to make sure that
217 it matches all non-whitespace characters. A match that contains a
218 newline is silently truncated(!) at the newline.
219
220 The regex can also be set via a diff driver or configuration
221 option, see gitattributes(1) or git-config(1). Giving it explicitly
222 overrides any diff driver or configuration setting. Diff drivers
223 override configuration settings.
224
225 --color-words[=<regex>]
226 Equivalent to --word-diff=color plus (if a regex was specified)
227 --word-diff-regex=<regex>.
228
229 --no-renames
230 Turn off rename detection, even when the configuration file gives
231 the default to do so.
232
233 --check
234 Warn if changes introduce whitespace errors. What are considered
235 whitespace errors is controlled by core.whitespace configuration.
236 By default, trailing whitespaces (including lines that solely
237 consist of whitespaces) and a space character that is immediately
238 followed by a tab character inside the initial indent of the line
239 are considered whitespace errors. Exits with non-zero status if
240 problems are found. Not compatible with --exit-code.
241
242 --full-index
243 Instead of the first handful of characters, show the full pre- and
244 post-image blob object names on the "index" line when generating
245 patch format output.
246
247 --binary
248 In addition to --full-index, output a binary diff that can be
249 applied with git-apply.
250
251 --abbrev[=<n>]
252 Instead of showing the full 40-byte hexadecimal object name in
253 diff-raw format output and diff-tree header lines, show only a
254 partial prefix. This is independent of the --full-index option
255 above, which controls the diff-patch output format. Non default
256 number of digits can be specified with --abbrev=<n>.
257
258 -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
259 Break complete rewrite changes into pairs of delete and create.
260 This serves two purposes:
261
262 It affects the way a change that amounts to a total rewrite of a
263 file not as a series of deletion and insertion mixed together with
264 a very few lines that happen to match textually as the context, but
265 as a single deletion of everything old followed by a single
266 insertion of everything new, and the number m controls this aspect
267 of the -B option (defaults to 60%). -B/70% specifies that less
268 than 30% of the original should remain in the result for Git to
269 consider it a total rewrite (i.e. otherwise the resulting patch
270 will be a series of deletion and insertion mixed together with
271 context lines).
272
273 When used with -M, a totally-rewritten file is also considered as
274 the source of a rename (usually -M only considers a file that
275 disappeared as the source of a rename), and the number n controls
276 this aspect of the -B option (defaults to 50%). -B20% specifies
277 that a change with addition and deletion compared to 20% or more of
278 the file’s size are eligible for being picked up as a possible
279 source of a rename to another file.
280
281 -M[<n>], --find-renames[=<n>]
282 Detect renames. If n is specified, it is a threshold on the
283 similarity index (i.e. amount of addition/deletions compared to the
284 file’s size). For example, -M90% means Git should consider a
285 delete/add pair to be a rename if more than 90% of the file hasn’t
286 changed. Without a % sign, the number is to be read as a fraction,
287 with a decimal point before it. I.e., -M5 becomes 0.5, and is thus
288 the same as -M50%. Similarly, -M05 is the same as -M5%. To limit
289 detection to exact renames, use -M100%.
290
291 -C[<n>], --find-copies[=<n>]
292 Detect copies as well as renames. See also --find-copies-harder. If
293 n is specified, it has the same meaning as for -M<n>.
294
295 --find-copies-harder
296 For performance reasons, by default, -C option finds copies only if
297 the original file of the copy was modified in the same changeset.
298 This flag makes the command inspect unmodified files as candidates
299 for the source of copy. This is a very expensive operation for
300 large projects, so use it with caution. Giving more than one -C
301 option has the same effect.
302
303 -D, --irreversible-delete
304 Omit the preimage for deletes, i.e. print only the header but not
305 the diff between the preimage and /dev/null. The resulting patch is
306 not meant to be applied with patch nor git apply; this is solely
307 for people who want to just concentrate on reviewing the text after
308 the change. In addition, the output obviously lack enough
309 information to apply such a patch in reverse, even manually, hence
310 the name of the option.
311
312 When used together with -B, omit also the preimage in the deletion
313 part of a delete/create pair.
314
315 -l<num>
316 The -M and -C options require O(n^2) processing time where n is the
317 number of potential rename/copy targets. This option prevents
318 rename/copy detection from running if the number of rename/copy
319 targets exceeds the specified number.
320
321 --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
322 Select only files that are Added (A), Copied (C), Deleted (D),
323 Modified (M), Renamed (R), have their type (i.e. regular file,
324 symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
325 (X), or have had their pairing Broken (B). Any combination of the
326 filter characters (including none) can be used. When *
327 (All-or-none) is added to the combination, all paths are selected
328 if there is any file that matches other criteria in the comparison;
329 if there is no file that matches other criteria, nothing is
330 selected.
331
332 -S<string>
333 Look for differences that introduce or remove an instance of
334 <string>. Note that this is different than the string simply
335 appearing in diff output; see the pickaxe entry in gitdiffcore(7)
336 for more details.
337
338 -G<regex>
339 Look for differences whose added or removed line matches the given
340 <regex>.
341
342 --pickaxe-all
343 When -S or -G finds a change, show all the changes in that
344 changeset, not just the files that contain the change in <string>.
345
346 --pickaxe-regex
347 Make the <string> not a plain string but an extended POSIX regex to
348 match.
349
350 -O<orderfile>
351 Output the patch in the order specified in the <orderfile>, which
352 has one shell glob pattern per line.
353
354 -R
355 Swap two inputs; that is, show differences from index or on-disk
356 file to tree contents.
357
358 --relative[=<path>]
359 When run from a subdirectory of the project, it can be told to
360 exclude changes outside the directory and show pathnames relative
361 to it with this option. When you are not in a subdirectory (e.g. in
362 a bare repository), you can name which subdirectory to make the
363 output relative to by giving a <path> as an argument.
364
365 -a, --text
366 Treat all files as text.
367
368 --ignore-space-at-eol
369 Ignore changes in whitespace at EOL.
370
371 -b, --ignore-space-change
372 Ignore changes in amount of whitespace. This ignores whitespace at
373 line end, and considers all other sequences of one or more
374 whitespace characters to be equivalent.
375
376 -w, --ignore-all-space
377 Ignore whitespace when comparing lines. This ignores differences
378 even if one line has whitespace where the other line has none.
379
380 --inter-hunk-context=<lines>
381 Show the context between diff hunks, up to the specified number of
382 lines, thereby fusing hunks that are close to each other.
383
384 -W, --function-context
385 Show whole surrounding functions of changes.
386
387 --exit-code
388 Make the program exit with codes similar to diff(1). That is, it
389 exits with 1 if there were differences and 0 means no differences.
390
391 --quiet
392 Disable all output of the program. Implies --exit-code.
393
394 --ext-diff
395 Allow an external diff helper to be executed. If you set an
396 external diff driver with gitattributes(5), you need to use this
397 option with git-log(1) and friends.
398
399 --no-ext-diff
400 Disallow external diff drivers.
401
402 --textconv, --no-textconv
403 Allow (or disallow) external text conversion filters to be run when
404 comparing binary files. See gitattributes(5) for details. Because
405 textconv filters are typically a one-way conversion, the resulting
406 diff is suitable for human consumption, but cannot be applied. For
407 this reason, textconv filters are enabled by default only for git-
408 diff(1) and git-log(1), but not for git-format-patch(1) or diff
409 plumbing commands.
410
411 --ignore-submodules[=<when>]
412 Ignore changes to submodules in the diff generation. <when> can be
413 either "none", "untracked", "dirty" or "all", which is the default.
414 Using "none" will consider the submodule modified when it either
415 contains untracked or modified files or its HEAD differs from the
416 commit recorded in the superproject and can be used to override any
417 settings of the ignore option in git-config(1) or gitmodules(5).
418 When "untracked" is used submodules are not considered dirty when
419 they only contain untracked content (but they are still scanned for
420 modified content). Using "dirty" ignores all changes to the work
421 tree of submodules, only changes to the commits stored in the
422 superproject are shown (this was the behavior until 1.7.0). Using
423 "all" hides all changes to submodules.
424
425 --src-prefix=<prefix>
426 Show the given source prefix instead of "a/".
427
428 --dst-prefix=<prefix>
429 Show the given destination prefix instead of "b/".
430
431 --no-prefix
432 Do not show any source or destination prefix.
433
434 For more detailed explanation on these common options, see also
435 gitdiffcore(7).
436
437 <tree-ish>
438 The id of a tree object to diff against.
439
440 --cached
441 do not consider the on-disk file at all
442
443 -m
444 By default, files recorded in the index but not checked out are
445 reported as deleted. This flag makes git diff-index say that all
446 non-checked-out files are up to date.
447
449 The raw output format from "git-diff-index", "git-diff-tree",
450 "git-diff-files" and "git diff --raw" are very similar.
451
452 These commands all compare two sets of things; what is compared
453 differs:
454
455 git-diff-index <tree-ish>
456 compares the <tree-ish> and the files on the filesystem.
457
458 git-diff-index --cached <tree-ish>
459 compares the <tree-ish> and the index.
460
461 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
462 compares the trees named by the two arguments.
463
464 git-diff-files [<pattern>...]
465 compares the index and the files on the filesystem.
466
467 The "git-diff-tree" command begins its output by printing the hash of
468 what is being compared. After that, all the commands print one output
469 line per changed file.
470
471 An output line is formatted this way:
472
473 in-place edit :100644 100644 bcd1234... 0123456... M file0
474 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
475 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
476 create :000000 100644 0000000... 1234567... A file4
477 delete :100644 000000 1234567... 0000000... D file5
478 unmerged :000000 000000 0000000... 0000000... U file6
479
480
481 That is, from the left to the right:
482
483 1. a colon.
484
485 2. mode for "src"; 000000 if creation or unmerged.
486
487 3. a space.
488
489 4. mode for "dst"; 000000 if deletion or unmerged.
490
491 5. a space.
492
493 6. sha1 for "src"; 0{40} if creation or unmerged.
494
495 7. a space.
496
497 8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
498
499 9. a space.
500
501 10. status, followed by optional "score" number.
502
503 11. a tab or a NUL when -z option is used.
504
505 12. path for "src"
506
507 13. a tab or a NUL when -z option is used; only exists for C or R.
508
509 14. path for "dst"; only exists for C or R.
510
511 15. an LF or a NUL when -z option is used, to terminate the record.
512
513 Possible status letters are:
514
515 · A: addition of a file
516
517 · C: copy of a file into a new one
518
519 · D: deletion of a file
520
521 · M: modification of the contents or mode of a file
522
523 · R: renaming of a file
524
525 · T: change in the type of the file
526
527 · U: file is unmerged (you must complete the merge before it can be
528 committed)
529
530 · X: "unknown" change type (most probably a bug, please report it)
531
532 Status letters C and R are always followed by a score (denoting the
533 percentage of similarity between the source and target of the move or
534 copy), and are the only ones to be so.
535
536 <sha1> is shown as all 0’s if a file is new on the filesystem and it is
537 out of sync with the index.
538
539 Example:
540
541 :100644 100644 5be4a4...... 000000...... M file.c
542
543
544 When -z option is not used, TAB, LF, and backslash characters in
545 pathnames are represented as \t, \n, and \\, respectively.
546
548 "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
549 --cc option to generate diff output also for merge commits. The output
550 differs from the format described above in the following way:
551
552 1. there is a colon for each parent
553
554 2. there are more "src" modes and "src" sha1
555
556 3. status is concatenated status characters for each parent
557
558 4. no optional "score" number
559
560 5. single path, only for "dst"
561
562 Example:
563
564 ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c
565
566
567 Note that combined diff lists only files which were modified from all
568 parents.
569
571 When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
572 with a -p option, "git diff" without the --raw option, or "git log"
573 with the "-p" option, they do not produce the output described above;
574 instead they produce a patch file. You can customize the creation of
575 such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
576 environment variables.
577
578 What the -p option produces is slightly different from the traditional
579 diff format:
580
581 1. It is preceded with a "git diff" header that looks like this:
582
583 diff --git a/file1 b/file2
584
585 The a/ and b/ filenames are the same unless rename/copy is
586 involved. Especially, even for a creation or a deletion, /dev/null
587 is not used in place of the a/ or b/ filenames.
588
589 When rename/copy is involved, file1 and file2 show the name of the
590 source file of the rename/copy and the name of the file that
591 rename/copy produces, respectively.
592
593 2. It is followed by one or more extended header lines:
594
595 old mode <mode>
596 new mode <mode>
597 deleted file mode <mode>
598 new file mode <mode>
599 copy from <path>
600 copy to <path>
601 rename from <path>
602 rename to <path>
603 similarity index <number>
604 dissimilarity index <number>
605 index <hash>..<hash> <mode>
606
607 File modes are printed as 6-digit octal numbers including the file
608 type and file permission bits.
609
610 Path names in extended headers do not include the a/ and b/
611 prefixes.
612
613 The similarity index is the percentage of unchanged lines, and the
614 dissimilarity index is the percentage of changed lines. It is a
615 rounded down integer, followed by a percent sign. The similarity
616 index value of 100% is thus reserved for two equal files, while
617 100% dissimilarity means that no line from the old file made it
618 into the new one.
619
620 The index line includes the SHA-1 checksum before and after the
621 change. The <mode> is included if the file mode does not change;
622 otherwise, separate lines indicate the old and the new mode.
623
624 3. TAB, LF, double quote and backslash characters in pathnames are
625 represented as \t, \n, \" and \\, respectively. If there is need
626 for such substitution then the whole pathname is put in double
627 quotes.
628
629 4. All the file1 files in the output refer to files before the commit,
630 and all the file2 files refer to files after the commit. It is
631 incorrect to apply each change to each file sequentially. For
632 example, this patch will swap a and b:
633
634 diff --git a/a b/b
635 rename from a
636 rename to b
637 diff --git a/b b/a
638 rename from b
639 rename to a
640
642 Any diff-generating command can take the ‘-c` or --cc option to produce
643 a combined diff when showing a merge. This is the default format when
644 showing merges with git-diff(1) or git-show(1). Note also that you can
645 give the `-m’ option to any of these commands to force generation of
646 diffs with individual parents of a merge.
647
648 A combined diff format looks like this:
649
650 diff --combined describe.c
651 index fabadb8,cc95eb0..4866510
652 --- a/describe.c
653 +++ b/describe.c
654 @@@ -98,20 -98,12 +98,20 @@@
655 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
656 }
657
658 - static void describe(char *arg)
659 -static void describe(struct commit *cmit, int last_one)
660 ++static void describe(char *arg, int last_one)
661 {
662 + unsigned char sha1[20];
663 + struct commit *cmit;
664 struct commit_list *list;
665 static int initialized = 0;
666 struct commit_name *n;
667
668 + if (get_sha1(arg, sha1) < 0)
669 + usage(describe_usage);
670 + cmit = lookup_commit_reference(sha1);
671 + if (!cmit)
672 + usage(describe_usage);
673 +
674 if (!initialized) {
675 initialized = 1;
676 for_each_ref(get_name);
677
678
679
680 1. It is preceded with a "git diff" header, that looks like this (when
681 -c option is used):
682
683 diff --combined file
684
685 or like this (when --cc option is used):
686
687 diff --cc file
688
689 2. It is followed by one or more extended header lines (this example
690 shows a merge with two parents):
691
692 index <hash>,<hash>..<hash>
693 mode <mode>,<mode>..<mode>
694 new file mode <mode>
695 deleted file mode <mode>,<mode>
696
697 The mode <mode>,<mode>..<mode> line appears only if at least one of
698 the <mode> is different from the rest. Extended headers with
699 information about detected contents movement (renames and copying
700 detection) are designed to work with diff of two <tree-ish> and are
701 not used by combined diff format.
702
703 3. It is followed by two-line from-file/to-file header
704
705 --- a/file
706 +++ b/file
707
708 Similar to two-line header for traditional unified diff format,
709 /dev/null is used to signal created or deleted files.
710
711 4. Chunk header format is modified to prevent people from accidentally
712 feeding it to patch -p1. Combined diff format was created for
713 review of merge commit changes, and was not meant for apply. The
714 change is similar to the change in the extended index header:
715
716 @@@ <from-file-range> <from-file-range> <to-file-range> @@@
717
718 There are (number of parents + 1) @ characters in the chunk header
719 for combined diff format.
720
721 Unlike the traditional unified diff format, which shows two files A and
722 B with a single column that has - (minus — appears in A but removed in
723 B), + (plus — missing in A but added to B), or " " (space — unchanged)
724 prefix, this format compares two or more files file1, file2,... with
725 one file X, and shows how X differs from each of fileN. One column for
726 each of fileN is prepended to the output line to note how X’s line is
727 different from it.
728
729 A - character in the column N means that the line appears in fileN but
730 it does not appear in the result. A + character in the column N means
731 that the line appears in the result, and fileN does not have that line
732 (in other words, the line was added, from the point of view of that
733 parent).
734
735 In the above example output, the function signature was changed from
736 both files (hence two - removals from both file1 and file2, plus ++ to
737 mean one line that was added does not appear in either file1 nor
738 file2). Also eight other lines are the same from file1 but do not
739 appear in file2 (hence prefixed with +).
740
741 When shown by git diff-tree -c, it compares the parents of a merge
742 commit with the merge result (i.e. file1..fileN are the parents). When
743 shown by git diff-files -c, it compares the two unresolved merge
744 parents with the working tree file (i.e. file1 is stage 2 aka "our
745 version", file2 is stage 3 aka "their version").
746
748 The --summary option describes newly added, deleted, renamed and copied
749 files. The --stat option adds diffstat(1) graph to the output. These
750 options can be combined with other options, such as -p, and are meant
751 for human consumption.
752
753 When showing a change that involves a rename or a copy, --stat output
754 formats the pathnames compactly by combining common prefix and suffix
755 of the pathnames. For example, a change that moves arch/i386/Makefile
756 to arch/x86/Makefile while modifying 4 lines will be shown like this:
757
758 arch/{i386 => x86}/Makefile | 4 +--
759
760
761 The --numstat option gives the diffstat(1) information but is designed
762 for easier machine consumption. An entry in --numstat output looks like
763 this:
764
765 1 2 README
766 3 1 arch/{i386 => x86}/Makefile
767
768
769 That is, from left to right:
770
771 1. the number of added lines;
772
773 2. a tab;
774
775 3. the number of deleted lines;
776
777 4. a tab;
778
779 5. pathname (possibly with rename/copy information);
780
781 6. a newline.
782
783 When -z output option is in effect, the output is formatted this way:
784
785 1 2 README NUL
786 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
787
788
789 That is:
790
791 1. the number of added lines;
792
793 2. a tab;
794
795 3. the number of deleted lines;
796
797 4. a tab;
798
799 5. a NUL (only exists if renamed/copied);
800
801 6. pathname in preimage;
802
803 7. a NUL (only exists if renamed/copied);
804
805 8. pathname in postimage (only exists if renamed/copied);
806
807 9. a NUL.
808
809 The extra NUL before the preimage path in renamed case is to allow
810 scripts that read the output to tell if the current record being read
811 is a single-path record or a rename/copy record without reading ahead.
812 After reading added and deleted lines, reading up to NUL would yield
813 the pathname, but if that is NUL, the record will show two paths.
814
816 You can choose whether you want to trust the index file entirely (using
817 the --cached flag) or ask the diff logic to show any files that don’t
818 match the stat state as being "tentatively changed". Both of these
819 operations are very useful indeed.
820
822 If --cached is specified, it allows you to ask:
823
824 show me the differences between HEAD and the current index
825 contents (the ones I'd write using 'git write-tree')
826
827 For example, let’s say that you have worked on your working directory,
828 updated some files in the index and are ready to commit. You want to
829 see exactly what you are going to commit, without having to write a new
830 tree object and compare it that way, and to do that, you just do
831
832 git diff-index --cached HEAD
833
834 Example: let’s say I had renamed commit.c to git-commit.c, and I had
835 done an update-index to make that effective in the index file. git
836 diff-files wouldn’t show anything at all, since the index file matches
837 my working directory. But doing a git diff-index does:
838
839 torvalds@ppc970:~/git> git diff-index --cached HEAD
840 -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
841 +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
842
843 You can see easily that the above is a rename.
844
845 In fact, git diff-index --cached should always be entirely equivalent
846 to actually doing a git write-tree and comparing that. Except this one
847 is much nicer for the case where you just want to check where you are.
848
849 So doing a git diff-index --cached is basically very useful when you
850 are asking yourself "what have I already marked for being committed,
851 and what’s the difference to a previous tree".
852
854 The "non-cached" mode takes a different approach, and is potentially
855 the more useful of the two in that what it does can’t be emulated with
856 a git write-tree + git diff-tree. Thus that’s the default mode. The
857 non-cached version asks the question:
858
859 show me the differences between HEAD and the currently checked out
860 tree - index contents _and_ files that aren't up-to-date
861
862 which is obviously a very useful question too, since that tells you
863 what you could commit. Again, the output matches the git diff-tree -r
864 output to a tee, but with a twist.
865
866 The twist is that if some file doesn’t match the index, we don’t have a
867 backing store thing for it, and we use the magic "all-zero" sha1 to
868 show that. So let’s say that you have edited kernel/sched.c, but have
869 not actually done a git update-index on it yet - there is no "object"
870 associated with the new state, and you get:
871
872 torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
873 :100644 100664 7476bb... 000000... kernel/sched.c
874
875 i.e., it shows that the tree has changed, and that kernel/sched.c has
876 is not up-to-date and may contain new stuff. The all-zero sha1 means
877 that to get the real diff, you need to look at the object in the
878 working directory directly rather than do an object-to-object diff.
879
880 Note
881 As with other commands of this type, git diff-index does not
882 actually look at the contents of the file at all. So maybe
883 kernel/sched.c hasn’t actually changed, and it’s just that you
884 touched it. In either case, it’s a note that you need to git
885 update-index it to make the index be in sync.
886
887 Note
888 You can have a mixture of files show up as "has been updated" and
889 "is still dirty in the working directory" together. You can always
890 tell which file is in which state, since the "has been updated"
891 ones show a valid sha1, and the "not in sync with the index" ones
892 will always have the special all-zero sha1.
893
895 Part of the git(1) suite
896
897
898
899Git 1.8.3.1 11/19/2018 GIT-DIFF-INDEX(1)