1GIT-DIFF-INDEX(1) Git Manual GIT-DIFF-INDEX(1)
2
3
4
6 git-diff-index - Compare a tree to the working tree or index
7
9 git diff-index [-m] [--cached] [--merge-base] [<common-diff-options>] <tree-ish> [<path>...]
10
12 Compare the content and mode of the blobs found in a tree object with
13 the corresponding tracked files in the working tree, or with the
14 corresponding paths in the index. When <path> arguments are present,
15 compare only paths matching those patterns. Otherwise all tracked files
16 are compared.
17
19 -p, -u, --patch
20 Generate patch (see the section called “GENERATING PATCH TEXT WITH
21 -P”).
22
23 -s, --no-patch
24 Suppress all output from the diff machinery. Useful for commands
25 like git show that show the patch by default to squelch their
26 output, or to cancel the effect of options like --patch, --stat
27 earlier on the command line in an alias.
28
29 -U<n>, --unified=<n>
30 Generate diffs with <n> lines of context instead of the usual
31 three. Implies --patch.
32
33 --output=<file>
34 Output to a specific file instead of stdout.
35
36 --output-indicator-new=<char>, --output-indicator-old=<char>,
37 --output-indicator-context=<char>
38 Specify the character used to indicate new, old or context lines in
39 the generated patch. Normally they are +, - and ' ' respectively.
40
41 --raw
42 Generate the diff in raw format. This is the default.
43
44 --patch-with-raw
45 Synonym for -p --raw.
46
47 --indent-heuristic
48 Enable the heuristic that shifts diff hunk boundaries to make
49 patches easier to read. This is the default.
50
51 --no-indent-heuristic
52 Disable the indent heuristic.
53
54 --minimal
55 Spend extra time to make sure the smallest possible diff is
56 produced.
57
58 --patience
59 Generate a diff using the "patience diff" algorithm.
60
61 --histogram
62 Generate a diff using the "histogram diff" algorithm.
63
64 --anchored=<text>
65 Generate a diff using the "anchored diff" algorithm.
66
67 This option may be specified more than once.
68
69 If a line exists in both the source and destination, exists only
70 once, and starts with this text, this algorithm attempts to prevent
71 it from appearing as a deletion or addition in the output. It uses
72 the "patience diff" algorithm internally.
73
74 --diff-algorithm={patience|minimal|histogram|myers}
75 Choose a diff algorithm. The variants are as follows:
76
77 default, myers
78 The basic greedy diff algorithm. Currently, this is the
79 default.
80
81 minimal
82 Spend extra time to make sure the smallest possible diff is
83 produced.
84
85 patience
86 Use "patience diff" algorithm when generating patches.
87
88 histogram
89 This algorithm extends the patience algorithm to "support
90 low-occurrence common elements".
91
92 For instance, if you configured the diff.algorithm variable to a
93 non-default value and want to use the default one, then you have to
94 use --diff-algorithm=default option.
95
96 --stat[=<width>[,<name-width>[,<count>]]]
97 Generate a diffstat. By default, as much space as necessary will be
98 used for the filename part, and the rest for the graph part.
99 Maximum width defaults to terminal width, or 80 columns if not
100 connected to a terminal, and can be overridden by <width>. The
101 width of the filename part can be limited by giving another width
102 <name-width> after a comma or by setting
103 diff.statNameWidth=<width>. The width of the graph part can be
104 limited by using --stat-graph-width=<width> or by setting
105 diff.statGraphWidth=<width>. Using --stat or --stat-graph-width
106 affects all commands generating a stat graph, while setting
107 diff.statNameWidth or diff.statGraphWidth does not affect git
108 format-patch. By giving a third parameter <count>, you can limit
109 the output to the first <count> lines, followed by ... if there
110 are more.
111
112 These parameters can also be set individually with
113 --stat-width=<width>, --stat-name-width=<name-width> and
114 --stat-count=<count>.
115
116 --compact-summary
117 Output a condensed summary of extended header information such as
118 file creations or deletions ("new" or "gone", optionally "+l" if
119 it’s a symlink) and mode changes ("+x" or "-x" for adding or
120 removing executable bit respectively) in diffstat. The information
121 is put between the filename part and the graph part. Implies
122 --stat.
123
124 --numstat
125 Similar to --stat, but shows number of added and deleted lines in
126 decimal notation and pathname without abbreviation, to make it more
127 machine friendly. For binary files, outputs two - instead of saying
128 0 0.
129
130 --shortstat
131 Output only the last line of the --stat format containing total
132 number of modified files, as well as number of added and deleted
133 lines.
134
135 -X[<param1,param2,...>], --dirstat[=<param1,param2,...>]
136 Output the distribution of relative amount of changes for each
137 sub-directory. The behavior of --dirstat can be customized by
138 passing it a comma separated list of parameters. The defaults are
139 controlled by the diff.dirstat configuration variable (see git-
140 config(1)). The following parameters are available:
141
142 changes
143 Compute the dirstat numbers by counting the lines that have
144 been removed from the source, or added to the destination. This
145 ignores the amount of pure code movements within a file. In
146 other words, rearranging lines in a file is not counted as much
147 as other changes. This is the default behavior when no
148 parameter is given.
149
150 lines
151 Compute the dirstat numbers by doing the regular line-based
152 diff analysis, and summing the removed/added line counts. (For
153 binary files, count 64-byte chunks instead, since binary files
154 have no natural concept of lines). This is a more expensive
155 --dirstat behavior than the changes behavior, but it does count
156 rearranged lines within a file as much as other changes. The
157 resulting output is consistent with what you get from the other
158 --*stat options.
159
160 files
161 Compute the dirstat numbers by counting the number of files
162 changed. Each changed file counts equally in the dirstat
163 analysis. This is the computationally cheapest --dirstat
164 behavior, since it does not have to look at the file contents
165 at all.
166
167 cumulative
168 Count changes in a child directory for the parent directory as
169 well. Note that when using cumulative, the sum of the
170 percentages reported may exceed 100%. The default
171 (non-cumulative) behavior can be specified with the
172 noncumulative parameter.
173
174 <limit>
175 An integer parameter specifies a cut-off percent (3% by
176 default). Directories contributing less than this percentage of
177 the changes are not shown in the output.
178
179 Example: The following will count changed files, while ignoring
180 directories with less than 10% of the total amount of changed
181 files, and accumulating child directory counts in the parent
182 directories: --dirstat=files,10,cumulative.
183
184 --cumulative
185 Synonym for --dirstat=cumulative
186
187 --dirstat-by-file[=<param1,param2>...]
188 Synonym for --dirstat=files,param1,param2...
189
190 --summary
191 Output a condensed summary of extended header information such as
192 creations, renames and mode changes.
193
194 --patch-with-stat
195 Synonym for -p --stat.
196
197 -z
198 When --raw, --numstat, --name-only or --name-status has been given,
199 do not munge pathnames and use NULs as output field terminators.
200
201 Without this option, pathnames with "unusual" characters are quoted
202 as explained for the configuration variable core.quotePath (see
203 git-config(1)).
204
205 --name-only
206 Show only names of changed files. The file names are often encoded
207 in UTF-8. For more information see the discussion about encoding in
208 the git-log(1) manual page.
209
210 --name-status
211 Show only names and status of changed files. See the description of
212 the --diff-filter option on what the status letters mean. Just like
213 --name-only the file names are often encoded in UTF-8.
214
215 --submodule[=<format>]
216 Specify how differences in submodules are shown. When specifying
217 --submodule=short the short format is used. This format just shows
218 the names of the commits at the beginning and end of the range.
219 When --submodule or --submodule=log is specified, the log format is
220 used. This format lists the commits in the range like git-
221 submodule(1) summary does. When --submodule=diff is specified, the
222 diff format is used. This format shows an inline diff of the
223 changes in the submodule contents between the commit range.
224 Defaults to diff.submodule or the short format if the config option
225 is unset.
226
227 --color[=<when>]
228 Show colored diff. --color (i.e. without =<when>) is the same as
229 --color=always. <when> can be one of always, never, or auto.
230
231 --no-color
232 Turn off colored diff. It is the same as --color=never.
233
234 --color-moved[=<mode>]
235 Moved lines of code are colored differently. The <mode> defaults to
236 no if the option is not given and to zebra if the option with no
237 mode is given. The mode must be one of:
238
239 no
240 Moved lines are not highlighted.
241
242 default
243 Is a synonym for zebra. This may change to a more sensible mode
244 in the future.
245
246 plain
247 Any line that is added in one location and was removed in
248 another location will be colored with color.diff.newMoved.
249 Similarly color.diff.oldMoved will be used for removed lines
250 that are added somewhere else in the diff. This mode picks up
251 any moved line, but it is not very useful in a review to
252 determine if a block of code was moved without permutation.
253
254 blocks
255 Blocks of moved text of at least 20 alphanumeric characters are
256 detected greedily. The detected blocks are painted using either
257 the color.diff.{old,new}Moved color. Adjacent blocks cannot be
258 told apart.
259
260 zebra
261 Blocks of moved text are detected as in blocks mode. The blocks
262 are painted using either the color.diff.{old,new}Moved color or
263 color.diff.{old,new}MovedAlternative. The change between the
264 two colors indicates that a new block was detected.
265
266 dimmed-zebra
267 Similar to zebra, but additional dimming of uninteresting parts
268 of moved code is performed. The bordering lines of two adjacent
269 blocks are considered interesting, the rest is uninteresting.
270 dimmed_zebra is a deprecated synonym.
271
272 --no-color-moved
273 Turn off move detection. This can be used to override configuration
274 settings. It is the same as --color-moved=no.
275
276 --color-moved-ws=<modes>
277 This configures how whitespace is ignored when performing the move
278 detection for --color-moved. These modes can be given as a comma
279 separated list:
280
281 no
282 Do not ignore whitespace when performing move detection.
283
284 ignore-space-at-eol
285 Ignore changes in whitespace at EOL.
286
287 ignore-space-change
288 Ignore changes in amount of whitespace. This ignores whitespace
289 at line end, and considers all other sequences of one or more
290 whitespace characters to be equivalent.
291
292 ignore-all-space
293 Ignore whitespace when comparing lines. This ignores
294 differences even if one line has whitespace where the other
295 line has none.
296
297 allow-indentation-change
298 Initially ignore any whitespace in the move detection, then
299 group the moved code blocks only into a block if the change in
300 whitespace is the same per line. This is incompatible with the
301 other modes.
302
303 --no-color-moved-ws
304 Do not ignore whitespace when performing move detection. This can
305 be used to override configuration settings. It is the same as
306 --color-moved-ws=no.
307
308 --word-diff[=<mode>]
309 Show a word diff, using the <mode> to delimit changed words. By
310 default, words are delimited by whitespace; see --word-diff-regex
311 below. The <mode> defaults to plain, and must be one of:
312
313 color
314 Highlight changed words using only colors. Implies --color.
315
316 plain
317 Show words as [-removed-] and {+added+}. Makes no attempts to
318 escape the delimiters if they appear in the input, so the
319 output may be ambiguous.
320
321 porcelain
322 Use a special line-based format intended for script
323 consumption. Added/removed/unchanged runs are printed in the
324 usual unified diff format, starting with a +/-/` ` character at
325 the beginning of the line and extending to the end of the line.
326 Newlines in the input are represented by a tilde ~ on a line of
327 its own.
328
329 none
330 Disable word diff again.
331
332 Note that despite the name of the first mode, color is used to
333 highlight the changed parts in all modes if enabled.
334
335 --word-diff-regex=<regex>
336 Use <regex> to decide what a word is, instead of considering runs
337 of non-whitespace to be a word. Also implies --word-diff unless it
338 was already enabled.
339
340 Every non-overlapping match of the <regex> is considered a word.
341 Anything between these matches is considered whitespace and
342 ignored(!) for the purposes of finding differences. You may want to
343 append |[^[:space:]] to your regular expression to make sure that
344 it matches all non-whitespace characters. A match that contains a
345 newline is silently truncated(!) at the newline.
346
347 For example, --word-diff-regex=. will treat each character as a
348 word and, correspondingly, show differences character by character.
349
350 The regex can also be set via a diff driver or configuration
351 option, see gitattributes(5) or git-config(1). Giving it explicitly
352 overrides any diff driver or configuration setting. Diff drivers
353 override configuration settings.
354
355 --color-words[=<regex>]
356 Equivalent to --word-diff=color plus (if a regex was specified)
357 --word-diff-regex=<regex>.
358
359 --no-renames
360 Turn off rename detection, even when the configuration file gives
361 the default to do so.
362
363 --[no-]rename-empty
364 Whether to use empty blobs as rename source.
365
366 --check
367 Warn if changes introduce conflict markers or whitespace errors.
368 What are considered whitespace errors is controlled by
369 core.whitespace configuration. By default, trailing whitespaces
370 (including lines that consist solely of whitespaces) and a space
371 character that is immediately followed by a tab character inside
372 the initial indent of the line are considered whitespace errors.
373 Exits with non-zero status if problems are found. Not compatible
374 with --exit-code.
375
376 --ws-error-highlight=<kind>
377 Highlight whitespace errors in the context, old or new lines of the
378 diff. Multiple values are separated by comma, none resets previous
379 values, default reset the list to new and all is a shorthand for
380 old,new,context. When this option is not given, and the
381 configuration variable diff.wsErrorHighlight is not set, only
382 whitespace errors in new lines are highlighted. The whitespace
383 errors are colored with color.diff.whitespace.
384
385 --full-index
386 Instead of the first handful of characters, show the full pre- and
387 post-image blob object names on the "index" line when generating
388 patch format output.
389
390 --binary
391 In addition to --full-index, output a binary diff that can be
392 applied with git-apply. Implies --patch.
393
394 --abbrev[=<n>]
395 Instead of showing the full 40-byte hexadecimal object name in
396 diff-raw format output and diff-tree header lines, show the
397 shortest prefix that is at least <n> hexdigits long that uniquely
398 refers the object. In diff-patch output format, --full-index takes
399 higher precedence, i.e. if --full-index is specified, full blob
400 names will be shown regardless of --abbrev. Non default number of
401 digits can be specified with --abbrev=<n>.
402
403 -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
404 Break complete rewrite changes into pairs of delete and create.
405 This serves two purposes:
406
407 It affects the way a change that amounts to a total rewrite of a
408 file not as a series of deletion and insertion mixed together with
409 a very few lines that happen to match textually as the context, but
410 as a single deletion of everything old followed by a single
411 insertion of everything new, and the number m controls this aspect
412 of the -B option (defaults to 60%). -B/70% specifies that less
413 than 30% of the original should remain in the result for Git to
414 consider it a total rewrite (i.e. otherwise the resulting patch
415 will be a series of deletion and insertion mixed together with
416 context lines).
417
418 When used with -M, a totally-rewritten file is also considered as
419 the source of a rename (usually -M only considers a file that
420 disappeared as the source of a rename), and the number n controls
421 this aspect of the -B option (defaults to 50%). -B20% specifies
422 that a change with addition and deletion compared to 20% or more of
423 the file’s size are eligible for being picked up as a possible
424 source of a rename to another file.
425
426 -M[<n>], --find-renames[=<n>]
427 Detect renames. If n is specified, it is a threshold on the
428 similarity index (i.e. amount of addition/deletions compared to the
429 file’s size). For example, -M90% means Git should consider a
430 delete/add pair to be a rename if more than 90% of the file hasn’t
431 changed. Without a % sign, the number is to be read as a fraction,
432 with a decimal point before it. I.e., -M5 becomes 0.5, and is thus
433 the same as -M50%. Similarly, -M05 is the same as -M5%. To limit
434 detection to exact renames, use -M100%. The default similarity
435 index is 50%.
436
437 -C[<n>], --find-copies[=<n>]
438 Detect copies as well as renames. See also --find-copies-harder. If
439 n is specified, it has the same meaning as for -M<n>.
440
441 --find-copies-harder
442 For performance reasons, by default, -C option finds copies only if
443 the original file of the copy was modified in the same changeset.
444 This flag makes the command inspect unmodified files as candidates
445 for the source of copy. This is a very expensive operation for
446 large projects, so use it with caution. Giving more than one -C
447 option has the same effect.
448
449 -D, --irreversible-delete
450 Omit the preimage for deletes, i.e. print only the header but not
451 the diff between the preimage and /dev/null. The resulting patch is
452 not meant to be applied with patch or git apply; this is solely for
453 people who want to just concentrate on reviewing the text after the
454 change. In addition, the output obviously lacks enough information
455 to apply such a patch in reverse, even manually, hence the name of
456 the option.
457
458 When used together with -B, omit also the preimage in the deletion
459 part of a delete/create pair.
460
461 -l<num>
462 The -M and -C options involve some preliminary steps that can
463 detect subsets of renames/copies cheaply, followed by an exhaustive
464 fallback portion that compares all remaining unpaired destinations
465 to all relevant sources. (For renames, only remaining unpaired
466 sources are relevant; for copies, all original sources are
467 relevant.) For N sources and destinations, this exhaustive check is
468 O(N^2). This option prevents the exhaustive portion of rename/copy
469 detection from running if the number of source/destination files
470 involved exceeds the specified number. Defaults to
471 diff.renameLimit. Note that a value of 0 is treated as unlimited.
472
473 --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
474 Select only files that are Added (A), Copied (C), Deleted (D),
475 Modified (M), Renamed (R), have their type (i.e. regular file,
476 symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
477 (X), or have had their pairing Broken (B). Any combination of the
478 filter characters (including none) can be used. When *
479 (All-or-none) is added to the combination, all paths are selected
480 if there is any file that matches other criteria in the comparison;
481 if there is no file that matches other criteria, nothing is
482 selected.
483
484 Also, these upper-case letters can be downcased to exclude. E.g.
485 --diff-filter=ad excludes added and deleted paths.
486
487 Note that not all diffs can feature all types. For instance, copied
488 and renamed entries cannot appear if detection for those types is
489 disabled.
490
491 -S<string>
492 Look for differences that change the number of occurrences of the
493 specified string (i.e. addition/deletion) in a file. Intended for
494 the scripter’s use.
495
496 It is useful when you’re looking for an exact block of code (like a
497 struct), and want to know the history of that block since it first
498 came into being: use the feature iteratively to feed the
499 interesting block in the preimage back into -S, and keep going
500 until you get the very first version of the block.
501
502 Binary files are searched as well.
503
504 -G<regex>
505 Look for differences whose patch text contains added/removed lines
506 that match <regex>.
507
508 To illustrate the difference between -S<regex> --pickaxe-regex and
509 -G<regex>, consider a commit with the following diff in the same
510 file:
511
512 + return frotz(nitfol, two->ptr, 1, 0);
513 ...
514 - hit = frotz(nitfol, mf2.ptr, 1, 0);
515
516 While git log -G"frotz\(nitfol" will show this commit, git log
517 -S"frotz\(nitfol" --pickaxe-regex will not (because the number of
518 occurrences of that string did not change).
519
520 Unless --text is supplied patches of binary files without a
521 textconv filter will be ignored.
522
523 See the pickaxe entry in gitdiffcore(7) for more information.
524
525 --find-object=<object-id>
526 Look for differences that change the number of occurrences of the
527 specified object. Similar to -S, just the argument is different in
528 that it doesn’t search for a specific string but for a specific
529 object id.
530
531 The object can be a blob or a submodule commit. It implies the -t
532 option in git-log to also find trees.
533
534 --pickaxe-all
535 When -S or -G finds a change, show all the changes in that
536 changeset, not just the files that contain the change in <string>.
537
538 --pickaxe-regex
539 Treat the <string> given to -S as an extended POSIX regular
540 expression to match.
541
542 -O<orderfile>
543 Control the order in which files appear in the output. This
544 overrides the diff.orderFile configuration variable (see git-
545 config(1)). To cancel diff.orderFile, use -O/dev/null.
546
547 The output order is determined by the order of glob patterns in
548 <orderfile>. All files with pathnames that match the first pattern
549 are output first, all files with pathnames that match the second
550 pattern (but not the first) are output next, and so on. All files
551 with pathnames that do not match any pattern are output last, as if
552 there was an implicit match-all pattern at the end of the file. If
553 multiple pathnames have the same rank (they match the same pattern
554 but no earlier patterns), their output order relative to each other
555 is the normal order.
556
557 <orderfile> is parsed as follows:
558
559 • Blank lines are ignored, so they can be used as separators for
560 readability.
561
562 • Lines starting with a hash ("#") are ignored, so they can be
563 used for comments. Add a backslash ("\") to the beginning of
564 the pattern if it starts with a hash.
565
566 • Each other line contains a single pattern.
567
568 Patterns have the same syntax and semantics as patterns used for
569 fnmatch(3) without the FNM_PATHNAME flag, except a pathname also
570 matches a pattern if removing any number of the final pathname
571 components matches the pattern. For example, the pattern "foo*bar"
572 matches "fooasdfbar" and "foo/bar/baz/asdf" but not "foobarx".
573
574 --skip-to=<file>, --rotate-to=<file>
575 Discard the files before the named <file> from the output (i.e.
576 skip to), or move them to the end of the output (i.e. rotate to).
577 These options were invented primarily for the use of the git
578 difftool command, and may not be very useful otherwise.
579
580 -R
581 Swap two inputs; that is, show differences from index or on-disk
582 file to tree contents.
583
584 --relative[=<path>], --no-relative
585 When run from a subdirectory of the project, it can be told to
586 exclude changes outside the directory and show pathnames relative
587 to it with this option. When you are not in a subdirectory (e.g. in
588 a bare repository), you can name which subdirectory to make the
589 output relative to by giving a <path> as an argument.
590 --no-relative can be used to countermand both diff.relative config
591 option and previous --relative.
592
593 -a, --text
594 Treat all files as text.
595
596 --ignore-cr-at-eol
597 Ignore carriage-return at the end of line when doing a comparison.
598
599 --ignore-space-at-eol
600 Ignore changes in whitespace at EOL.
601
602 -b, --ignore-space-change
603 Ignore changes in amount of whitespace. This ignores whitespace at
604 line end, and considers all other sequences of one or more
605 whitespace characters to be equivalent.
606
607 -w, --ignore-all-space
608 Ignore whitespace when comparing lines. This ignores differences
609 even if one line has whitespace where the other line has none.
610
611 --ignore-blank-lines
612 Ignore changes whose lines are all blank.
613
614 -I<regex>, --ignore-matching-lines=<regex>
615 Ignore changes whose all lines match <regex>. This option may be
616 specified more than once.
617
618 --inter-hunk-context=<lines>
619 Show the context between diff hunks, up to the specified number of
620 lines, thereby fusing hunks that are close to each other. Defaults
621 to diff.interHunkContext or 0 if the config option is unset.
622
623 -W, --function-context
624 Show whole function as context lines for each change. The function
625 names are determined in the same way as git diff works out patch
626 hunk headers (see Defining a custom hunk-header in
627 gitattributes(5)).
628
629 --exit-code
630 Make the program exit with codes similar to diff(1). That is, it
631 exits with 1 if there were differences and 0 means no differences.
632
633 --quiet
634 Disable all output of the program. Implies --exit-code.
635
636 --ext-diff
637 Allow an external diff helper to be executed. If you set an
638 external diff driver with gitattributes(5), you need to use this
639 option with git-log(1) and friends.
640
641 --no-ext-diff
642 Disallow external diff drivers.
643
644 --textconv, --no-textconv
645 Allow (or disallow) external text conversion filters to be run when
646 comparing binary files. See gitattributes(5) for details. Because
647 textconv filters are typically a one-way conversion, the resulting
648 diff is suitable for human consumption, but cannot be applied. For
649 this reason, textconv filters are enabled by default only for git-
650 diff(1) and git-log(1), but not for git-format-patch(1) or diff
651 plumbing commands.
652
653 --ignore-submodules[=<when>]
654 Ignore changes to submodules in the diff generation. <when> can be
655 either "none", "untracked", "dirty" or "all", which is the default.
656 Using "none" will consider the submodule modified when it either
657 contains untracked or modified files or its HEAD differs from the
658 commit recorded in the superproject and can be used to override any
659 settings of the ignore option in git-config(1) or gitmodules(5).
660 When "untracked" is used submodules are not considered dirty when
661 they only contain untracked content (but they are still scanned for
662 modified content). Using "dirty" ignores all changes to the work
663 tree of submodules, only changes to the commits stored in the
664 superproject are shown (this was the behavior until 1.7.0). Using
665 "all" hides all changes to submodules.
666
667 --src-prefix=<prefix>
668 Show the given source prefix instead of "a/".
669
670 --dst-prefix=<prefix>
671 Show the given destination prefix instead of "b/".
672
673 --no-prefix
674 Do not show any source or destination prefix.
675
676 --default-prefix
677 Use the default source and destination prefixes ("a/" and "b/").
678 This is usually the default already, but may be used to override
679 config such as diff.noprefix.
680
681 --line-prefix=<prefix>
682 Prepend an additional prefix to every line of output.
683
684 --ita-invisible-in-index
685 By default entries added by "git add -N" appear as an existing
686 empty file in "git diff" and a new file in "git diff --cached".
687 This option makes the entry appear as a new file in "git diff" and
688 non-existent in "git diff --cached". This option could be reverted
689 with --ita-visible-in-index. Both options are experimental and
690 could be removed in future.
691
692 For more detailed explanation on these common options, see also
693 gitdiffcore(7).
694
695 <tree-ish>
696 The id of a tree object to diff against.
697
698 --cached
699 Do not consider the on-disk file at all.
700
701 --merge-base
702 Instead of comparing <tree-ish> directly, use the merge base
703 between <tree-ish> and HEAD instead. <tree-ish> must be a commit.
704
705 -m
706 By default, files recorded in the index but not checked out are
707 reported as deleted. This flag makes git diff-index say that all
708 non-checked-out files are up to date.
709
711 The raw output format from "git-diff-index", "git-diff-tree",
712 "git-diff-files" and "git diff --raw" are very similar.
713
714 These commands all compare two sets of things; what is compared
715 differs:
716
717 git-diff-index <tree-ish>
718 compares the <tree-ish> and the files on the filesystem.
719
720 git-diff-index --cached <tree-ish>
721 compares the <tree-ish> and the index.
722
723 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
724 compares the trees named by the two arguments.
725
726 git-diff-files [<pattern>...]
727 compares the index and the files on the filesystem.
728
729 The "git-diff-tree" command begins its output by printing the hash of
730 what is being compared. After that, all the commands print one output
731 line per changed file.
732
733 An output line is formatted this way:
734
735 in-place edit :100644 100644 bcd1234 0123456 M file0
736 copy-edit :100644 100644 abcd123 1234567 C68 file1 file2
737 rename-edit :100644 100644 abcd123 1234567 R86 file1 file3
738 create :000000 100644 0000000 1234567 A file4
739 delete :100644 000000 1234567 0000000 D file5
740 unmerged :000000 000000 0000000 0000000 U file6
741
742 That is, from the left to the right:
743
744 1. a colon.
745
746 2. mode for "src"; 000000 if creation or unmerged.
747
748 3. a space.
749
750 4. mode for "dst"; 000000 if deletion or unmerged.
751
752 5. a space.
753
754 6. sha1 for "src"; 0{40} if creation or unmerged.
755
756 7. a space.
757
758 8. sha1 for "dst"; 0{40} if deletion, unmerged or "work tree out of
759 sync with the index".
760
761 9. a space.
762
763 10. status, followed by optional "score" number.
764
765 11. a tab or a NUL when -z option is used.
766
767 12. path for "src"
768
769 13. a tab or a NUL when -z option is used; only exists for C or R.
770
771 14. path for "dst"; only exists for C or R.
772
773 15. an LF or a NUL when -z option is used, to terminate the record.
774
775 Possible status letters are:
776
777 • A: addition of a file
778
779 • C: copy of a file into a new one
780
781 • D: deletion of a file
782
783 • M: modification of the contents or mode of a file
784
785 • R: renaming of a file
786
787 • T: change in the type of the file (regular file, symbolic link or
788 submodule)
789
790 • U: file is unmerged (you must complete the merge before it can be
791 committed)
792
793 • X: "unknown" change type (most probably a bug, please report it)
794
795 Status letters C and R are always followed by a score (denoting the
796 percentage of similarity between the source and target of the move or
797 copy). Status letter M may be followed by a score (denoting the
798 percentage of dissimilarity) for file rewrites.
799
800 The sha1 for "dst" is shown as all 0’s if a file on the filesystem is
801 out of sync with the index.
802
803 Example:
804
805 :100644 100644 5be4a4a 0000000 M file.c
806
807 Without the -z option, pathnames with "unusual" characters are quoted
808 as explained for the configuration variable core.quotePath (see git-
809 config(1)). Using -z the filename is output verbatim and the line is
810 terminated by a NUL byte.
811
813 "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
814 --cc option to generate diff output also for merge commits. The output
815 differs from the format described above in the following way:
816
817 1. there is a colon for each parent
818
819 2. there are more "src" modes and "src" sha1
820
821 3. status is concatenated status characters for each parent
822
823 4. no optional "score" number
824
825 5. tab-separated pathname(s) of the file
826
827 For -c and --cc, only the destination or final path is shown even if
828 the file was renamed on any side of history. With --combined-all-paths,
829 the name of the path in each parent is shown followed by the name of
830 the path in the merge commit.
831
832 Examples for -c and --cc without --combined-all-paths:
833
834 ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c
835 ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM bar.sh
836 ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR phooey.c
837
838 Examples when --combined-all-paths added to either -c or --cc:
839
840 ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c desc.c desc.c
841 ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM foo.sh bar.sh bar.sh
842 ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR fooey.c fuey.c phooey.c
843
844 Note that combined diff lists only files which were modified from all
845 parents.
846
848 Running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-
849 diff-tree(1), or git-diff-files(1) with the -p option produces patch
850 text. You can customize the creation of patch text via the
851 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables (see
852 git(1)), and the diff attribute (see gitattributes(5)).
853
854 What the -p option produces is slightly different from the traditional
855 diff format:
856
857 1. It is preceded by a "git diff" header that looks like this:
858
859 diff --git a/file1 b/file2
860
861 The a/ and b/ filenames are the same unless rename/copy is
862 involved. Especially, even for a creation or a deletion, /dev/null
863 is not used in place of the a/ or b/ filenames.
864
865 When a rename/copy is involved, file1 and file2 show the name of
866 the source file of the rename/copy and the name of the file that
867 the rename/copy produces, respectively.
868
869 2. It is followed by one or more extended header lines:
870
871 old mode <mode>
872 new mode <mode>
873 deleted file mode <mode>
874 new file mode <mode>
875 copy from <path>
876 copy to <path>
877 rename from <path>
878 rename to <path>
879 similarity index <number>
880 dissimilarity index <number>
881 index <hash>..<hash> <mode>
882
883 File modes are printed as 6-digit octal numbers including the file
884 type and file permission bits.
885
886 Path names in extended headers do not include the a/ and b/
887 prefixes.
888
889 The similarity index is the percentage of unchanged lines, and the
890 dissimilarity index is the percentage of changed lines. It is a
891 rounded down integer, followed by a percent sign. The similarity
892 index value of 100% is thus reserved for two equal files, while
893 100% dissimilarity means that no line from the old file made it
894 into the new one.
895
896 The index line includes the blob object names before and after the
897 change. The <mode> is included if the file mode does not change;
898 otherwise, separate lines indicate the old and the new mode.
899
900 3. Pathnames with "unusual" characters are quoted as explained for the
901 configuration variable core.quotePath (see git-config(1)).
902
903 4. All the file1 files in the output refer to files before the commit,
904 and all the file2 files refer to files after the commit. It is
905 incorrect to apply each change to each file sequentially. For
906 example, this patch will swap a and b:
907
908 diff --git a/a b/b
909 rename from a
910 rename to b
911 diff --git a/b b/a
912 rename from b
913 rename to a
914
915 5. Hunk headers mention the name of the function to which the hunk
916 applies. See "Defining a custom hunk-header" in gitattributes(5)
917 for details of how to tailor this to specific languages.
918
920 Any diff-generating command can take the -c or --cc option to produce a
921 combined diff when showing a merge. This is the default format when
922 showing merges with git-diff(1) or git-show(1). Note also that you can
923 give suitable --diff-merges option to any of these commands to force
924 generation of diffs in a specific format.
925
926 A "combined diff" format looks like this:
927
928 diff --combined describe.c
929 index fabadb8,cc95eb0..4866510
930 --- a/describe.c
931 +++ b/describe.c
932 @@@ -98,20 -98,12 +98,20 @@@
933 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
934 }
935
936 - static void describe(char *arg)
937 -static void describe(struct commit *cmit, int last_one)
938 ++static void describe(char *arg, int last_one)
939 {
940 + unsigned char sha1[20];
941 + struct commit *cmit;
942 struct commit_list *list;
943 static int initialized = 0;
944 struct commit_name *n;
945
946 + if (get_sha1(arg, sha1) < 0)
947 + usage(describe_usage);
948 + cmit = lookup_commit_reference(sha1);
949 + if (!cmit)
950 + usage(describe_usage);
951 +
952 if (!initialized) {
953 initialized = 1;
954 for_each_ref(get_name);
955
956 1. It is preceded by a "git diff" header, that looks like this (when
957 the -c option is used):
958
959 diff --combined file
960
961 or like this (when the --cc option is used):
962
963 diff --cc file
964
965 2. It is followed by one or more extended header lines (this example
966 shows a merge with two parents):
967
968 index <hash>,<hash>..<hash>
969 mode <mode>,<mode>..<mode>
970 new file mode <mode>
971 deleted file mode <mode>,<mode>
972
973 The mode <mode>,<mode>..<mode> line appears only if at least one of
974 the <mode> is different from the rest. Extended headers with
975 information about detected content movement (renames and copying
976 detection) are designed to work with the diff of two <tree-ish> and
977 are not used by combined diff format.
978
979 3. It is followed by a two-line from-file/to-file header:
980
981 --- a/file
982 +++ b/file
983
984 Similar to the two-line header for the traditional unified diff
985 format, /dev/null is used to signal created or deleted files.
986
987 However, if the --combined-all-paths option is provided, instead of
988 a two-line from-file/to-file, you get an N+1 line from-file/to-file
989 header, where N is the number of parents in the merge commit:
990
991 --- a/file
992 --- a/file
993 --- a/file
994 +++ b/file
995
996 This extended format can be useful if rename or copy detection is
997 active, to allow you to see the original name of the file in
998 different parents.
999
1000 4. Chunk header format is modified to prevent people from accidentally
1001 feeding it to patch -p1. Combined diff format was created for
1002 review of merge commit changes, and was not meant to be applied.
1003 The change is similar to the change in the extended index header:
1004
1005 @@@ <from-file-range> <from-file-range> <to-file-range> @@@
1006
1007 There are (number of parents + 1) @ characters in the chunk header
1008 for combined diff format.
1009
1010 Unlike the traditional unified diff format, which shows two files A and
1011 B with a single column that has - (minus — appears in A but removed in
1012 B), + (plus — missing in A but added to B), or " " (space — unchanged)
1013 prefix, this format compares two or more files file1, file2,... with
1014 one file X, and shows how X differs from each of fileN. One column for
1015 each of fileN is prepended to the output line to note how X’s line is
1016 different from it.
1017
1018 A - character in the column N means that the line appears in fileN but
1019 it does not appear in the result. A + character in the column N means
1020 that the line appears in the result, and fileN does not have that line
1021 (in other words, the line was added, from the point of view of that
1022 parent).
1023
1024 In the above example output, the function signature was changed from
1025 both files (hence two - removals from both file1 and file2, plus ++ to
1026 mean one line that was added does not appear in either file1 or file2).
1027 Also, eight other lines are the same from file1 but do not appear in
1028 file2 (hence prefixed with +).
1029
1030 When shown by git diff-tree -c, it compares the parents of a merge
1031 commit with the merge result (i.e. file1..fileN are the parents). When
1032 shown by git diff-files -c, it compares the two unresolved merge
1033 parents with the working tree file (i.e. file1 is stage 2 aka "our
1034 version", file2 is stage 3 aka "their version").
1035
1037 The --summary option describes newly added, deleted, renamed and copied
1038 files. The --stat option adds diffstat(1) graph to the output. These
1039 options can be combined with other options, such as -p, and are meant
1040 for human consumption.
1041
1042 When showing a change that involves a rename or a copy, --stat output
1043 formats the pathnames compactly by combining common prefix and suffix
1044 of the pathnames. For example, a change that moves arch/i386/Makefile
1045 to arch/x86/Makefile while modifying 4 lines will be shown like this:
1046
1047 arch/{i386 => x86}/Makefile | 4 +--
1048
1049 The --numstat option gives the diffstat(1) information but is designed
1050 for easier machine consumption. An entry in --numstat output looks like
1051 this:
1052
1053 1 2 README
1054 3 1 arch/{i386 => x86}/Makefile
1055
1056 That is, from left to right:
1057
1058 1. the number of added lines;
1059
1060 2. a tab;
1061
1062 3. the number of deleted lines;
1063
1064 4. a tab;
1065
1066 5. pathname (possibly with rename/copy information);
1067
1068 6. a newline.
1069
1070 When -z output option is in effect, the output is formatted this way:
1071
1072 1 2 README NUL
1073 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1074
1075 That is:
1076
1077 1. the number of added lines;
1078
1079 2. a tab;
1080
1081 3. the number of deleted lines;
1082
1083 4. a tab;
1084
1085 5. a NUL (only exists if renamed/copied);
1086
1087 6. pathname in preimage;
1088
1089 7. a NUL (only exists if renamed/copied);
1090
1091 8. pathname in postimage (only exists if renamed/copied);
1092
1093 9. a NUL.
1094
1095 The extra NUL before the preimage path in renamed case is to allow
1096 scripts that read the output to tell if the current record being read
1097 is a single-path record or a rename/copy record without reading ahead.
1098 After reading added and deleted lines, reading up to NUL would yield
1099 the pathname, but if that is NUL, the record will show two paths.
1100
1102 You can choose whether you want to trust the index file entirely (using
1103 the --cached flag) or ask the diff logic to show any files that don’t
1104 match the stat state as being "tentatively changed". Both of these
1105 operations are very useful indeed.
1106
1108 If --cached is specified, it allows you to ask:
1109
1110 show me the differences between HEAD and the current index
1111 contents (the ones I'd write using 'git write-tree')
1112
1113 For example, let’s say that you have worked on your working directory,
1114 updated some files in the index and are ready to commit. You want to
1115 see exactly what you are going to commit, without having to write a new
1116 tree object and compare it that way, and to do that, you just do
1117
1118 git diff-index --cached HEAD
1119
1120 Example: let’s say I had renamed commit.c to git-commit.c, and I had
1121 done an update-index to make that effective in the index file. git
1122 diff-files wouldn’t show anything at all, since the index file matches
1123 my working directory. But doing a git diff-index does:
1124
1125 torvalds@ppc970:~/git> git diff-index --cached HEAD
1126 :100644 000000 4161aecc6700a2eb579e842af0b7f22b98443f74 0000000000000000000000000000000000000000 D commit.c
1127 :000000 100644 0000000000000000000000000000000000000000 4161aecc6700a2eb579e842af0b7f22b98443f74 A git-commit.c
1128
1129 You can see easily that the above is a rename.
1130
1131 In fact, git diff-index --cached should always be entirely equivalent
1132 to actually doing a git write-tree and comparing that. Except this one
1133 is much nicer for the case where you just want to check where you are.
1134
1135 So doing a git diff-index --cached is basically very useful when you
1136 are asking yourself "what have I already marked for being committed,
1137 and what’s the difference to a previous tree".
1138
1140 The "non-cached" mode takes a different approach, and is potentially
1141 the more useful of the two in that what it does can’t be emulated with
1142 a git write-tree + git diff-tree. Thus that’s the default mode. The
1143 non-cached version asks the question:
1144
1145 show me the differences between HEAD and the currently checked out
1146 tree - index contents _and_ files that aren't up to date
1147
1148 which is obviously a very useful question too, since that tells you
1149 what you could commit. Again, the output matches the git diff-tree -r
1150 output to a tee, but with a twist.
1151
1152 The twist is that if some file doesn’t match the index, we don’t have a
1153 backing store thing for it, and we use the magic "all-zero" sha1 to
1154 show that. So let’s say that you have edited kernel/sched.c, but have
1155 not actually done a git update-index on it yet - there is no "object"
1156 associated with the new state, and you get:
1157
1158 torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
1159 :100644 100644 7476bb5ba 000000000 M kernel/sched.c
1160
1161 i.e., it shows that the tree has changed, and that kernel/sched.c is
1162 not up to date and may contain new stuff. The all-zero sha1 means that
1163 to get the real diff, you need to look at the object in the working
1164 directory directly rather than do an object-to-object diff.
1165
1166 Note
1167 As with other commands of this type, git diff-index does not
1168 actually look at the contents of the file at all. So maybe
1169 kernel/sched.c hasn’t actually changed, and it’s just that you
1170 touched it. In either case, it’s a note that you need to git
1171 update-index it to make the index be in sync.
1172
1173 Note
1174 You can have a mixture of files show up as "has been updated" and
1175 "is still dirty in the working directory" together. You can always
1176 tell which file is in which state, since the "has been updated"
1177 ones show a valid sha1, and the "not in sync with the index" ones
1178 will always have the special all-zero sha1.
1179
1181 Part of the git(1) suite
1182
1183
1184
1185Git 2.43.0 11/20/2023 GIT-DIFF-INDEX(1)