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

NAME

6       git-diff-index - Compare a tree to the working tree or index
7

SYNOPSIS

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

DESCRIPTION

13       Compares the content and mode of the blobs found in a tree object with
14       the corresponding tracked files in the working tree, or with the
15       corresponding paths in the index. When <path> arguments are present,
16       compares only paths matching those patterns. Otherwise all tracked
17       files are compared.
18

OPTIONS

20       -p, -u, --patch
21           Generate patch (see section on generating patches).
22
23       -s, --no-patch
24           Suppress diff output. Useful for commands like git show that show
25           the patch by default, or to cancel the effect of --patch.
26
27       -U<n>, --unified=<n>
28           Generate diffs with <n> lines of context instead of the usual
29           three. Implies -p.
30
31       --raw
32           Generate the diff in raw format. This is the default.
33
34       --patch-with-raw
35           Synonym for -p --raw.
36
37       --indent-heuristic
38           Enable the heuristic that shifts diff hunk boundaries to make
39           patches easier to read. This is the default.
40
41       --no-indent-heuristic
42           Disable the indent heuristic.
43
44       --minimal
45           Spend extra time to make sure the smallest possible diff is
46           produced.
47
48       --patience
49           Generate a diff using the "patience diff" algorithm.
50
51       --histogram
52           Generate a diff using the "histogram diff" algorithm.
53
54       --anchored=<text>
55           Generate a diff using the "anchored diff" algorithm.
56
57           This option may be specified more than once.
58
59           If a line exists in both the source and destination, exists only
60           once, and starts with this text, this algorithm attempts to prevent
61           it from appearing as a deletion or addition in the output. It uses
62           the "patience diff" algorithm internally.
63
64       --diff-algorithm={patience|minimal|histogram|myers}
65           Choose a diff algorithm. The variants are as follows:
66
67           default, myers
68               The basic greedy diff algorithm. Currently, this is the
69               default.
70
71           minimal
72               Spend extra time to make sure the smallest possible diff is
73               produced.
74
75           patience
76               Use "patience diff" algorithm when generating patches.
77
78           histogram
79               This algorithm extends the patience algorithm to "support
80               low-occurrence common elements".
81
82           For instance, if you configured the diff.algorithm variable to a
83           non-default value and want to use the default one, then you have to
84           use --diff-algorithm=default option.
85
86       --stat[=<width>[,<name-width>[,<count>]]]
87           Generate a diffstat. By default, as much space as necessary will be
88           used for the filename part, and the rest for the graph part.
89           Maximum width defaults to terminal width, or 80 columns if not
90           connected to a terminal, and can be overridden by <width>. The
91           width of the filename part can be limited by giving another width
92           <name-width> after a comma. The width of the graph part can be
93           limited by using --stat-graph-width=<width> (affects all commands
94           generating a stat graph) or by setting diff.statGraphWidth=<width>
95           (does not affect git format-patch). By giving a third parameter
96           <count>, you can limit the output to the first <count> lines,
97           followed by ...  if there are more.
98
99           These parameters can also be set individually with
100           --stat-width=<width>, --stat-name-width=<name-width> and
101           --stat-count=<count>.
102
103       --compact-summary
104           Output a condensed summary of extended header information such as
105           file creations or deletions ("new" or "gone", optionally "+l" if
106           it’s a symlink) and mode changes ("+x" or "-x" for adding or
107           removing executable bit respectively) in diffstat. The information
108           is put between the filename part and the graph part. Implies
109           --stat.
110
111       --numstat
112           Similar to --stat, but shows number of added and deleted lines in
113           decimal notation and pathname without abbreviation, to make it more
114           machine friendly. For binary files, outputs two - instead of saying
115           0 0.
116
117       --shortstat
118           Output only the last line of the --stat format containing total
119           number of modified files, as well as number of added and deleted
120           lines.
121
122       --dirstat[=<param1,param2,...>]
123           Output the distribution of relative amount of changes for each
124           sub-directory. The behavior of --dirstat can be customized by
125           passing it a comma separated list of parameters. The defaults are
126           controlled by the diff.dirstat configuration variable (see git-
127           config(1)). The following parameters are available:
128
129           changes
130               Compute the dirstat numbers by counting the lines that have
131               been removed from the source, or added to the destination. This
132               ignores the amount of pure code movements within a file. In
133               other words, rearranging lines in a file is not counted as much
134               as other changes. This is the default behavior when no
135               parameter is given.
136
137           lines
138               Compute the dirstat numbers by doing the regular line-based
139               diff analysis, and summing the removed/added line counts. (For
140               binary files, count 64-byte chunks instead, since binary files
141               have no natural concept of lines). This is a more expensive
142               --dirstat behavior than the changes behavior, but it does count
143               rearranged lines within a file as much as other changes. The
144               resulting output is consistent with what you get from the other
145               --*stat options.
146
147           files
148               Compute the dirstat numbers by counting the number of files
149               changed. Each changed file counts equally in the dirstat
150               analysis. This is the computationally cheapest --dirstat
151               behavior, since it does not have to look at the file contents
152               at all.
153
154           cumulative
155               Count changes in a child directory for the parent directory as
156               well. Note that when using cumulative, the sum of the
157               percentages reported may exceed 100%. The default
158               (non-cumulative) behavior can be specified with the
159               noncumulative parameter.
160
161           <limit>
162               An integer parameter specifies a cut-off percent (3% by
163               default). Directories contributing less than this percentage of
164               the changes are not shown in the output.
165
166           Example: The following will count changed files, while ignoring
167           directories with less than 10% of the total amount of changed
168           files, and accumulating child directory counts in the parent
169           directories: --dirstat=files,10,cumulative.
170
171       --summary
172           Output a condensed summary of extended header information such as
173           creations, renames and mode changes.
174
175       --patch-with-stat
176           Synonym for -p --stat.
177
178       -z
179           When --raw, --numstat, --name-only or --name-status has been given,
180           do not munge pathnames and use NULs as output field terminators.
181
182           Without this option, pathnames with "unusual" characters are quoted
183           as explained for the configuration variable core.quotePath (see
184           git-config(1)).
185
186       --name-only
187           Show only names of changed files.
188
189       --name-status
190           Show only names and status of changed files. See the description of
191           the --diff-filter option on what the status letters mean.
192
193       --submodule[=<format>]
194           Specify how differences in submodules are shown. When specifying
195           --submodule=short the short format is used. This format just shows
196           the names of the commits at the beginning and end of the range.
197           When --submodule or --submodule=log is specified, the log format is
198           used. This format lists the commits in the range like git-
199           submodule(1) summary does. When --submodule=diff is specified, the
200           diff format is used. This format shows an inline diff of the
201           changes in the submodule contents between the commit range.
202           Defaults to diff.submodule or the short format if the config option
203           is unset.
204
205       --color[=<when>]
206           Show colored diff.  --color (i.e. without =<when>) is the same as
207           --color=always.  <when> can be one of always, never, or auto.
208
209       --no-color
210           Turn off colored diff. It is the same as --color=never.
211
212       --color-moved[=<mode>]
213           Moved lines of code are colored differently. The <mode> defaults to
214           no if the option is not given and to zebra if the option with no
215           mode is given. The mode must be one of:
216
217           no
218               Moved lines are not highlighted.
219
220           default
221               Is a synonym for zebra. This may change to a more sensible mode
222               in the future.
223
224           plain
225               Any line that is added in one location and was removed in
226               another location will be colored with color.diff.newMoved.
227               Similarly color.diff.oldMoved will be used for removed lines
228               that are added somewhere else in the diff. This mode picks up
229               any moved line, but it is not very useful in a review to
230               determine if a block of code was moved without permutation.
231
232           blocks
233               Blocks of moved text of at least 20 alphanumeric characters are
234               detected greedily. The detected blocks are painted using either
235               the color.diff.{old,new}Moved color. Adjacent blocks cannot be
236               told apart.
237
238           zebra
239               Blocks of moved text are detected as in blocks mode. The blocks
240               are painted using either the color.diff.{old,new}Moved color or
241               color.diff.{old,new}MovedAlternative. The change between the
242               two colors indicates that a new block was detected.
243
244           dimmed-zebra
245               Similar to zebra, but additional dimming of uninteresting parts
246               of moved code is performed. The bordering lines of two adjacent
247               blocks are considered interesting, the rest is uninteresting.
248               dimmed_zebra is a deprecated synonym.
249
250       --no-color-moved
251           Turn off move detection. This can be used to override configuration
252           settings. It is the same as --color-moved=no.
253
254       --color-moved-ws=<modes>
255           This configures how whitespace is ignored when performing the move
256           detection for --color-moved. These modes can be given as a comma
257           separated list:
258
259           no
260               Do not ignore whitespace when performing move detection.
261
262           ignore-space-at-eol
263               Ignore changes in whitespace at EOL.
264
265           ignore-space-change
266               Ignore changes in amount of whitespace. This ignores whitespace
267               at line end, and considers all other sequences of one or more
268               whitespace characters to be equivalent.
269
270           ignore-all-space
271               Ignore whitespace when comparing lines. This ignores
272               differences even if one line has whitespace where the other
273               line has none.
274
275           allow-indentation-change
276               Initially ignore any whitespace in the move detection, then
277               group the moved code blocks only into a block if the change in
278               whitespace is the same per line. This is incompatible with the
279               other modes.
280
281       --no-color-moved-ws
282           Do not ignore whitespace when performing move detection. This can
283           be used to override configuration settings. It is the same as
284           --color-moved-ws=no.
285
286       --word-diff[=<mode>]
287           Show a word diff, using the <mode> to delimit changed words. By
288           default, words are delimited by whitespace; see --word-diff-regex
289           below. The <mode> defaults to plain, and must be one of:
290
291           color
292               Highlight changed words using only colors. Implies --color.
293
294           plain
295               Show words as [-removed-] and {+added+}. Makes no attempts to
296               escape the delimiters if they appear in the input, so the
297               output may be ambiguous.
298
299           porcelain
300               Use a special line-based format intended for script
301               consumption. Added/removed/unchanged runs are printed in the
302               usual unified diff format, starting with a +/-/` ` character at
303               the beginning of the line and extending to the end of the line.
304               Newlines in the input are represented by a tilde ~ on a line of
305               its own.
306
307           none
308               Disable word diff again.
309
310           Note that despite the name of the first mode, color is used to
311           highlight the changed parts in all modes if enabled.
312
313       --word-diff-regex=<regex>
314           Use <regex> to decide what a word is, instead of considering runs
315           of non-whitespace to be a word. Also implies --word-diff unless it
316           was already enabled.
317
318           Every non-overlapping match of the <regex> is considered a word.
319           Anything between these matches is considered whitespace and
320           ignored(!) for the purposes of finding differences. You may want to
321           append |[^[:space:]] to your regular expression to make sure that
322           it matches all non-whitespace characters. A match that contains a
323           newline is silently truncated(!) at the newline.
324
325           For example, --word-diff-regex=.  will treat each character as a
326           word and, correspondingly, show differences character by character.
327
328           The regex can also be set via a diff driver or configuration
329           option, see gitattributes(5) or git-config(1). Giving it explicitly
330           overrides any diff driver or configuration setting. Diff drivers
331           override configuration settings.
332
333       --color-words[=<regex>]
334           Equivalent to --word-diff=color plus (if a regex was specified)
335           --word-diff-regex=<regex>.
336
337       --no-renames
338           Turn off rename detection, even when the configuration file gives
339           the default to do so.
340
341       --check
342           Warn if changes introduce conflict markers or whitespace errors.
343           What are considered whitespace errors is controlled by
344           core.whitespace configuration. By default, trailing whitespaces
345           (including lines that consist solely of whitespaces) and a space
346           character that is immediately followed by a tab character inside
347           the initial indent of the line are considered whitespace errors.
348           Exits with non-zero status if problems are found. Not compatible
349           with --exit-code.
350
351       --ws-error-highlight=<kind>
352           Highlight whitespace errors in the context, old or new lines of the
353           diff. Multiple values are separated by comma, none resets previous
354           values, default reset the list to new and all is a shorthand for
355           old,new,context. When this option is not given, and the
356           configuration variable diff.wsErrorHighlight is not set, only
357           whitespace errors in new lines are highlighted. The whitespace
358           errors are colored with color.diff.whitespace.
359
360       --full-index
361           Instead of the first handful of characters, show the full pre- and
362           post-image blob object names on the "index" line when generating
363           patch format output.
364
365       --binary
366           In addition to --full-index, output a binary diff that can be
367           applied with git-apply.
368
369       --abbrev[=<n>]
370           Instead of showing the full 40-byte hexadecimal object name in
371           diff-raw format output and diff-tree header lines, show only a
372           partial prefix. This is independent of the --full-index option
373           above, which controls the diff-patch output format. Non default
374           number of digits can be specified with --abbrev=<n>.
375
376       -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
377           Break complete rewrite changes into pairs of delete and create.
378           This serves two purposes:
379
380           It affects the way a change that amounts to a total rewrite of a
381           file not as a series of deletion and insertion mixed together with
382           a very few lines that happen to match textually as the context, but
383           as a single deletion of everything old followed by a single
384           insertion of everything new, and the number m controls this aspect
385           of the -B option (defaults to 60%).  -B/70% specifies that less
386           than 30% of the original should remain in the result for Git to
387           consider it a total rewrite (i.e. otherwise the resulting patch
388           will be a series of deletion and insertion mixed together with
389           context lines).
390
391           When used with -M, a totally-rewritten file is also considered as
392           the source of a rename (usually -M only considers a file that
393           disappeared as the source of a rename), and the number n controls
394           this aspect of the -B option (defaults to 50%).  -B20% specifies
395           that a change with addition and deletion compared to 20% or more of
396           the file’s size are eligible for being picked up as a possible
397           source of a rename to another file.
398
399       -M[<n>], --find-renames[=<n>]
400           Detect renames. If n is specified, it is a threshold on the
401           similarity index (i.e. amount of addition/deletions compared to the
402           file’s size). For example, -M90% means Git should consider a
403           delete/add pair to be a rename if more than 90% of the file hasn’t
404           changed. Without a % sign, the number is to be read as a fraction,
405           with a decimal point before it. I.e., -M5 becomes 0.5, and is thus
406           the same as -M50%. Similarly, -M05 is the same as -M5%. To limit
407           detection to exact renames, use -M100%. The default similarity
408           index is 50%.
409
410       -C[<n>], --find-copies[=<n>]
411           Detect copies as well as renames. See also --find-copies-harder. If
412           n is specified, it has the same meaning as for -M<n>.
413
414       --find-copies-harder
415           For performance reasons, by default, -C option finds copies only if
416           the original file of the copy was modified in the same changeset.
417           This flag makes the command inspect unmodified files as candidates
418           for the source of copy. This is a very expensive operation for
419           large projects, so use it with caution. Giving more than one -C
420           option has the same effect.
421
422       -D, --irreversible-delete
423           Omit the preimage for deletes, i.e. print only the header but not
424           the diff between the preimage and /dev/null. The resulting patch is
425           not meant to be applied with patch or git apply; this is solely for
426           people who want to just concentrate on reviewing the text after the
427           change. In addition, the output obviously lacks enough information
428           to apply such a patch in reverse, even manually, hence the name of
429           the option.
430
431           When used together with -B, omit also the preimage in the deletion
432           part of a delete/create pair.
433
434       -l<num>
435           The -M and -C options require O(n^2) processing time where n is the
436           number of potential rename/copy targets. This option prevents
437           rename/copy detection from running if the number of rename/copy
438           targets exceeds the specified number.
439
440       --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
441           Select only files that are Added (A), Copied (C), Deleted (D),
442           Modified (M), Renamed (R), have their type (i.e. regular file,
443           symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
444           (X), or have had their pairing Broken (B). Any combination of the
445           filter characters (including none) can be used. When *
446           (All-or-none) is added to the combination, all paths are selected
447           if there is any file that matches other criteria in the comparison;
448           if there is no file that matches other criteria, nothing is
449           selected.
450
451           Also, these upper-case letters can be downcased to exclude. E.g.
452           --diff-filter=ad excludes added and deleted paths.
453
454           Note that not all diffs can feature all types. For instance, diffs
455           from the index to the working tree can never have Added entries
456           (because the set of paths included in the diff is limited by what
457           is in the index). Similarly, copied and renamed entries cannot
458           appear if detection for those types is disabled.
459
460       -S<string>
461           Look for differences that change the number of occurrences of the
462           specified string (i.e. addition/deletion) in a file. Intended for
463           the scripter’s use.
464
465           It is useful when you’re looking for an exact block of code (like a
466           struct), and want to know the history of that block since it first
467           came into being: use the feature iteratively to feed the
468           interesting block in the preimage back into -S, and keep going
469           until you get the very first version of the block.
470
471           Binary files are searched as well.
472
473       -G<regex>
474           Look for differences whose patch text contains added/removed lines
475           that match <regex>.
476
477           To illustrate the difference between -S<regex> --pickaxe-regex and
478           -G<regex>, consider a commit with the following diff in the same
479           file:
480
481               +    return !regexec(regexp, two->ptr, 1, &regmatch, 0);
482               ...
483               -    hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
484
485           While git log -G"regexec\(regexp" will show this commit, git log
486           -S"regexec\(regexp" --pickaxe-regex will not (because the number of
487           occurrences of that string did not change).
488
489           Unless --text is supplied patches of binary files without a
490           textconv filter will be ignored.
491
492           See the pickaxe entry in gitdiffcore(7) for more information.
493
494       --find-object=<object-id>
495           Look for differences that change the number of occurrences of the
496           specified object. Similar to -S, just the argument is different in
497           that it doesn’t search for a specific string but for a specific
498           object id.
499
500           The object can be a blob or a submodule commit. It implies the -t
501           option in git-log to also find trees.
502
503       --pickaxe-all
504           When -S or -G finds a change, show all the changes in that
505           changeset, not just the files that contain the change in <string>.
506
507       --pickaxe-regex
508           Treat the <string> given to -S as an extended POSIX regular
509           expression to match.
510
511       -O<orderfile>
512           Control the order in which files appear in the output. This
513           overrides the diff.orderFile configuration variable (see git-
514           config(1)). To cancel diff.orderFile, use -O/dev/null.
515
516           The output order is determined by the order of glob patterns in
517           <orderfile>. All files with pathnames that match the first pattern
518           are output first, all files with pathnames that match the second
519           pattern (but not the first) are output next, and so on. All files
520           with pathnames that do not match any pattern are output last, as if
521           there was an implicit match-all pattern at the end of the file. If
522           multiple pathnames have the same rank (they match the same pattern
523           but no earlier patterns), their output order relative to each other
524           is the normal order.
525
526           <orderfile> is parsed as follows:
527
528           ·   Blank lines are ignored, so they can be used as separators for
529               readability.
530
531           ·   Lines starting with a hash ("#") are ignored, so they can be
532               used for comments. Add a backslash ("\") to the beginning of
533               the pattern if it starts with a hash.
534
535           ·   Each other line contains a single pattern.
536
537           Patterns have the same syntax and semantics as patterns used for
538           fnmatch(3) without the FNM_PATHNAME flag, except a pathname also
539           matches a pattern if removing any number of the final pathname
540           components matches the pattern. For example, the pattern "foo*bar"
541           matches "fooasdfbar" and "foo/bar/baz/asdf" but not "foobarx".
542
543       -R
544           Swap two inputs; that is, show differences from index or on-disk
545           file to tree contents.
546
547       --relative[=<path>]
548           When run from a subdirectory of the project, it can be told to
549           exclude changes outside the directory and show pathnames relative
550           to it with this option. When you are not in a subdirectory (e.g. in
551           a bare repository), you can name which subdirectory to make the
552           output relative to by giving a <path> as an argument.
553
554       -a, --text
555           Treat all files as text.
556
557       --ignore-cr-at-eol
558           Ignore carriage-return at the end of line when doing a comparison.
559
560       --ignore-space-at-eol
561           Ignore changes in whitespace at EOL.
562
563       -b, --ignore-space-change
564           Ignore changes in amount of whitespace. This ignores whitespace at
565           line end, and considers all other sequences of one or more
566           whitespace characters to be equivalent.
567
568       -w, --ignore-all-space
569           Ignore whitespace when comparing lines. This ignores differences
570           even if one line has whitespace where the other line has none.
571
572       --ignore-blank-lines
573           Ignore changes whose lines are all blank.
574
575       --inter-hunk-context=<lines>
576           Show the context between diff hunks, up to the specified number of
577           lines, thereby fusing hunks that are close to each other. Defaults
578           to diff.interHunkContext or 0 if the config option is unset.
579
580       -W, --function-context
581           Show whole surrounding functions of changes.
582
583       --exit-code
584           Make the program exit with codes similar to diff(1). That is, it
585           exits with 1 if there were differences and 0 means no differences.
586
587       --quiet
588           Disable all output of the program. Implies --exit-code.
589
590       --ext-diff
591           Allow an external diff helper to be executed. If you set an
592           external diff driver with gitattributes(5), you need to use this
593           option with git-log(1) and friends.
594
595       --no-ext-diff
596           Disallow external diff drivers.
597
598       --textconv, --no-textconv
599           Allow (or disallow) external text conversion filters to be run when
600           comparing binary files. See gitattributes(5) for details. Because
601           textconv filters are typically a one-way conversion, the resulting
602           diff is suitable for human consumption, but cannot be applied. For
603           this reason, textconv filters are enabled by default only for git-
604           diff(1) and git-log(1), but not for git-format-patch(1) or diff
605           plumbing commands.
606
607       --ignore-submodules[=<when>]
608           Ignore changes to submodules in the diff generation. <when> can be
609           either "none", "untracked", "dirty" or "all", which is the default.
610           Using "none" will consider the submodule modified when it either
611           contains untracked or modified files or its HEAD differs from the
612           commit recorded in the superproject and can be used to override any
613           settings of the ignore option in git-config(1) or gitmodules(5).
614           When "untracked" is used submodules are not considered dirty when
615           they only contain untracked content (but they are still scanned for
616           modified content). Using "dirty" ignores all changes to the work
617           tree of submodules, only changes to the commits stored in the
618           superproject are shown (this was the behavior until 1.7.0). Using
619           "all" hides all changes to submodules.
620
621       --src-prefix=<prefix>
622           Show the given source prefix instead of "a/".
623
624       --dst-prefix=<prefix>
625           Show the given destination prefix instead of "b/".
626
627       --no-prefix
628           Do not show any source or destination prefix.
629
630       --line-prefix=<prefix>
631           Prepend an additional prefix to every line of output.
632
633       --ita-invisible-in-index
634           By default entries added by "git add -N" appear as an existing
635           empty file in "git diff" and a new file in "git diff --cached".
636           This option makes the entry appear as a new file in "git diff" and
637           non-existent in "git diff --cached". This option could be reverted
638           with --ita-visible-in-index. Both options are experimental and
639           could be removed in future.
640
641       For more detailed explanation on these common options, see also
642       gitdiffcore(7).
643
644       <tree-ish>
645           The id of a tree object to diff against.
646
647       --cached
648           do not consider the on-disk file at all
649
650       -m
651           By default, files recorded in the index but not checked out are
652           reported as deleted. This flag makes git diff-index say that all
653           non-checked-out files are up to date.
654

RAW OUTPUT FORMAT

656       The raw output format from "git-diff-index", "git-diff-tree",
657       "git-diff-files" and "git diff --raw" are very similar.
658
659       These commands all compare two sets of things; what is compared
660       differs:
661
662       git-diff-index <tree-ish>
663           compares the <tree-ish> and the files on the filesystem.
664
665       git-diff-index --cached <tree-ish>
666           compares the <tree-ish> and the index.
667
668       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
669           compares the trees named by the two arguments.
670
671       git-diff-files [<pattern>...]
672           compares the index and the files on the filesystem.
673
674       The "git-diff-tree" command begins its output by printing the hash of
675       what is being compared. After that, all the commands print one output
676       line per changed file.
677
678       An output line is formatted this way:
679
680           in-place edit  :100644 100644 bcd1234 0123456 M file0
681           copy-edit      :100644 100644 abcd123 1234567 C68 file1 file2
682           rename-edit    :100644 100644 abcd123 1234567 R86 file1 file3
683           create         :000000 100644 0000000 1234567 A file4
684           delete         :100644 000000 1234567 0000000 D file5
685           unmerged       :000000 000000 0000000 0000000 U file6
686
687
688       That is, from the left to the right:
689
690        1. a colon.
691
692        2. mode for "src"; 000000 if creation or unmerged.
693
694        3. a space.
695
696        4. mode for "dst"; 000000 if deletion or unmerged.
697
698        5. a space.
699
700        6. sha1 for "src"; 0{40} if creation or unmerged.
701
702        7. a space.
703
704        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
705
706        9. a space.
707
708       10. status, followed by optional "score" number.
709
710       11. a tab or a NUL when -z option is used.
711
712       12. path for "src"
713
714       13. a tab or a NUL when -z option is used; only exists for C or R.
715
716       14. path for "dst"; only exists for C or R.
717
718       15. an LF or a NUL when -z option is used, to terminate the record.
719
720       Possible status letters are:
721
722       ·   A: addition of a file
723
724       ·   C: copy of a file into a new one
725
726       ·   D: deletion of a file
727
728       ·   M: modification of the contents or mode of a file
729
730       ·   R: renaming of a file
731
732       ·   T: change in the type of the file
733
734       ·   U: file is unmerged (you must complete the merge before it can be
735           committed)
736
737       ·   X: "unknown" change type (most probably a bug, please report it)
738
739       Status letters C and R are always followed by a score (denoting the
740       percentage of similarity between the source and target of the move or
741       copy). Status letter M may be followed by a score (denoting the
742       percentage of dissimilarity) for file rewrites.
743
744       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
745       out of sync with the index.
746
747       Example:
748
749           :100644 100644 5be4a4a 0000000 M file.c
750
751
752       Without the -z option, pathnames with "unusual" characters are quoted
753       as explained for the configuration variable core.quotePath (see git-
754       config(1)). Using -z the filename is output verbatim and the line is
755       terminated by a NUL byte.
756

DIFF FORMAT FOR MERGES

758       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
759       --cc option to generate diff output also for merge commits. The output
760       differs from the format described above in the following way:
761
762        1. there is a colon for each parent
763
764        2. there are more "src" modes and "src" sha1
765
766        3. status is concatenated status characters for each parent
767
768        4. no optional "score" number
769
770        5. single path, only for "dst"
771
772       Example:
773
774           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       describe.c
775
776
777       Note that combined diff lists only files which were modified from all
778       parents.
779

GENERATING PATCHES WITH -P

781       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
782       with a -p option, "git diff" without the --raw option, or "git log"
783       with the "-p" option, they do not produce the output described above;
784       instead they produce a patch file. You can customize the creation of
785       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
786       environment variables.
787
788       What the -p option produces is slightly different from the traditional
789       diff format:
790
791        1. It is preceded with a "git diff" header that looks like this:
792
793               diff --git a/file1 b/file2
794
795           The a/ and b/ filenames are the same unless rename/copy is
796           involved. Especially, even for a creation or a deletion, /dev/null
797           is not used in place of the a/ or b/ filenames.
798
799           When rename/copy is involved, file1 and file2 show the name of the
800           source file of the rename/copy and the name of the file that
801           rename/copy produces, respectively.
802
803        2. It is followed by one or more extended header lines:
804
805               old mode <mode>
806               new mode <mode>
807               deleted file mode <mode>
808               new file mode <mode>
809               copy from <path>
810               copy to <path>
811               rename from <path>
812               rename to <path>
813               similarity index <number>
814               dissimilarity index <number>
815               index <hash>..<hash> <mode>
816
817           File modes are printed as 6-digit octal numbers including the file
818           type and file permission bits.
819
820           Path names in extended headers do not include the a/ and b/
821           prefixes.
822
823           The similarity index is the percentage of unchanged lines, and the
824           dissimilarity index is the percentage of changed lines. It is a
825           rounded down integer, followed by a percent sign. The similarity
826           index value of 100% is thus reserved for two equal files, while
827           100% dissimilarity means that no line from the old file made it
828           into the new one.
829
830           The index line includes the SHA-1 checksum before and after the
831           change. The <mode> is included if the file mode does not change;
832           otherwise, separate lines indicate the old and the new mode.
833
834        3. Pathnames with "unusual" characters are quoted as explained for the
835           configuration variable core.quotePath (see git-config(1)).
836
837        4. All the file1 files in the output refer to files before the commit,
838           and all the file2 files refer to files after the commit. It is
839           incorrect to apply each change to each file sequentially. For
840           example, this patch will swap a and b:
841
842               diff --git a/a b/b
843               rename from a
844               rename to b
845               diff --git a/b b/a
846               rename from b
847               rename to a
848

COMBINED DIFF FORMAT

850       Any diff-generating command can take the -c or --cc option to produce a
851       combined diff when showing a merge. This is the default format when
852       showing merges with git-diff(1) or git-show(1). Note also that you can
853       give the -m option to any of these commands to force generation of
854       diffs with individual parents of a merge.
855
856       A combined diff format looks like this:
857
858           diff --combined describe.c
859           index fabadb8,cc95eb0..4866510
860           --- a/describe.c
861           +++ b/describe.c
862           @@@ -98,20 -98,12 +98,20 @@@
863                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
864             }
865
866           - static void describe(char *arg)
867            -static void describe(struct commit *cmit, int last_one)
868           ++static void describe(char *arg, int last_one)
869             {
870            +      unsigned char sha1[20];
871            +      struct commit *cmit;
872                   struct commit_list *list;
873                   static int initialized = 0;
874                   struct commit_name *n;
875
876            +      if (get_sha1(arg, sha1) < 0)
877            +              usage(describe_usage);
878            +      cmit = lookup_commit_reference(sha1);
879            +      if (!cmit)
880            +              usage(describe_usage);
881            +
882                   if (!initialized) {
883                           initialized = 1;
884                           for_each_ref(get_name);
885
886
887
888        1. It is preceded with a "git diff" header, that looks like this (when
889           -c option is used):
890
891               diff --combined file
892
893           or like this (when --cc option is used):
894
895               diff --cc file
896
897        2. It is followed by one or more extended header lines (this example
898           shows a merge with two parents):
899
900               index <hash>,<hash>..<hash>
901               mode <mode>,<mode>..<mode>
902               new file mode <mode>
903               deleted file mode <mode>,<mode>
904
905           The mode <mode>,<mode>..<mode> line appears only if at least one of
906           the <mode> is different from the rest. Extended headers with
907           information about detected contents movement (renames and copying
908           detection) are designed to work with diff of two <tree-ish> and are
909           not used by combined diff format.
910
911        3. It is followed by two-line from-file/to-file header
912
913               --- a/file
914               +++ b/file
915
916           Similar to two-line header for traditional unified diff format,
917           /dev/null is used to signal created or deleted files.
918
919        4. Chunk header format is modified to prevent people from accidentally
920           feeding it to patch -p1. Combined diff format was created for
921           review of merge commit changes, and was not meant for apply. The
922           change is similar to the change in the extended index header:
923
924               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
925
926           There are (number of parents + 1) @ characters in the chunk header
927           for combined diff format.
928
929       Unlike the traditional unified diff format, which shows two files A and
930       B with a single column that has - (minus — appears in A but removed in
931       B), + (plus — missing in A but added to B), or " " (space — unchanged)
932       prefix, this format compares two or more files file1, file2,... with
933       one file X, and shows how X differs from each of fileN. One column for
934       each of fileN is prepended to the output line to note how X’s line is
935       different from it.
936
937       A - character in the column N means that the line appears in fileN but
938       it does not appear in the result. A + character in the column N means
939       that the line appears in the result, and fileN does not have that line
940       (in other words, the line was added, from the point of view of that
941       parent).
942
943       In the above example output, the function signature was changed from
944       both files (hence two - removals from both file1 and file2, plus ++ to
945       mean one line that was added does not appear in either file1 or file2).
946       Also eight other lines are the same from file1 but do not appear in
947       file2 (hence prefixed with +).
948
949       When shown by git diff-tree -c, it compares the parents of a merge
950       commit with the merge result (i.e. file1..fileN are the parents). When
951       shown by git diff-files -c, it compares the two unresolved merge
952       parents with the working tree file (i.e. file1 is stage 2 aka "our
953       version", file2 is stage 3 aka "their version").
954

OTHER DIFF FORMATS

956       The --summary option describes newly added, deleted, renamed and copied
957       files. The --stat option adds diffstat(1) graph to the output. These
958       options can be combined with other options, such as -p, and are meant
959       for human consumption.
960
961       When showing a change that involves a rename or a copy, --stat output
962       formats the pathnames compactly by combining common prefix and suffix
963       of the pathnames. For example, a change that moves arch/i386/Makefile
964       to arch/x86/Makefile while modifying 4 lines will be shown like this:
965
966           arch/{i386 => x86}/Makefile    |   4 +--
967
968
969       The --numstat option gives the diffstat(1) information but is designed
970       for easier machine consumption. An entry in --numstat output looks like
971       this:
972
973           1       2       README
974           3       1       arch/{i386 => x86}/Makefile
975
976
977       That is, from left to right:
978
979        1. the number of added lines;
980
981        2. a tab;
982
983        3. the number of deleted lines;
984
985        4. a tab;
986
987        5. pathname (possibly with rename/copy information);
988
989        6. a newline.
990
991       When -z output option is in effect, the output is formatted this way:
992
993           1       2       README NUL
994           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
995
996
997       That is:
998
999        1. the number of added lines;
1000
1001        2. a tab;
1002
1003        3. the number of deleted lines;
1004
1005        4. a tab;
1006
1007        5. a NUL (only exists if renamed/copied);
1008
1009        6. pathname in preimage;
1010
1011        7. a NUL (only exists if renamed/copied);
1012
1013        8. pathname in postimage (only exists if renamed/copied);
1014
1015        9. a NUL.
1016
1017       The extra NUL before the preimage path in renamed case is to allow
1018       scripts that read the output to tell if the current record being read
1019       is a single-path record or a rename/copy record without reading ahead.
1020       After reading added and deleted lines, reading up to NUL would yield
1021       the pathname, but if that is NUL, the record will show two paths.
1022

OPERATING MODES

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

CACHED MODE

1030       If --cached is specified, it allows you to ask:
1031
1032           show me the differences between HEAD and the current index
1033           contents (the ones I'd write using 'git write-tree')
1034
1035       For example, let’s say that you have worked on your working directory,
1036       updated some files in the index and are ready to commit. You want to
1037       see exactly what you are going to commit, without having to write a new
1038       tree object and compare it that way, and to do that, you just do
1039
1040           git diff-index --cached HEAD
1041
1042       Example: let’s say I had renamed commit.c to git-commit.c, and I had
1043       done an update-index to make that effective in the index file. git
1044       diff-files wouldn’t show anything at all, since the index file matches
1045       my working directory. But doing a git diff-index does:
1046
1047           torvalds@ppc970:~/git> git diff-index --cached HEAD
1048           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
1049           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
1050
1051       You can see easily that the above is a rename.
1052
1053       In fact, git diff-index --cached should always be entirely equivalent
1054       to actually doing a git write-tree and comparing that. Except this one
1055       is much nicer for the case where you just want to check where you are.
1056
1057       So doing a git diff-index --cached is basically very useful when you
1058       are asking yourself "what have I already marked for being committed,
1059       and what’s the difference to a previous tree".
1060

NON-CACHED MODE

1062       The "non-cached" mode takes a different approach, and is potentially
1063       the more useful of the two in that what it does can’t be emulated with
1064       a git write-tree + git diff-tree. Thus that’s the default mode. The
1065       non-cached version asks the question:
1066
1067           show me the differences between HEAD and the currently checked out
1068           tree - index contents _and_ files that aren't up to date
1069
1070       which is obviously a very useful question too, since that tells you
1071       what you could commit. Again, the output matches the git diff-tree -r
1072       output to a tee, but with a twist.
1073
1074       The twist is that if some file doesn’t match the index, we don’t have a
1075       backing store thing for it, and we use the magic "all-zero" sha1 to
1076       show that. So let’s say that you have edited kernel/sched.c, but have
1077       not actually done a git update-index on it yet - there is no "object"
1078       associated with the new state, and you get:
1079
1080           torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
1081           :100644 100664 7476bb... 000000...      kernel/sched.c
1082
1083       i.e., it shows that the tree has changed, and that kernel/sched.c is
1084       not up to date and may contain new stuff. The all-zero sha1 means that
1085       to get the real diff, you need to look at the object in the working
1086       directory directly rather than do an object-to-object diff.
1087
1088           Note
1089           As with other commands of this type, git diff-index does not
1090           actually look at the contents of the file at all. So maybe
1091           kernel/sched.c hasn’t actually changed, and it’s just that you
1092           touched it. In either case, it’s a note that you need to git
1093           update-index it to make the index be in sync.
1094
1095           Note
1096           You can have a mixture of files show up as "has been updated" and
1097           "is still dirty in the working directory" together. You can always
1098           tell which file is in which state, since the "has been updated"
1099           ones show a valid sha1, and the "not in sync with the index" ones
1100           will always have the special all-zero sha1.
1101

GIT

1103       Part of the git(1) suite
1104
1105
1106
1107Git 2.21.0                        02/24/2019                 GIT-DIFF-INDEX(1)
Impressum