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           zebra
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 or
236               color.diff.{old,new}MovedAlternative. The change between the
237               two colors indicates that a new block was detected.
238
239           dimmed_zebra
240               Similar to zebra, but additional dimming of uninteresting parts
241               of moved code is performed. The bordering lines of two adjacent
242               blocks are considered interesting, the rest is uninteresting.
243
244       --word-diff[=<mode>]
245           Show a word diff, using the <mode> to delimit changed words. By
246           default, words are delimited by whitespace; see --word-diff-regex
247           below. The <mode> defaults to plain, and must be one of:
248
249           color
250               Highlight changed words using only colors. Implies --color.
251
252           plain
253               Show words as [-removed-] and {+added+}. Makes no attempts to
254               escape the delimiters if they appear in the input, so the
255               output may be ambiguous.
256
257           porcelain
258               Use a special line-based format intended for script
259               consumption. Added/removed/unchanged runs are printed in the
260               usual unified diff format, starting with a +/-/` ` character at
261               the beginning of the line and extending to the end of the line.
262               Newlines in the input are represented by a tilde ~ on a line of
263               its own.
264
265           none
266               Disable word diff again.
267
268           Note that despite the name of the first mode, color is used to
269           highlight the changed parts in all modes if enabled.
270
271       --word-diff-regex=<regex>
272           Use <regex> to decide what a word is, instead of considering runs
273           of non-whitespace to be a word. Also implies --word-diff unless it
274           was already enabled.
275
276           Every non-overlapping match of the <regex> is considered a word.
277           Anything between these matches is considered whitespace and
278           ignored(!) for the purposes of finding differences. You may want to
279           append |[^[:space:]] to your regular expression to make sure that
280           it matches all non-whitespace characters. A match that contains a
281           newline is silently truncated(!) at the newline.
282
283           For example, --word-diff-regex=.  will treat each character as a
284           word and, correspondingly, show differences character by character.
285
286           The regex can also be set via a diff driver or configuration
287           option, see gitattributes(5) or git-config(1). Giving it explicitly
288           overrides any diff driver or configuration setting. Diff drivers
289           override configuration settings.
290
291       --color-words[=<regex>]
292           Equivalent to --word-diff=color plus (if a regex was specified)
293           --word-diff-regex=<regex>.
294
295       --no-renames
296           Turn off rename detection, even when the configuration file gives
297           the default to do so.
298
299       --check
300           Warn if changes introduce conflict markers or whitespace errors.
301           What are considered whitespace errors is controlled by
302           core.whitespace configuration. By default, trailing whitespaces
303           (including lines that consist solely of whitespaces) and a space
304           character that is immediately followed by a tab character inside
305           the initial indent of the line are considered whitespace errors.
306           Exits with non-zero status if problems are found. Not compatible
307           with --exit-code.
308
309       --ws-error-highlight=<kind>
310           Highlight whitespace errors in the context, old or new lines of the
311           diff. Multiple values are separated by comma, none resets previous
312           values, default reset the list to new and all is a shorthand for
313           old,new,context. When this option is not given, and the
314           configuration variable diff.wsErrorHighlight is not set, only
315           whitespace errors in new lines are highlighted. The whitespace
316           errors are colored with color.diff.whitespace.
317
318       --full-index
319           Instead of the first handful of characters, show the full pre- and
320           post-image blob object names on the "index" line when generating
321           patch format output.
322
323       --binary
324           In addition to --full-index, output a binary diff that can be
325           applied with git-apply.
326
327       --abbrev[=<n>]
328           Instead of showing the full 40-byte hexadecimal object name in
329           diff-raw format output and diff-tree header lines, show only a
330           partial prefix. This is independent of the --full-index option
331           above, which controls the diff-patch output format. Non default
332           number of digits can be specified with --abbrev=<n>.
333
334       -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
335           Break complete rewrite changes into pairs of delete and create.
336           This serves two purposes:
337
338           It affects the way a change that amounts to a total rewrite of a
339           file not as a series of deletion and insertion mixed together with
340           a very few lines that happen to match textually as the context, but
341           as a single deletion of everything old followed by a single
342           insertion of everything new, and the number m controls this aspect
343           of the -B option (defaults to 60%).  -B/70% specifies that less
344           than 30% of the original should remain in the result for Git to
345           consider it a total rewrite (i.e. otherwise the resulting patch
346           will be a series of deletion and insertion mixed together with
347           context lines).
348
349           When used with -M, a totally-rewritten file is also considered as
350           the source of a rename (usually -M only considers a file that
351           disappeared as the source of a rename), and the number n controls
352           this aspect of the -B option (defaults to 50%).  -B20% specifies
353           that a change with addition and deletion compared to 20% or more of
354           the file’s size are eligible for being picked up as a possible
355           source of a rename to another file.
356
357       -M[<n>], --find-renames[=<n>]
358           Detect renames. If n is specified, it is a threshold on the
359           similarity index (i.e. amount of addition/deletions compared to the
360           file’s size). For example, -M90% means Git should consider a
361           delete/add pair to be a rename if more than 90% of the file hasn’t
362           changed. Without a % sign, the number is to be read as a fraction,
363           with a decimal point before it. I.e., -M5 becomes 0.5, and is thus
364           the same as -M50%. Similarly, -M05 is the same as -M5%. To limit
365           detection to exact renames, use -M100%. The default similarity
366           index is 50%.
367
368       -C[<n>], --find-copies[=<n>]
369           Detect copies as well as renames. See also --find-copies-harder. If
370           n is specified, it has the same meaning as for -M<n>.
371
372       --find-copies-harder
373           For performance reasons, by default, -C option finds copies only if
374           the original file of the copy was modified in the same changeset.
375           This flag makes the command inspect unmodified files as candidates
376           for the source of copy. This is a very expensive operation for
377           large projects, so use it with caution. Giving more than one -C
378           option has the same effect.
379
380       -D, --irreversible-delete
381           Omit the preimage for deletes, i.e. print only the header but not
382           the diff between the preimage and /dev/null. The resulting patch is
383           not meant to be applied with patch or git apply; this is solely for
384           people who want to just concentrate on reviewing the text after the
385           change. In addition, the output obviously lacks enough information
386           to apply such a patch in reverse, even manually, hence the name of
387           the option.
388
389           When used together with -B, omit also the preimage in the deletion
390           part of a delete/create pair.
391
392       -l<num>
393           The -M and -C options require O(n^2) processing time where n is the
394           number of potential rename/copy targets. This option prevents
395           rename/copy detection from running if the number of rename/copy
396           targets exceeds the specified number.
397
398       --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
399           Select only files that are Added (A), Copied (C), Deleted (D),
400           Modified (M), Renamed (R), have their type (i.e. regular file,
401           symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
402           (X), or have had their pairing Broken (B). Any combination of the
403           filter characters (including none) can be used. When *
404           (All-or-none) is added to the combination, all paths are selected
405           if there is any file that matches other criteria in the comparison;
406           if there is no file that matches other criteria, nothing is
407           selected.
408
409           Also, these upper-case letters can be downcased to exclude. E.g.
410           --diff-filter=ad excludes added and deleted paths.
411
412           Note that not all diffs can feature all types. For instance, diffs
413           from the index to the working tree can never have Added entries
414           (because the set of paths included in the diff is limited by what
415           is in the index). Similarly, copied and renamed entries cannot
416           appear if detection for those types is disabled.
417
418       -S<string>
419           Look for differences that change the number of occurrences of the
420           specified string (i.e. addition/deletion) in a file. Intended for
421           the scripter’s use.
422
423           It is useful when you’re looking for an exact block of code (like a
424           struct), and want to know the history of that block since it first
425           came into being: use the feature iteratively to feed the
426           interesting block in the preimage back into -S, and keep going
427           until you get the very first version of the block.
428
429       -G<regex>
430           Look for differences whose patch text contains added/removed lines
431           that match <regex>.
432
433           To illustrate the difference between -S<regex> --pickaxe-regex and
434           -G<regex>, consider a commit with the following diff in the same
435           file:
436
437               +    return !regexec(regexp, two->ptr, 1, &regmatch, 0);
438               ...
439               -    hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
440
441           While git log -G"regexec\(regexp" will show this commit, git log
442           -S"regexec\(regexp" --pickaxe-regex will not (because the number of
443           occurrences of that string did not change).
444
445           See the pickaxe entry in gitdiffcore(7) for more information.
446
447       --find-object=<object-id>
448           Look for differences that change the number of occurrences of the
449           specified object. Similar to -S, just the argument is different in
450           that it doesn’t search for a specific string but for a specific
451           object id.
452
453           The object can be a blob or a submodule commit. It implies the -t
454           option in git-log to also find trees.
455
456       --pickaxe-all
457           When -S or -G finds a change, show all the changes in that
458           changeset, not just the files that contain the change in <string>.
459
460       --pickaxe-regex
461           Treat the <string> given to -S as an extended POSIX regular
462           expression to match.
463
464       -O<orderfile>
465           Control the order in which files appear in the output. This
466           overrides the diff.orderFile configuration variable (see git-
467           config(1)). To cancel diff.orderFile, use -O/dev/null.
468
469           The output order is determined by the order of glob patterns in
470           <orderfile>. All files with pathnames that match the first pattern
471           are output first, all files with pathnames that match the second
472           pattern (but not the first) are output next, and so on. All files
473           with pathnames that do not match any pattern are output last, as if
474           there was an implicit match-all pattern at the end of the file. If
475           multiple pathnames have the same rank (they match the same pattern
476           but no earlier patterns), their output order relative to each other
477           is the normal order.
478
479           <orderfile> is parsed as follows:
480
481           ·   Blank lines are ignored, so they can be used as separators for
482               readability.
483
484           ·   Lines starting with a hash ("#") are ignored, so they can be
485               used for comments. Add a backslash ("\") to the beginning of
486               the pattern if it starts with a hash.
487
488           ·   Each other line contains a single pattern.
489
490           Patterns have the same syntax and semantics as patterns used for
491           fnmatch(3) without the FNM_PATHNAME flag, except a pathname also
492           matches a pattern if removing any number of the final pathname
493           components matches the pattern. For example, the pattern "foo*bar"
494           matches "fooasdfbar" and "foo/bar/baz/asdf" but not "foobarx".
495
496       -R
497           Swap two inputs; that is, show differences from index or on-disk
498           file to tree contents.
499
500       --relative[=<path>]
501           When run from a subdirectory of the project, it can be told to
502           exclude changes outside the directory and show pathnames relative
503           to it with this option. When you are not in a subdirectory (e.g. in
504           a bare repository), you can name which subdirectory to make the
505           output relative to by giving a <path> as an argument.
506
507       -a, --text
508           Treat all files as text.
509
510       --ignore-cr-at-eol
511           Ignore carriage-return at the end of line when doing a comparison.
512
513       --ignore-space-at-eol
514           Ignore changes in whitespace at EOL.
515
516       -b, --ignore-space-change
517           Ignore changes in amount of whitespace. This ignores whitespace at
518           line end, and considers all other sequences of one or more
519           whitespace characters to be equivalent.
520
521       -w, --ignore-all-space
522           Ignore whitespace when comparing lines. This ignores differences
523           even if one line has whitespace where the other line has none.
524
525       --ignore-blank-lines
526           Ignore changes whose lines are all blank.
527
528       --inter-hunk-context=<lines>
529           Show the context between diff hunks, up to the specified number of
530           lines, thereby fusing hunks that are close to each other. Defaults
531           to diff.interHunkContext or 0 if the config option is unset.
532
533       -W, --function-context
534           Show whole surrounding functions of changes.
535
536       --exit-code
537           Make the program exit with codes similar to diff(1). That is, it
538           exits with 1 if there were differences and 0 means no differences.
539
540       --quiet
541           Disable all output of the program. Implies --exit-code.
542
543       --ext-diff
544           Allow an external diff helper to be executed. If you set an
545           external diff driver with gitattributes(5), you need to use this
546           option with git-log(1) and friends.
547
548       --no-ext-diff
549           Disallow external diff drivers.
550
551       --textconv, --no-textconv
552           Allow (or disallow) external text conversion filters to be run when
553           comparing binary files. See gitattributes(5) for details. Because
554           textconv filters are typically a one-way conversion, the resulting
555           diff is suitable for human consumption, but cannot be applied. For
556           this reason, textconv filters are enabled by default only for git-
557           diff(1) and git-log(1), but not for git-format-patch(1) or diff
558           plumbing commands.
559
560       --ignore-submodules[=<when>]
561           Ignore changes to submodules in the diff generation. <when> can be
562           either "none", "untracked", "dirty" or "all", which is the default.
563           Using "none" will consider the submodule modified when it either
564           contains untracked or modified files or its HEAD differs from the
565           commit recorded in the superproject and can be used to override any
566           settings of the ignore option in git-config(1) or gitmodules(5).
567           When "untracked" is used submodules are not considered dirty when
568           they only contain untracked content (but they are still scanned for
569           modified content). Using "dirty" ignores all changes to the work
570           tree of submodules, only changes to the commits stored in the
571           superproject are shown (this was the behavior until 1.7.0). Using
572           "all" hides all changes to submodules.
573
574       --src-prefix=<prefix>
575           Show the given source prefix instead of "a/".
576
577       --dst-prefix=<prefix>
578           Show the given destination prefix instead of "b/".
579
580       --no-prefix
581           Do not show any source or destination prefix.
582
583       --line-prefix=<prefix>
584           Prepend an additional prefix to every line of output.
585
586       --ita-invisible-in-index
587           By default entries added by "git add -N" appear as an existing
588           empty file in "git diff" and a new file in "git diff --cached".
589           This option makes the entry appear as a new file in "git diff" and
590           non-existent in "git diff --cached". This option could be reverted
591           with --ita-visible-in-index. Both options are experimental and
592           could be removed in future.
593
594       For more detailed explanation on these common options, see also
595       gitdiffcore(7).
596
597       <tree-ish>
598           The id of a tree object to diff against.
599
600       --cached
601           do not consider the on-disk file at all
602
603       -m
604           By default, files recorded in the index but not checked out are
605           reported as deleted. This flag makes git diff-index say that all
606           non-checked-out files are up to date.
607

RAW OUTPUT FORMAT

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

DIFF FORMAT FOR MERGES

711       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
712       --cc option to generate diff output also for merge commits. The output
713       differs from the format described above in the following way:
714
715        1. there is a colon for each parent
716
717        2. there are more "src" modes and "src" sha1
718
719        3. status is concatenated status characters for each parent
720
721        4. no optional "score" number
722
723        5. single path, only for "dst"
724
725       Example:
726
727           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
728
729
730       Note that combined diff lists only files which were modified from all
731       parents.
732

GENERATING PATCHES WITH -P

734       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
735       with a -p option, "git diff" without the --raw option, or "git log"
736       with the "-p" option, they do not produce the output described above;
737       instead they produce a patch file. You can customize the creation of
738       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
739       environment variables.
740
741       What the -p option produces is slightly different from the traditional
742       diff format:
743
744        1. It is preceded with a "git diff" header that looks like this:
745
746               diff --git a/file1 b/file2
747
748           The a/ and b/ filenames are the same unless rename/copy is
749           involved. Especially, even for a creation or a deletion, /dev/null
750           is not used in place of the a/ or b/ filenames.
751
752           When rename/copy is involved, file1 and file2 show the name of the
753           source file of the rename/copy and the name of the file that
754           rename/copy produces, respectively.
755
756        2. It is followed by one or more extended header lines:
757
758               old mode <mode>
759               new mode <mode>
760               deleted file mode <mode>
761               new file mode <mode>
762               copy from <path>
763               copy to <path>
764               rename from <path>
765               rename to <path>
766               similarity index <number>
767               dissimilarity index <number>
768               index <hash>..<hash> <mode>
769
770           File modes are printed as 6-digit octal numbers including the file
771           type and file permission bits.
772
773           Path names in extended headers do not include the a/ and b/
774           prefixes.
775
776           The similarity index is the percentage of unchanged lines, and the
777           dissimilarity index is the percentage of changed lines. It is a
778           rounded down integer, followed by a percent sign. The similarity
779           index value of 100% is thus reserved for two equal files, while
780           100% dissimilarity means that no line from the old file made it
781           into the new one.
782
783           The index line includes the SHA-1 checksum before and after the
784           change. The <mode> is included if the file mode does not change;
785           otherwise, separate lines indicate the old and the new mode.
786
787        3. Pathnames with "unusual" characters are quoted as explained for the
788           configuration variable core.quotePath (see git-config(1)).
789
790        4. All the file1 files in the output refer to files before the commit,
791           and all the file2 files refer to files after the commit. It is
792           incorrect to apply each change to each file sequentially. For
793           example, this patch will swap a and b:
794
795               diff --git a/a b/b
796               rename from a
797               rename to b
798               diff --git a/b b/a
799               rename from b
800               rename to a
801

COMBINED DIFF FORMAT

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

OTHER DIFF FORMATS

909       The --summary option describes newly added, deleted, renamed and copied
910       files. The --stat option adds diffstat(1) graph to the output. These
911       options can be combined with other options, such as -p, and are meant
912       for human consumption.
913
914       When showing a change that involves a rename or a copy, --stat output
915       formats the pathnames compactly by combining common prefix and suffix
916       of the pathnames. For example, a change that moves arch/i386/Makefile
917       to arch/x86/Makefile while modifying 4 lines will be shown like this:
918
919           arch/{i386 => x86}/Makefile    |   4 +--
920
921
922       The --numstat option gives the diffstat(1) information but is designed
923       for easier machine consumption. An entry in --numstat output looks like
924       this:
925
926           1       2       README
927           3       1       arch/{i386 => x86}/Makefile
928
929
930       That is, from left to right:
931
932        1. the number of added lines;
933
934        2. a tab;
935
936        3. the number of deleted lines;
937
938        4. a tab;
939
940        5. pathname (possibly with rename/copy information);
941
942        6. a newline.
943
944       When -z output option is in effect, the output is formatted this way:
945
946           1       2       README NUL
947           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
948
949
950       That is:
951
952        1. the number of added lines;
953
954        2. a tab;
955
956        3. the number of deleted lines;
957
958        4. a tab;
959
960        5. a NUL (only exists if renamed/copied);
961
962        6. pathname in preimage;
963
964        7. a NUL (only exists if renamed/copied);
965
966        8. pathname in postimage (only exists if renamed/copied);
967
968        9. a NUL.
969
970       The extra NUL before the preimage path in renamed case is to allow
971       scripts that read the output to tell if the current record being read
972       is a single-path record or a rename/copy record without reading ahead.
973       After reading added and deleted lines, reading up to NUL would yield
974       the pathname, but if that is NUL, the record will show two paths.
975

OPERATING MODES

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

CACHED MODE

983       If --cached is specified, it allows you to ask:
984
985           show me the differences between HEAD and the current index
986           contents (the ones I'd write using 'git write-tree')
987
988       For example, let’s say that you have worked on your working directory,
989       updated some files in the index and are ready to commit. You want to
990       see exactly what you are going to commit, without having to write a new
991       tree object and compare it that way, and to do that, you just do
992
993           git diff-index --cached HEAD
994
995       Example: let’s say I had renamed commit.c to git-commit.c, and I had
996       done an update-index to make that effective in the index file. git
997       diff-files wouldn’t show anything at all, since the index file matches
998       my working directory. But doing a git diff-index does:
999
1000           torvalds@ppc970:~/git> git diff-index --cached HEAD
1001           -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
1002           +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
1003
1004       You can see easily that the above is a rename.
1005
1006       In fact, git diff-index --cached should always be entirely equivalent
1007       to actually doing a git write-tree and comparing that. Except this one
1008       is much nicer for the case where you just want to check where you are.
1009
1010       So doing a git diff-index --cached is basically very useful when you
1011       are asking yourself "what have I already marked for being committed,
1012       and what’s the difference to a previous tree".
1013

NON-CACHED MODE

1015       The "non-cached" mode takes a different approach, and is potentially
1016       the more useful of the two in that what it does can’t be emulated with
1017       a git write-tree + git diff-tree. Thus that’s the default mode. The
1018       non-cached version asks the question:
1019
1020           show me the differences between HEAD and the currently checked out
1021           tree - index contents _and_ files that aren't up to date
1022
1023       which is obviously a very useful question too, since that tells you
1024       what you could commit. Again, the output matches the git diff-tree -r
1025       output to a tee, but with a twist.
1026
1027       The twist is that if some file doesn’t match the index, we don’t have a
1028       backing store thing for it, and we use the magic "all-zero" sha1 to
1029       show that. So let’s say that you have edited kernel/sched.c, but have
1030       not actually done a git update-index on it yet - there is no "object"
1031       associated with the new state, and you get:
1032
1033           torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
1034           :100644 100664 7476bb... 000000...      kernel/sched.c
1035
1036       i.e., it shows that the tree has changed, and that kernel/sched.c is
1037       not up to date and may contain new stuff. The all-zero sha1 means that
1038       to get the real diff, you need to look at the object in the working
1039       directory directly rather than do an object-to-object diff.
1040
1041           Note
1042           As with other commands of this type, git diff-index does not
1043           actually look at the contents of the file at all. So maybe
1044           kernel/sched.c hasn’t actually changed, and it’s just that you
1045           touched it. In either case, it’s a note that you need to git
1046           update-index it to make the index be in sync.
1047
1048           Note
1049           You can have a mixture of files show up as "has been updated" and
1050           "is still dirty in the working directory" together. You can always
1051           tell which file is in which state, since the "has been updated"
1052           ones show a valid sha1, and the "not in sync with the index" ones
1053           will always have the special all-zero sha1.
1054

GIT

1056       Part of the git(1) suite
1057
1058
1059
1060Git 2.18.1                        05/14/2019                 GIT-DIFF-INDEX(1)
Impressum