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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

OPTIONS

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

RAW OUTPUT FORMAT

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

DIFF FORMAT FOR MERGES

741       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
742       --cc option to generate diff output also for merge commits. The output
743       differs from the format described above in the following way:
744
745        1. there is a colon for each parent
746
747        2. there are more "src" modes and "src" sha1
748
749        3. status is concatenated status characters for each parent
750
751        4. no optional "score" number
752
753        5. single path, only for "dst"
754
755       Example:
756
757           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       describe.c
758
759
760       Note that combined diff lists only files which were modified from all
761       parents.
762

GENERATING PATCHES WITH -P

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

COMBINED DIFF FORMAT

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

OTHER DIFF FORMATS

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

OPERATING MODES

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

CACHED MODE

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

NON-CACHED MODE

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

GIT

1086       Part of the git(1) suite
1087
1088
1089
1090Git 2.20.1                        12/15/2018                 GIT-DIFF-INDEX(1)
Impressum