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 [--merge-base] [<commit>] [--] [<path>...]
11       git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]
12       git diff [<options>] <commit>...<commit> [--] [<path>...]
13       git diff [<options>] <blob> <blob>
14       git diff [<options>] --no-index [--] <path> <path>
15

DESCRIPTION

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

OPTIONS

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

RAW OUTPUT FORMAT

791       The raw output format from "git-diff-index", "git-diff-tree",
792       "git-diff-files" and "git diff --raw" are very similar.
793
794       These commands all compare two sets of things; what is compared
795       differs:
796
797       git-diff-index <tree-ish>
798           compares the <tree-ish> and the files on the filesystem.
799
800       git-diff-index --cached <tree-ish>
801           compares the <tree-ish> and the index.
802
803       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
804           compares the trees named by the two arguments.
805
806       git-diff-files [<pattern>...]
807           compares the index and the files on the filesystem.
808
809       The "git-diff-tree" command begins its output by printing the hash of
810       what is being compared. After that, all the commands print one output
811       line per changed file.
812
813       An output line is formatted this way:
814
815           in-place edit  :100644 100644 bcd1234 0123456 M file0
816           copy-edit      :100644 100644 abcd123 1234567 C68 file1 file2
817           rename-edit    :100644 100644 abcd123 1234567 R86 file1 file3
818           create         :000000 100644 0000000 1234567 A file4
819           delete         :100644 000000 1234567 0000000 D file5
820           unmerged       :000000 000000 0000000 0000000 U file6
821
822       That is, from the left to the right:
823
824        1. a colon.
825
826        2. mode for "src"; 000000 if creation or unmerged.
827
828        3. a space.
829
830        4. mode for "dst"; 000000 if deletion or unmerged.
831
832        5. a space.
833
834        6. sha1 for "src"; 0{40} if creation or unmerged.
835
836        7. a space.
837
838        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
839
840        9. a space.
841
842       10. status, followed by optional "score" number.
843
844       11. a tab or a NUL when -z option is used.
845
846       12. path for "src"
847
848       13. a tab or a NUL when -z option is used; only exists for C or R.
849
850       14. path for "dst"; only exists for C or R.
851
852       15. an LF or a NUL when -z option is used, to terminate the record.
853
854       Possible status letters are:
855
856       •   A: addition of a file
857
858       •   C: copy of a file into a new one
859
860       •   D: deletion of a file
861
862       •   M: modification of the contents or mode of a file
863
864       •   R: renaming of a file
865
866       •   T: change in the type of the file
867
868       •   U: file is unmerged (you must complete the merge before it can be
869           committed)
870
871       •   X: "unknown" change type (most probably a bug, please report it)
872
873       Status letters C and R are always followed by a score (denoting the
874       percentage of similarity between the source and target of the move or
875       copy). Status letter M may be followed by a score (denoting the
876       percentage of dissimilarity) for file rewrites.
877
878       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
879       out of sync with the index.
880
881       Example:
882
883           :100644 100644 5be4a4a 0000000 M file.c
884
885       Without the -z option, pathnames with "unusual" characters are quoted
886       as explained for the configuration variable core.quotePath (see git-
887       config(1)). Using -z the filename is output verbatim and the line is
888       terminated by a NUL byte.
889

DIFF FORMAT FOR MERGES

891       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
892       --cc option to generate diff output also for merge commits. The output
893       differs from the format described above in the following way:
894
895        1. there is a colon for each parent
896
897        2. there are more "src" modes and "src" sha1
898
899        3. status is concatenated status characters for each parent
900
901        4. no optional "score" number
902
903        5. tab-separated pathname(s) of the file
904
905       For -c and --cc, only the destination or final path is shown even if
906       the file was renamed on any side of history. With --combined-all-paths,
907       the name of the path in each parent is shown followed by the name of
908       the path in the merge commit.
909
910       Examples for -c and --cc without --combined-all-paths:
911
912           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c
913           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       bar.sh
914           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       phooey.c
915
916       Examples when --combined-all-paths added to either -c or --cc:
917
918           ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM       desc.c  desc.c  desc.c
919           ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM       foo.sh  bar.sh  bar.sh
920           ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR       fooey.c fuey.c  phooey.c
921
922       Note that combined diff lists only files which were modified from all
923       parents.
924

GENERATING PATCH TEXT WITH -P

926       Running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-
927       diff-tree(1), or git-diff-files(1) with the -p option produces patch
928       text. You can customize the creation of patch text via the
929       GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables (see
930       git(1)), and the diff attribute (see gitattributes(5)).
931
932       What the -p option produces is slightly different from the traditional
933       diff format:
934
935        1. It is preceded with a "git diff" header that looks like this:
936
937               diff --git a/file1 b/file2
938
939           The a/ and b/ filenames are the same unless rename/copy is
940           involved. Especially, even for a creation or a deletion, /dev/null
941           is not used in place of the a/ or b/ filenames.
942
943           When rename/copy is involved, file1 and file2 show the name of the
944           source file of the rename/copy and the name of the file that
945           rename/copy produces, respectively.
946
947        2. It is followed by one or more extended header lines:
948
949               old mode <mode>
950               new mode <mode>
951               deleted file mode <mode>
952               new file mode <mode>
953               copy from <path>
954               copy to <path>
955               rename from <path>
956               rename to <path>
957               similarity index <number>
958               dissimilarity index <number>
959               index <hash>..<hash> <mode>
960
961           File modes are printed as 6-digit octal numbers including the file
962           type and file permission bits.
963
964           Path names in extended headers do not include the a/ and b/
965           prefixes.
966
967           The similarity index is the percentage of unchanged lines, and the
968           dissimilarity index is the percentage of changed lines. It is a
969           rounded down integer, followed by a percent sign. The similarity
970           index value of 100% is thus reserved for two equal files, while
971           100% dissimilarity means that no line from the old file made it
972           into the new one.
973
974           The index line includes the blob object names before and after the
975           change. The <mode> is included if the file mode does not change;
976           otherwise, separate lines indicate the old and the new mode.
977
978        3. Pathnames with "unusual" characters are quoted as explained for the
979           configuration variable core.quotePath (see git-config(1)).
980
981        4. All the file1 files in the output refer to files before the commit,
982           and all the file2 files refer to files after the commit. It is
983           incorrect to apply each change to each file sequentially. For
984           example, this patch will swap a and b:
985
986               diff --git a/a b/b
987               rename from a
988               rename to b
989               diff --git a/b b/a
990               rename from b
991               rename to a
992
993        5. Hunk headers mention the name of the function to which the hunk
994           applies. See "Defining a custom hunk-header" in gitattributes(5)
995           for details of how to tailor to this to specific languages.
996

COMBINED DIFF FORMAT

998       Any diff-generating command can take the -c or --cc option to produce a
999       combined diff when showing a merge. This is the default format when
1000       showing merges with git-diff(1) or git-show(1). Note also that you can
1001       give suitable --diff-merges option to any of these commands to force
1002       generation of diffs in specific format.
1003
1004       A "combined diff" format looks like this:
1005
1006           diff --combined describe.c
1007           index fabadb8,cc95eb0..4866510
1008           --- a/describe.c
1009           +++ b/describe.c
1010           @@@ -98,20 -98,12 +98,20 @@@
1011                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
1012             }
1013
1014           - static void describe(char *arg)
1015            -static void describe(struct commit *cmit, int last_one)
1016           ++static void describe(char *arg, int last_one)
1017             {
1018            +      unsigned char sha1[20];
1019            +      struct commit *cmit;
1020                   struct commit_list *list;
1021                   static int initialized = 0;
1022                   struct commit_name *n;
1023
1024            +      if (get_sha1(arg, sha1) < 0)
1025            +              usage(describe_usage);
1026            +      cmit = lookup_commit_reference(sha1);
1027            +      if (!cmit)
1028            +              usage(describe_usage);
1029            +
1030                   if (!initialized) {
1031                           initialized = 1;
1032                           for_each_ref(get_name);
1033
1034        1. It is preceded with a "git diff" header, that looks like this (when
1035           the -c option is used):
1036
1037               diff --combined file
1038
1039           or like this (when the --cc option is used):
1040
1041               diff --cc file
1042
1043        2. It is followed by one or more extended header lines (this example
1044           shows a merge with two parents):
1045
1046               index <hash>,<hash>..<hash>
1047               mode <mode>,<mode>..<mode>
1048               new file mode <mode>
1049               deleted file mode <mode>,<mode>
1050
1051           The mode <mode>,<mode>..<mode> line appears only if at least one of
1052           the <mode> is different from the rest. Extended headers with
1053           information about detected contents movement (renames and copying
1054           detection) are designed to work with diff of two <tree-ish> and are
1055           not used by combined diff format.
1056
1057        3. It is followed by two-line from-file/to-file header
1058
1059               --- a/file
1060               +++ b/file
1061
1062           Similar to two-line header for traditional unified diff format,
1063           /dev/null is used to signal created or deleted files.
1064
1065           However, if the --combined-all-paths option is provided, instead of
1066           a two-line from-file/to-file you get a N+1 line from-file/to-file
1067           header, where N is the number of parents in the merge commit
1068
1069               --- a/file
1070               --- a/file
1071               --- a/file
1072               +++ b/file
1073
1074           This extended format can be useful if rename or copy detection is
1075           active, to allow you to see the original name of the file in
1076           different parents.
1077
1078        4. Chunk header format is modified to prevent people from accidentally
1079           feeding it to patch -p1. Combined diff format was created for
1080           review of merge commit changes, and was not meant to be applied.
1081           The change is similar to the change in the extended index header:
1082
1083               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
1084
1085           There are (number of parents + 1) @ characters in the chunk header
1086           for combined diff format.
1087
1088       Unlike the traditional unified diff format, which shows two files A and
1089       B with a single column that has - (minus — appears in A but removed in
1090       B), + (plus — missing in A but added to B), or " " (space — unchanged)
1091       prefix, this format compares two or more files file1, file2,... with
1092       one file X, and shows how X differs from each of fileN. One column for
1093       each of fileN is prepended to the output line to note how X’s line is
1094       different from it.
1095
1096       A - character in the column N means that the line appears in fileN but
1097       it does not appear in the result. A + character in the column N means
1098       that the line appears in the result, and fileN does not have that line
1099       (in other words, the line was added, from the point of view of that
1100       parent).
1101
1102       In the above example output, the function signature was changed from
1103       both files (hence two - removals from both file1 and file2, plus ++ to
1104       mean one line that was added does not appear in either file1 or file2).
1105       Also eight other lines are the same from file1 but do not appear in
1106       file2 (hence prefixed with +).
1107
1108       When shown by git diff-tree -c, it compares the parents of a merge
1109       commit with the merge result (i.e. file1..fileN are the parents). When
1110       shown by git diff-files -c, it compares the two unresolved merge
1111       parents with the working tree file (i.e. file1 is stage 2 aka "our
1112       version", file2 is stage 3 aka "their version").
1113

OTHER DIFF FORMATS

1115       The --summary option describes newly added, deleted, renamed and copied
1116       files. The --stat option adds diffstat(1) graph to the output. These
1117       options can be combined with other options, such as -p, and are meant
1118       for human consumption.
1119
1120       When showing a change that involves a rename or a copy, --stat output
1121       formats the pathnames compactly by combining common prefix and suffix
1122       of the pathnames. For example, a change that moves arch/i386/Makefile
1123       to arch/x86/Makefile while modifying 4 lines will be shown like this:
1124
1125           arch/{i386 => x86}/Makefile    |   4 +--
1126
1127       The --numstat option gives the diffstat(1) information but is designed
1128       for easier machine consumption. An entry in --numstat output looks like
1129       this:
1130
1131           1       2       README
1132           3       1       arch/{i386 => x86}/Makefile
1133
1134       That is, from left to right:
1135
1136        1. the number of added lines;
1137
1138        2. a tab;
1139
1140        3. the number of deleted lines;
1141
1142        4. a tab;
1143
1144        5. pathname (possibly with rename/copy information);
1145
1146        6. a newline.
1147
1148       When -z output option is in effect, the output is formatted this way:
1149
1150           1       2       README NUL
1151           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1152
1153       That is:
1154
1155        1. the number of added lines;
1156
1157        2. a tab;
1158
1159        3. the number of deleted lines;
1160
1161        4. a tab;
1162
1163        5. a NUL (only exists if renamed/copied);
1164
1165        6. pathname in preimage;
1166
1167        7. a NUL (only exists if renamed/copied);
1168
1169        8. pathname in postimage (only exists if renamed/copied);
1170
1171        9. a NUL.
1172
1173       The extra NUL before the preimage path in renamed case is to allow
1174       scripts that read the output to tell if the current record being read
1175       is a single-path record or a rename/copy record without reading ahead.
1176       After reading added and deleted lines, reading up to NUL would yield
1177       the pathname, but if that is NUL, the record will show two paths.
1178

EXAMPLES

1180       Various ways to check your working tree
1181
1182               $ git diff            (1)
1183               $ git diff --cached   (2)
1184               $ git diff HEAD       (3)
1185
1186            1. Changes in the working tree not yet staged for the next
1187               commit.
1188
1189            2. Changes between the index and your last commit; what you
1190               would be committing if you run git commit without -a
1191               option.
1192            3. Changes in the working tree since your last commit; what
1193               you would be committing if you run git commit -a
1194
1195       Comparing with arbitrary commits
1196
1197               $ git diff test            (1)
1198               $ git diff HEAD -- ./test  (2)
1199               $ git diff HEAD^ HEAD      (3)
1200
1201            1. Instead of using the tip of the current branch, compare
1202               with the tip of "test" branch.
1203            2. Instead of comparing with the tip of "test" branch,
1204               compare with the tip of the current branch, but limit the
1205               comparison to the file "test".
1206            3. Compare the version before the last commit and the last
1207               commit.
1208
1209       Comparing branches
1210
1211               $ git diff topic master    (1)
1212               $ git diff topic..master   (2)
1213               $ git diff topic...master  (3)
1214
1215            1. Changes between the tips of the topic and the master
1216               branches.
1217            2. Same as above.
1218            3. Changes that occurred on the master branch since when the
1219               topic branch was started off it.
1220
1221       Limiting the diff output
1222
1223               $ git diff --diff-filter=MRC            (1)
1224               $ git diff --name-status                (2)
1225               $ git diff arch/i386 include/asm-i386   (3)
1226
1227            1. Show only modification, rename, and copy, but not addition
1228               or deletion.
1229            2. Show only names and the nature of change, but not actual
1230               diff output.
1231            3. Limit diff output to named subtrees.
1232
1233       Munging the diff output
1234
1235               $ git diff --find-copies-harder -B -C  (1)
1236               $ git diff -R                          (2)
1237
1238            1. Spend extra cycles to find renames, copies and complete
1239               rewrites (very expensive).
1240            2. Output diff in reverse.
1241

SEE ALSO

1243       diff(1), git-difftool(1), git-log(1), gitdiffcore(7), git-format-
1244       patch(1), git-apply(1), git-show(1)
1245

GIT

1247       Part of the git(1) suite
1248
1249
1250
1251Git 2.33.1                        2021-10-12                       GIT-DIFF(1)
Impressum