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

RAW OUTPUT FORMAT

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

DIFF FORMAT FOR MERGES

775       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
776       --cc option to generate diff output also for merge commits. The output
777       differs from the format described above in the following way:
778
779        1. there is a colon for each parent
780
781        2. there are more "src" modes and "src" sha1
782
783        3. status is concatenated status characters for each parent
784
785        4. no optional "score" number
786
787        5. tab-separated pathname(s) of the file
788
789       For -c and --cc, only the destination or final path is shown even if
790       the file was renamed on any side of history. With --combined-all-paths,
791       the name of the path in each parent is shown followed by the name of
792       the path in the merge commit.
793
794       Examples for -c and --cc without --combined-all-paths:
795
796           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c
797           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       bar.sh
798           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       phooey.c
799
800
801       Examples when --combined-all-paths added to either -c or --cc:
802
803           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c  desc.c  desc.c
804           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       foo.sh  bar.sh  bar.sh
805           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       fooey.c fuey.c  phooey.c
806
807
808       Note that combined diff lists only files which were modified from all
809       parents.
810

GENERATING PATCH TEXT WITH -P

812       Running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-
813       diff-tree(1), or git-diff-files(1) with the -p option produces patch
814       text. You can customize the creation of patch text via the
815       GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.
816
817       What the -p option produces is slightly different from the traditional
818       diff format:
819
820        1. It is preceded with a "git diff" header that looks like this:
821
822               diff --git a/file1 b/file2
823
824           The a/ and b/ filenames are the same unless rename/copy is
825           involved. Especially, even for a creation or a deletion, /dev/null
826           is not used in place of the a/ or b/ filenames.
827
828           When rename/copy is involved, file1 and file2 show the name of the
829           source file of the rename/copy and the name of the file that
830           rename/copy produces, respectively.
831
832        2. It is followed by one or more extended header lines:
833
834               old mode <mode>
835               new mode <mode>
836               deleted file mode <mode>
837               new file mode <mode>
838               copy from <path>
839               copy to <path>
840               rename from <path>
841               rename to <path>
842               similarity index <number>
843               dissimilarity index <number>
844               index <hash>..<hash> <mode>
845
846           File modes are printed as 6-digit octal numbers including the file
847           type and file permission bits.
848
849           Path names in extended headers do not include the a/ and b/
850           prefixes.
851
852           The similarity index is the percentage of unchanged lines, and the
853           dissimilarity index is the percentage of changed lines. It is a
854           rounded down integer, followed by a percent sign. The similarity
855           index value of 100% is thus reserved for two equal files, while
856           100% dissimilarity means that no line from the old file made it
857           into the new one.
858
859           The index line includes the blob object names before and after the
860           change. The <mode> is included if the file mode does not change;
861           otherwise, separate lines indicate the old and the new mode.
862
863        3. Pathnames with "unusual" characters are quoted as explained for the
864           configuration variable core.quotePath (see git-config(1)).
865
866        4. All the file1 files in the output refer to files before the commit,
867           and all the file2 files refer to files after the commit. It is
868           incorrect to apply each change to each file sequentially. For
869           example, this patch will swap a and b:
870
871               diff --git a/a b/b
872               rename from a
873               rename to b
874               diff --git a/b b/a
875               rename from b
876               rename to a
877

COMBINED DIFF FORMAT

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

OTHER DIFF FORMATS

998       The --summary option describes newly added, deleted, renamed and copied
999       files. The --stat option adds diffstat(1) graph to the output. These
1000       options can be combined with other options, such as -p, and are meant
1001       for human consumption.
1002
1003       When showing a change that involves a rename or a copy, --stat output
1004       formats the pathnames compactly by combining common prefix and suffix
1005       of the pathnames. For example, a change that moves arch/i386/Makefile
1006       to arch/x86/Makefile while modifying 4 lines will be shown like this:
1007
1008           arch/{i386 => x86}/Makefile    |   4 +--
1009
1010
1011       The --numstat option gives the diffstat(1) information but is designed
1012       for easier machine consumption. An entry in --numstat output looks like
1013       this:
1014
1015           1       2       README
1016           3       1       arch/{i386 => x86}/Makefile
1017
1018
1019       That is, from left to right:
1020
1021        1. the number of added lines;
1022
1023        2. a tab;
1024
1025        3. the number of deleted lines;
1026
1027        4. a tab;
1028
1029        5. pathname (possibly with rename/copy information);
1030
1031        6. a newline.
1032
1033       When -z output option is in effect, the output is formatted this way:
1034
1035           1       2       README NUL
1036           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1037
1038
1039       That is:
1040
1041        1. the number of added lines;
1042
1043        2. a tab;
1044
1045        3. the number of deleted lines;
1046
1047        4. a tab;
1048
1049        5. a NUL (only exists if renamed/copied);
1050
1051        6. pathname in preimage;
1052
1053        7. a NUL (only exists if renamed/copied);
1054
1055        8. pathname in postimage (only exists if renamed/copied);
1056
1057        9. a NUL.
1058
1059       The extra NUL before the preimage path in renamed case is to allow
1060       scripts that read the output to tell if the current record being read
1061       is a single-path record or a rename/copy record without reading ahead.
1062       After reading added and deleted lines, reading up to NUL would yield
1063       the pathname, but if that is NUL, the record will show two paths.
1064

OPERATING MODES

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

CACHED MODE

1072       If --cached is specified, it allows you to ask:
1073
1074           show me the differences between HEAD and the current index
1075           contents (the ones I'd write using 'git write-tree')
1076
1077       For example, let’s say that you have worked on your working directory,
1078       updated some files in the index and are ready to commit. You want to
1079       see exactly what you are going to commit, without having to write a new
1080       tree object and compare it that way, and to do that, you just do
1081
1082           git diff-index --cached HEAD
1083
1084       Example: let’s say I had renamed commit.c to git-commit.c, and I had
1085       done an update-index to make that effective in the index file. git
1086       diff-files wouldn’t show anything at all, since the index file matches
1087       my working directory. But doing a git diff-index does:
1088
1089           torvalds@ppc970:~/git> git diff-index --cached HEAD
1090           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
1091           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
1092
1093       You can see easily that the above is a rename.
1094
1095       In fact, git diff-index --cached should always be entirely equivalent
1096       to actually doing a git write-tree and comparing that. Except this one
1097       is much nicer for the case where you just want to check where you are.
1098
1099       So doing a git diff-index --cached is basically very useful when you
1100       are asking yourself "what have I already marked for being committed,
1101       and what’s the difference to a previous tree".
1102

NON-CACHED MODE

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

GIT

1145       Part of the git(1) suite
1146
1147
1148
1149Git 2.24.1                        12/10/2019                 GIT-DIFF-INDEX(1)
Impressum