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