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 --merge-base A is equivalent
46           to git diff $(git merge-base A HEAD).
47
48       git diff [<options>] <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       git diff [<options>] [--merge-base] <commit> <commit> [--] [<path>...]
55           This is to view the changes between two arbitrary <commit>.
56
57           If --merge-base is given, use the merge base of the two commits for
58           the "before" side.  git diff --merge-base A B is equivalent to git
59           diff $(git merge-base A B) B.
60
61       git diff [<options>] <commit> <commit>... <commit> [--] [<path>...]
62           This form is to view the results of a merge commit. The first
63           listed <commit> must be the merge itself; the remaining two or more
64           commits should be its parents. A convenient way to produce the
65           desired set of revisions is to use the ^@ suffix. For instance, if
66           master names a merge commit, git diff master master^@ gives the
67           same combined diff as git show master.
68
69       git diff [<options>] <commit>..<commit> [--] [<path>...]
70           This is synonymous to the earlier form (without the ..) for viewing
71           the changes between two arbitrary <commit>. If <commit> on one side
72           is omitted, it will have the same effect as using HEAD instead.
73
74       git diff [<options>] <commit>...<commit> [--] [<path>...]
75           This form is to view the changes on the branch containing and up to
76           the second <commit>, starting at a common ancestor of both
77           <commit>.  git diff A...B is equivalent to git diff $(git
78           merge-base A B) B. You can omit any one of <commit>, which has the
79           same effect as using HEAD instead.
80
81       Just in case you are doing something exotic, it should be noted that
82       all of the <commit> in the above description, except in the
83       --merge-base case and in the last two forms that use .. notations, can
84       be any <tree>.
85
86       For a more complete list of ways to spell <commit>, see "SPECIFYING
87       REVISIONS" section in gitrevisions(7). However, "diff" is about
88       comparing two endpoints, not ranges, and the range notations
89       (<commit>..<commit> and <commit>...<commit>) do not mean a range as
90       defined in the "SPECIFYING RANGES" section in gitrevisions(7).
91
92       git diff [<options>] <blob> <blob>
93           This form is to view the differences between the raw contents of
94           two blob objects.
95

OPTIONS

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

RAW OUTPUT FORMAT

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

DIFF FORMAT FOR MERGES

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

GENERATING PATCH TEXT WITH -P

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

COMBINED DIFF FORMAT

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

OTHER DIFF FORMATS

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

EXAMPLES

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

SEE ALSO

1226       diff(1), git-difftool(1), git-log(1), gitdiffcore(7), git-format-
1227       patch(1), git-apply(1), git-show(1)
1228

GIT

1230       Part of the git(1) suite
1231
1232
1233
1234Git 2.31.1                        2021-03-26                       GIT-DIFF(1)
Impressum