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] [--merge-base] [<common-diff-options>] <tree-ish> [<path>...]
10

DESCRIPTION

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

OPTIONS

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

RAW OUTPUT FORMAT

700       The raw output format from "git-diff-index", "git-diff-tree",
701       "git-diff-files" and "git diff --raw" are very similar.
702
703       These commands all compare two sets of things; what is compared
704       differs:
705
706       git-diff-index <tree-ish>
707           compares the <tree-ish> and the files on the filesystem.
708
709       git-diff-index --cached <tree-ish>
710           compares the <tree-ish> and the index.
711
712       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
713           compares the trees named by the two arguments.
714
715       git-diff-files [<pattern>...]
716           compares the index and the files on the filesystem.
717
718       The "git-diff-tree" command begins its output by printing the hash of
719       what is being compared. After that, all the commands print one output
720       line per changed file.
721
722       An output line is formatted this way:
723
724           in-place edit  :100644 100644 bcd1234 0123456 M file0
725           copy-edit      :100644 100644 abcd123 1234567 C68 file1 file2
726           rename-edit    :100644 100644 abcd123 1234567 R86 file1 file3
727           create         :000000 100644 0000000 1234567 A file4
728           delete         :100644 000000 1234567 0000000 D file5
729           unmerged       :000000 000000 0000000 0000000 U file6
730
731       That is, from the left to the right:
732
733        1. a colon.
734
735        2. mode for "src"; 000000 if creation or unmerged.
736
737        3. a space.
738
739        4. mode for "dst"; 000000 if deletion or unmerged.
740
741        5. a space.
742
743        6. sha1 for "src"; 0{40} if creation or unmerged.
744
745        7. a space.
746
747        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
748
749        9. a space.
750
751       10. status, followed by optional "score" number.
752
753       11. a tab or a NUL when -z option is used.
754
755       12. path for "src"
756
757       13. a tab or a NUL when -z option is used; only exists for C or R.
758
759       14. path for "dst"; only exists for C or R.
760
761       15. an LF or a NUL when -z option is used, to terminate the record.
762
763       Possible status letters are:
764
765       •   A: addition of a file
766
767       •   C: copy of a file into a new one
768
769       •   D: deletion of a file
770
771       •   M: modification of the contents or mode of a file
772
773       •   R: renaming of a file
774
775       •   T: change in the type of the file (regular file, symbolic link or
776           submodule)
777
778       •   U: file is unmerged (you must complete the merge before it can be
779           committed)
780
781       •   X: "unknown" change type (most probably a bug, please report it)
782
783       Status letters C and R are always followed by a score (denoting the
784       percentage of similarity between the source and target of the move or
785       copy). Status letter M may be followed by a score (denoting the
786       percentage of dissimilarity) for file rewrites.
787
788       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
789       out of sync with the index.
790
791       Example:
792
793           :100644 100644 5be4a4a 0000000 M file.c
794
795       Without the -z option, pathnames with "unusual" characters are quoted
796       as explained for the configuration variable core.quotePath (see git-
797       config(1)). Using -z the filename is output verbatim and the line is
798       terminated by a NUL byte.
799

DIFF FORMAT FOR MERGES

801       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
802       --cc option to generate diff output also for merge commits. The output
803       differs from the format described above in the following way:
804
805        1. there is a colon for each parent
806
807        2. there are more "src" modes and "src" sha1
808
809        3. status is concatenated status characters for each parent
810
811        4. no optional "score" number
812
813        5. tab-separated pathname(s) of the file
814
815       For -c and --cc, only the destination or final path is shown even if
816       the file was renamed on any side of history. With --combined-all-paths,
817       the name of the path in each parent is shown followed by the name of
818       the path in the merge commit.
819
820       Examples for -c and --cc without --combined-all-paths:
821
822           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c
823           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       bar.sh
824           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       phooey.c
825
826       Examples when --combined-all-paths added to either -c or --cc:
827
828           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c  desc.c  desc.c
829           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       foo.sh  bar.sh  bar.sh
830           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       fooey.c fuey.c  phooey.c
831
832       Note that combined diff lists only files which were modified from all
833       parents.
834

GENERATING PATCH TEXT WITH -P

836       Running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-
837       diff-tree(1), or git-diff-files(1) with the -p option produces patch
838       text. You can customize the creation of patch text via the
839       GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables (see
840       git(1)), and the diff attribute (see gitattributes(5)).
841
842       What the -p option produces is slightly different from the traditional
843       diff format:
844
845        1. It is preceded with a "git diff" header that looks like this:
846
847               diff --git a/file1 b/file2
848
849           The a/ and b/ filenames are the same unless rename/copy is
850           involved. Especially, even for a creation or a deletion, /dev/null
851           is not used in place of the a/ or b/ filenames.
852
853           When rename/copy is involved, file1 and file2 show the name of the
854           source file of the rename/copy and the name of the file that
855           rename/copy produces, respectively.
856
857        2. It is followed by one or more extended header lines:
858
859               old mode <mode>
860               new mode <mode>
861               deleted file mode <mode>
862               new file mode <mode>
863               copy from <path>
864               copy to <path>
865               rename from <path>
866               rename to <path>
867               similarity index <number>
868               dissimilarity index <number>
869               index <hash>..<hash> <mode>
870
871           File modes are printed as 6-digit octal numbers including the file
872           type and file permission bits.
873
874           Path names in extended headers do not include the a/ and b/
875           prefixes.
876
877           The similarity index is the percentage of unchanged lines, and the
878           dissimilarity index is the percentage of changed lines. It is a
879           rounded down integer, followed by a percent sign. The similarity
880           index value of 100% is thus reserved for two equal files, while
881           100% dissimilarity means that no line from the old file made it
882           into the new one.
883
884           The index line includes the blob object names before and after the
885           change. The <mode> is included if the file mode does not change;
886           otherwise, separate lines indicate the old and the new mode.
887
888        3. Pathnames with "unusual" characters are quoted as explained for the
889           configuration variable core.quotePath (see git-config(1)).
890
891        4. All the file1 files in the output refer to files before the commit,
892           and all the file2 files refer to files after the commit. It is
893           incorrect to apply each change to each file sequentially. For
894           example, this patch will swap a and b:
895
896               diff --git a/a b/b
897               rename from a
898               rename to b
899               diff --git a/b b/a
900               rename from b
901               rename to a
902
903        5. Hunk headers mention the name of the function to which the hunk
904           applies. See "Defining a custom hunk-header" in gitattributes(5)
905           for details of how to tailor to this to specific languages.
906

COMBINED DIFF FORMAT

908       Any diff-generating command can take the -c or --cc option to produce a
909       combined diff when showing a merge. This is the default format when
910       showing merges with git-diff(1) or git-show(1). Note also that you can
911       give suitable --diff-merges option to any of these commands to force
912       generation of diffs in specific format.
913
914       A "combined diff" format looks like this:
915
916           diff --combined describe.c
917           index fabadb8,cc95eb0..4866510
918           --- a/describe.c
919           +++ b/describe.c
920           @@@ -98,20 -98,12 +98,20 @@@
921                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
922             }
923
924           - static void describe(char *arg)
925            -static void describe(struct commit *cmit, int last_one)
926           ++static void describe(char *arg, int last_one)
927             {
928            +      unsigned char sha1[20];
929            +      struct commit *cmit;
930                   struct commit_list *list;
931                   static int initialized = 0;
932                   struct commit_name *n;
933
934            +      if (get_sha1(arg, sha1) < 0)
935            +              usage(describe_usage);
936            +      cmit = lookup_commit_reference(sha1);
937            +      if (!cmit)
938            +              usage(describe_usage);
939            +
940                   if (!initialized) {
941                           initialized = 1;
942                           for_each_ref(get_name);
943
944        1. It is preceded with a "git diff" header, that looks like this (when
945           the -c option is used):
946
947               diff --combined file
948
949           or like this (when the --cc option is used):
950
951               diff --cc file
952
953        2. It is followed by one or more extended header lines (this example
954           shows a merge with two parents):
955
956               index <hash>,<hash>..<hash>
957               mode <mode>,<mode>..<mode>
958               new file mode <mode>
959               deleted file mode <mode>,<mode>
960
961           The mode <mode>,<mode>..<mode> line appears only if at least one of
962           the <mode> is different from the rest. Extended headers with
963           information about detected contents movement (renames and copying
964           detection) are designed to work with diff of two <tree-ish> and are
965           not used by combined diff format.
966
967        3. It is followed by two-line from-file/to-file header
968
969               --- a/file
970               +++ b/file
971
972           Similar to two-line header for traditional unified diff format,
973           /dev/null is used to signal created or deleted files.
974
975           However, if the --combined-all-paths option is provided, instead of
976           a two-line from-file/to-file you get a N+1 line from-file/to-file
977           header, where N is the number of parents in the merge commit
978
979               --- a/file
980               --- a/file
981               --- a/file
982               +++ b/file
983
984           This extended format can be useful if rename or copy detection is
985           active, to allow you to see the original name of the file in
986           different parents.
987
988        4. Chunk header format is modified to prevent people from accidentally
989           feeding it to patch -p1. Combined diff format was created for
990           review of merge commit changes, and was not meant to be applied.
991           The change is similar to the change in the extended index header:
992
993               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
994
995           There are (number of parents + 1) @ characters in the chunk header
996           for combined diff format.
997
998       Unlike the traditional unified diff format, which shows two files A and
999       B with a single column that has - (minus — appears in A but removed in
1000       B), + (plus — missing in A but added to B), or " " (space — unchanged)
1001       prefix, this format compares two or more files file1, file2,... with
1002       one file X, and shows how X differs from each of fileN. One column for
1003       each of fileN is prepended to the output line to note how X’s line is
1004       different from it.
1005
1006       A - character in the column N means that the line appears in fileN but
1007       it does not appear in the result. A + character in the column N means
1008       that the line appears in the result, and fileN does not have that line
1009       (in other words, the line was added, from the point of view of that
1010       parent).
1011
1012       In the above example output, the function signature was changed from
1013       both files (hence two - removals from both file1 and file2, plus ++ to
1014       mean one line that was added does not appear in either file1 or file2).
1015       Also eight other lines are the same from file1 but do not appear in
1016       file2 (hence prefixed with +).
1017
1018       When shown by git diff-tree -c, it compares the parents of a merge
1019       commit with the merge result (i.e. file1..fileN are the parents). When
1020       shown by git diff-files -c, it compares the two unresolved merge
1021       parents with the working tree file (i.e. file1 is stage 2 aka "our
1022       version", file2 is stage 3 aka "their version").
1023

OTHER DIFF FORMATS

1025       The --summary option describes newly added, deleted, renamed and copied
1026       files. The --stat option adds diffstat(1) graph to the output. These
1027       options can be combined with other options, such as -p, and are meant
1028       for human consumption.
1029
1030       When showing a change that involves a rename or a copy, --stat output
1031       formats the pathnames compactly by combining common prefix and suffix
1032       of the pathnames. For example, a change that moves arch/i386/Makefile
1033       to arch/x86/Makefile while modifying 4 lines will be shown like this:
1034
1035           arch/{i386 => x86}/Makefile    |   4 +--
1036
1037       The --numstat option gives the diffstat(1) information but is designed
1038       for easier machine consumption. An entry in --numstat output looks like
1039       this:
1040
1041           1       2       README
1042           3       1       arch/{i386 => x86}/Makefile
1043
1044       That is, from left to right:
1045
1046        1. the number of added lines;
1047
1048        2. a tab;
1049
1050        3. the number of deleted lines;
1051
1052        4. a tab;
1053
1054        5. pathname (possibly with rename/copy information);
1055
1056        6. a newline.
1057
1058       When -z output option is in effect, the output is formatted this way:
1059
1060           1       2       README NUL
1061           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1062
1063       That is:
1064
1065        1. the number of added lines;
1066
1067        2. a tab;
1068
1069        3. the number of deleted lines;
1070
1071        4. a tab;
1072
1073        5. a NUL (only exists if renamed/copied);
1074
1075        6. pathname in preimage;
1076
1077        7. a NUL (only exists if renamed/copied);
1078
1079        8. pathname in postimage (only exists if renamed/copied);
1080
1081        9. a NUL.
1082
1083       The extra NUL before the preimage path in renamed case is to allow
1084       scripts that read the output to tell if the current record being read
1085       is a single-path record or a rename/copy record without reading ahead.
1086       After reading added and deleted lines, reading up to NUL would yield
1087       the pathname, but if that is NUL, the record will show two paths.
1088

OPERATING MODES

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

CACHED MODE

1096       If --cached is specified, it allows you to ask:
1097
1098           show me the differences between HEAD and the current index
1099           contents (the ones I'd write using 'git write-tree')
1100
1101       For example, let’s say that you have worked on your working directory,
1102       updated some files in the index and are ready to commit. You want to
1103       see exactly what you are going to commit, without having to write a new
1104       tree object and compare it that way, and to do that, you just do
1105
1106           git diff-index --cached HEAD
1107
1108       Example: let’s say I had renamed commit.c to git-commit.c, and I had
1109       done an update-index to make that effective in the index file. git
1110       diff-files wouldn’t show anything at all, since the index file matches
1111       my working directory. But doing a git diff-index does:
1112
1113           torvalds@ppc970:~/git> git diff-index --cached HEAD
1114           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
1115           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
1116
1117       You can see easily that the above is a rename.
1118
1119       In fact, git diff-index --cached should always be entirely equivalent
1120       to actually doing a git write-tree and comparing that. Except this one
1121       is much nicer for the case where you just want to check where you are.
1122
1123       So doing a git diff-index --cached is basically very useful when you
1124       are asking yourself "what have I already marked for being committed,
1125       and what’s the difference to a previous tree".
1126

NON-CACHED MODE

1128       The "non-cached" mode takes a different approach, and is potentially
1129       the more useful of the two in that what it does can’t be emulated with
1130       a git write-tree + git diff-tree. Thus that’s the default mode. The
1131       non-cached version asks the question:
1132
1133           show me the differences between HEAD and the currently checked out
1134           tree - index contents _and_ files that aren't up to date
1135
1136       which is obviously a very useful question too, since that tells you
1137       what you could commit. Again, the output matches the git diff-tree -r
1138       output to a tee, but with a twist.
1139
1140       The twist is that if some file doesn’t match the index, we don’t have a
1141       backing store thing for it, and we use the magic "all-zero" sha1 to
1142       show that. So let’s say that you have edited kernel/sched.c, but have
1143       not actually done a git update-index on it yet - there is no "object"
1144       associated with the new state, and you get:
1145
1146           torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
1147           :100644 100664 7476bb... 000000...      kernel/sched.c
1148
1149       i.e., it shows that the tree has changed, and that kernel/sched.c is
1150       not up to date and may contain new stuff. The all-zero sha1 means that
1151       to get the real diff, you need to look at the object in the working
1152       directory directly rather than do an object-to-object diff.
1153
1154           Note
1155           As with other commands of this type, git diff-index does not
1156           actually look at the contents of the file at all. So maybe
1157           kernel/sched.c hasn’t actually changed, and it’s just that you
1158           touched it. In either case, it’s a note that you need to git
1159           update-index it to make the index be in sync.
1160
1161           Note
1162           You can have a mixture of files show up as "has been updated" and
1163           "is still dirty in the working directory" together. You can always
1164           tell which file is in which state, since the "has been updated"
1165           ones show a valid sha1, and the "not in sync with the index" ones
1166           will always have the special all-zero sha1.
1167

GIT

1169       Part of the git(1) suite
1170
1171
1172
1173Git 2.36.1                        2022-05-05                 GIT-DIFF-INDEX(1)
Impressum