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

NAME

6       git-diff - Show changes between commits, commit and working tree, etc
7

SYNOPSIS

9       git diff [<options>] [<commit>] [--] [<path>...]
10       git diff [<options>] --cached [<commit>] [--] [<path>...]
11       git diff [<options>] <commit> <commit> [--] [<path>...]
12       git diff [<options>] <blob> <blob>
13       git diff [<options>] --no-index [--] <path> <path>
14

DESCRIPTION

16       Show changes between the working tree and the index or a tree, changes
17       between the index and a tree, changes between two trees, changes
18       between two blob objects, or changes between two files on disk.
19
20       git diff [<options>] [--] [<path>...]
21           This form is to view the changes you made relative to the index
22           (staging area for the next commit). In other words, the differences
23           are what you could tell Git to further add to the index but you
24           still haven’t. You can stage these changes by using git-add(1).
25
26       git diff [<options>] --no-index [--] <path> <path>
27           This form is to compare the given two paths on the filesystem. You
28           can omit the --no-index option when running the command in a
29           working tree controlled by Git and at least one of the paths points
30           outside the working tree, or when running the command outside a
31           working tree controlled by Git. This form implies --exit-code.
32
33       git diff [<options>] --cached [<commit>] [--] [<path>...]
34           This form is to view the changes you staged for the next commit
35           relative to the named <commit>. Typically you would want comparison
36           with the latest commit, so if you do not give <commit>, it defaults
37           to HEAD. If HEAD does not exist (e.g. unborn branches) and <commit>
38           is not given, it shows all staged changes. --staged is a synonym of
39           --cached.
40
41       git diff [<options>] <commit> [--] [<path>...]
42           This form is to view the changes you have in your working tree
43           relative to the named <commit>. You can use HEAD to compare it with
44           the latest commit, or a branch name to compare with the tip of a
45           different branch.
46
47       git diff [<options>] <commit> <commit> [--] [<path>...]
48           This is to view the changes between two arbitrary <commit>.
49
50       git diff [<options>] <commit>..<commit> [--] [<path>...]
51           This is synonymous to the previous form. If <commit> on one side is
52           omitted, it will have the same effect as using HEAD instead.
53
54       git diff [<options>] <commit>...<commit> [--] [<path>...]
55           This form is to view the changes on the branch containing and up to
56           the second <commit>, starting at a common ancestor of both
57           <commit>. "git diff A...B" is equivalent to "git diff $(git
58           merge-base A B) B". You can omit any one of <commit>, which has the
59           same effect as using HEAD instead.
60
61       Just in case you are doing something exotic, it should be noted that
62       all of the <commit> in the above description, except in the last two
63       forms that use ".." notations, can be any <tree>.
64
65       For a more complete list of ways to spell <commit>, see "SPECIFYING
66       REVISIONS" section in gitrevisions(7). However, "diff" is about
67       comparing two endpoints, not ranges, and the range notations
68       ("<commit>..<commit>" and "<commit>...<commit>") do not mean a range as
69       defined in the "SPECIFYING RANGES" section in gitrevisions(7).
70
71       git diff [<options>] <blob> <blob>
72           This form is to view the differences between the raw contents of
73           two blob objects.
74

OPTIONS

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

RAW OUTPUT FORMAT

740       The raw output format from "git-diff-index", "git-diff-tree",
741       "git-diff-files" and "git diff --raw" are very similar.
742
743       These commands all compare two sets of things; what is compared
744       differs:
745
746       git-diff-index <tree-ish>
747           compares the <tree-ish> and the files on the filesystem.
748
749       git-diff-index --cached <tree-ish>
750           compares the <tree-ish> and the index.
751
752       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
753           compares the trees named by the two arguments.
754
755       git-diff-files [<pattern>...]
756           compares the index and the files on the filesystem.
757
758       The "git-diff-tree" command begins its output by printing the hash of
759       what is being compared. After that, all the commands print one output
760       line per changed file.
761
762       An output line is formatted this way:
763
764           in-place edit  :100644 100644 bcd1234 0123456 M file0
765           copy-edit      :100644 100644 abcd123 1234567 C68 file1 file2
766           rename-edit    :100644 100644 abcd123 1234567 R86 file1 file3
767           create         :000000 100644 0000000 1234567 A file4
768           delete         :100644 000000 1234567 0000000 D file5
769           unmerged       :000000 000000 0000000 0000000 U file6
770
771       That is, from the left to the right:
772
773        1. a colon.
774
775        2. mode for "src"; 000000 if creation or unmerged.
776
777        3. a space.
778
779        4. mode for "dst"; 000000 if deletion or unmerged.
780
781        5. a space.
782
783        6. sha1 for "src"; 0{40} if creation or unmerged.
784
785        7. a space.
786
787        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
788
789        9. a space.
790
791       10. status, followed by optional "score" number.
792
793       11. a tab or a NUL when -z option is used.
794
795       12. path for "src"
796
797       13. a tab or a NUL when -z option is used; only exists for C or R.
798
799       14. path for "dst"; only exists for C or R.
800
801       15. an LF or a NUL when -z option is used, to terminate the record.
802
803       Possible status letters are:
804
805       ·   A: addition of a file
806
807       ·   C: copy of a file into a new one
808
809       ·   D: deletion of a file
810
811       ·   M: modification of the contents or mode of a file
812
813       ·   R: renaming of a file
814
815       ·   T: change in the type of the file
816
817       ·   U: file is unmerged (you must complete the merge before it can be
818           committed)
819
820       ·   X: "unknown" change type (most probably a bug, please report it)
821
822       Status letters C and R are always followed by a score (denoting the
823       percentage of similarity between the source and target of the move or
824       copy). Status letter M may be followed by a score (denoting the
825       percentage of dissimilarity) for file rewrites.
826
827       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
828       out of sync with the index.
829
830       Example:
831
832           :100644 100644 5be4a4a 0000000 M file.c
833
834       Without the -z option, pathnames with "unusual" characters are quoted
835       as explained for the configuration variable core.quotePath (see git-
836       config(1)). Using -z the filename is output verbatim and the line is
837       terminated by a NUL byte.
838

DIFF FORMAT FOR MERGES

840       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
841       --cc option to generate diff output also for merge commits. The output
842       differs from the format described above in the following way:
843
844        1. there is a colon for each parent
845
846        2. there are more "src" modes and "src" sha1
847
848        3. status is concatenated status characters for each parent
849
850        4. no optional "score" number
851
852        5. tab-separated pathname(s) of the file
853
854       For -c and --cc, only the destination or final path is shown even if
855       the file was renamed on any side of history. With --combined-all-paths,
856       the name of the path in each parent is shown followed by the name of
857       the path in the merge commit.
858
859       Examples for -c and --cc without --combined-all-paths:
860
861           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c
862           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       bar.sh
863           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       phooey.c
864
865       Examples when --combined-all-paths added to either -c or --cc:
866
867           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c  desc.c  desc.c
868           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       foo.sh  bar.sh  bar.sh
869           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       fooey.c fuey.c  phooey.c
870
871       Note that combined diff lists only files which were modified from all
872       parents.
873

GENERATING PATCH TEXT WITH -P

875       Running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-
876       diff-tree(1), or git-diff-files(1) with the -p option produces patch
877       text. You can customize the creation of patch text via the
878       GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.
879
880       What the -p option produces is slightly different from the traditional
881       diff format:
882
883        1. It is preceded with a "git diff" header that looks like this:
884
885               diff --git a/file1 b/file2
886
887           The a/ and b/ filenames are the same unless rename/copy is
888           involved. Especially, even for a creation or a deletion, /dev/null
889           is not used in place of the a/ or b/ filenames.
890
891           When rename/copy is involved, file1 and file2 show the name of the
892           source file of the rename/copy and the name of the file that
893           rename/copy produces, respectively.
894
895        2. It is followed by one or more extended header lines:
896
897               old mode <mode>
898               new mode <mode>
899               deleted file mode <mode>
900               new file mode <mode>
901               copy from <path>
902               copy to <path>
903               rename from <path>
904               rename to <path>
905               similarity index <number>
906               dissimilarity index <number>
907               index <hash>..<hash> <mode>
908
909           File modes are printed as 6-digit octal numbers including the file
910           type and file permission bits.
911
912           Path names in extended headers do not include the a/ and b/
913           prefixes.
914
915           The similarity index is the percentage of unchanged lines, and the
916           dissimilarity index is the percentage of changed lines. It is a
917           rounded down integer, followed by a percent sign. The similarity
918           index value of 100% is thus reserved for two equal files, while
919           100% dissimilarity means that no line from the old file made it
920           into the new one.
921
922           The index line includes the blob object names before and after the
923           change. The <mode> is included if the file mode does not change;
924           otherwise, separate lines indicate the old and the new mode.
925
926        3. Pathnames with "unusual" characters are quoted as explained for the
927           configuration variable core.quotePath (see git-config(1)).
928
929        4. All the file1 files in the output refer to files before the commit,
930           and all the file2 files refer to files after the commit. It is
931           incorrect to apply each change to each file sequentially. For
932           example, this patch will swap a and b:
933
934               diff --git a/a b/b
935               rename from a
936               rename to b
937               diff --git a/b b/a
938               rename from b
939               rename to a
940

COMBINED DIFF FORMAT

942       Any diff-generating command can take the -c or --cc option to produce a
943       combined diff when showing a merge. This is the default format when
944       showing merges with git-diff(1) or git-show(1). Note also that you can
945       give the -m option to any of these commands to force generation of
946       diffs with individual parents of a merge.
947
948       A "combined diff" format looks like this:
949
950           diff --combined describe.c
951           index fabadb8,cc95eb0..4866510
952           --- a/describe.c
953           +++ b/describe.c
954           @@@ -98,20 -98,12 +98,20 @@@
955                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
956             }
957
958           - static void describe(char *arg)
959            -static void describe(struct commit *cmit, int last_one)
960           ++static void describe(char *arg, int last_one)
961             {
962            +      unsigned char sha1[20];
963            +      struct commit *cmit;
964                   struct commit_list *list;
965                   static int initialized = 0;
966                   struct commit_name *n;
967
968            +      if (get_sha1(arg, sha1) < 0)
969            +              usage(describe_usage);
970            +      cmit = lookup_commit_reference(sha1);
971            +      if (!cmit)
972            +              usage(describe_usage);
973            +
974                   if (!initialized) {
975                           initialized = 1;
976                           for_each_ref(get_name);
977
978        1. It is preceded with a "git diff" header, that looks like this (when
979           the -c option is used):
980
981               diff --combined file
982
983           or like this (when the --cc option is used):
984
985               diff --cc file
986
987        2. It is followed by one or more extended header lines (this example
988           shows a merge with two parents):
989
990               index <hash>,<hash>..<hash>
991               mode <mode>,<mode>..<mode>
992               new file mode <mode>
993               deleted file mode <mode>,<mode>
994
995           The mode <mode>,<mode>..<mode> line appears only if at least one of
996           the <mode> is different from the rest. Extended headers with
997           information about detected contents movement (renames and copying
998           detection) are designed to work with diff of two <tree-ish> and are
999           not used by combined diff format.
1000
1001        3. It is followed by two-line from-file/to-file header
1002
1003               --- a/file
1004               +++ b/file
1005
1006           Similar to two-line header for traditional unified diff format,
1007           /dev/null is used to signal created or deleted files.
1008
1009           However, if the --combined-all-paths option is provided, instead of
1010           a two-line from-file/to-file you get a N+1 line from-file/to-file
1011           header, where N is the number of parents in the merge commit
1012
1013               --- a/file
1014               --- a/file
1015               --- a/file
1016               +++ b/file
1017
1018           This extended format can be useful if rename or copy detection is
1019           active, to allow you to see the original name of the file in
1020           different parents.
1021
1022        4. Chunk header format is modified to prevent people from accidentally
1023           feeding it to patch -p1. Combined diff format was created for
1024           review of merge commit changes, and was not meant to be applied.
1025           The change is similar to the change in the extended index header:
1026
1027               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
1028
1029           There are (number of parents + 1) @ characters in the chunk header
1030           for combined diff format.
1031
1032       Unlike the traditional unified diff format, which shows two files A and
1033       B with a single column that has - (minus — appears in A but removed in
1034       B), + (plus — missing in A but added to B), or " " (space — unchanged)
1035       prefix, this format compares two or more files file1, file2,... with
1036       one file X, and shows how X differs from each of fileN. One column for
1037       each of fileN is prepended to the output line to note how X’s line is
1038       different from it.
1039
1040       A - character in the column N means that the line appears in fileN but
1041       it does not appear in the result. A + character in the column N means
1042       that the line appears in the result, and fileN does not have that line
1043       (in other words, the line was added, from the point of view of that
1044       parent).
1045
1046       In the above example output, the function signature was changed from
1047       both files (hence two - removals from both file1 and file2, plus ++ to
1048       mean one line that was added does not appear in either file1 or file2).
1049       Also eight other lines are the same from file1 but do not appear in
1050       file2 (hence prefixed with +).
1051
1052       When shown by git diff-tree -c, it compares the parents of a merge
1053       commit with the merge result (i.e. file1..fileN are the parents). When
1054       shown by git diff-files -c, it compares the two unresolved merge
1055       parents with the working tree file (i.e. file1 is stage 2 aka "our
1056       version", file2 is stage 3 aka "their version").
1057

OTHER DIFF FORMATS

1059       The --summary option describes newly added, deleted, renamed and copied
1060       files. The --stat option adds diffstat(1) graph to the output. These
1061       options can be combined with other options, such as -p, and are meant
1062       for human consumption.
1063
1064       When showing a change that involves a rename or a copy, --stat output
1065       formats the pathnames compactly by combining common prefix and suffix
1066       of the pathnames. For example, a change that moves arch/i386/Makefile
1067       to arch/x86/Makefile while modifying 4 lines will be shown like this:
1068
1069           arch/{i386 => x86}/Makefile    |   4 +--
1070
1071       The --numstat option gives the diffstat(1) information but is designed
1072       for easier machine consumption. An entry in --numstat output looks like
1073       this:
1074
1075           1       2       README
1076           3       1       arch/{i386 => x86}/Makefile
1077
1078       That is, from left to right:
1079
1080        1. the number of added lines;
1081
1082        2. a tab;
1083
1084        3. the number of deleted lines;
1085
1086        4. a tab;
1087
1088        5. pathname (possibly with rename/copy information);
1089
1090        6. a newline.
1091
1092       When -z output option is in effect, the output is formatted this way:
1093
1094           1       2       README NUL
1095           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1096
1097       That is:
1098
1099        1. the number of added lines;
1100
1101        2. a tab;
1102
1103        3. the number of deleted lines;
1104
1105        4. a tab;
1106
1107        5. a NUL (only exists if renamed/copied);
1108
1109        6. pathname in preimage;
1110
1111        7. a NUL (only exists if renamed/copied);
1112
1113        8. pathname in postimage (only exists if renamed/copied);
1114
1115        9. a NUL.
1116
1117       The extra NUL before the preimage path in renamed case is to allow
1118       scripts that read the output to tell if the current record being read
1119       is a single-path record or a rename/copy record without reading ahead.
1120       After reading added and deleted lines, reading up to NUL would yield
1121       the pathname, but if that is NUL, the record will show two paths.
1122

EXAMPLES

1124       Various ways to check your working tree
1125
1126               $ git diff            (1)
1127               $ git diff --cached   (2)
1128               $ git diff HEAD       (3)
1129
1130            1. Changes in the working tree not yet staged for the next
1131               commit.
1132            2. Changes between the index and your last commit; what you
1133               would be committing if you run "git commit" without "-a"
1134               option.
1135            3. Changes in the working tree since your last commit; what
1136               you would be committing if you run "git commit -a"
1137
1138       Comparing with arbitrary commits
1139
1140               $ git diff test            (1)
1141               $ git diff HEAD -- ./test  (2)
1142               $ git diff HEAD^ HEAD      (3)
1143
1144            1. Instead of using the tip of the current branch, compare
1145               with the tip of "test" branch.
1146            2. Instead of comparing with the tip of "test" branch,
1147               compare with the tip of the current branch, but limit the
1148               comparison to the file "test".
1149            3. Compare the version before the last commit and the last
1150               commit.
1151
1152       Comparing branches
1153
1154               $ git diff topic master    (1)
1155               $ git diff topic..master   (2)
1156               $ git diff topic...master  (3)
1157
1158            1. Changes between the tips of the topic and the master
1159               branches.
1160            2. Same as above.
1161            3. Changes that occurred on the master branch since when the
1162               topic branch was started off it.
1163
1164       Limiting the diff output
1165
1166               $ git diff --diff-filter=MRC            (1)
1167               $ git diff --name-status                (2)
1168               $ git diff arch/i386 include/asm-i386   (3)
1169
1170            1. Show only modification, rename, and copy, but not addition
1171               or deletion.
1172            2. Show only names and the nature of change, but not actual
1173               diff output.
1174            3. Limit diff output to named subtrees.
1175
1176       Munging the diff output
1177
1178               $ git diff --find-copies-harder -B -C  (1)
1179               $ git diff -R                          (2)
1180
1181            1. Spend extra cycles to find renames, copies and complete
1182               rewrites (very expensive).
1183            2. Output diff in reverse.
1184

SEE ALSO

1186       diff(1), git-difftool(1), git-log(1), gitdiffcore(7), git-format-
1187       patch(1), git-apply(1)
1188

GIT

1190       Part of the git(1) suite
1191
1192
1193
1194Git 2.26.2                        2020-04-20                       GIT-DIFF(1)
Impressum