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