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

NAME

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

SYNOPSIS

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

OPTIONS

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

RAW OUTPUT FORMAT

676       The raw output format from "git-diff-index", "git-diff-tree",
677       "git-diff-files" and "git diff --raw" are very similar.
678
679       These commands all compare two sets of things; what is compared
680       differs:
681
682       git-diff-index <tree-ish>
683           compares the <tree-ish> and the files on the filesystem.
684
685       git-diff-index --cached <tree-ish>
686           compares the <tree-ish> and the index.
687
688       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
689           compares the trees named by the two arguments.
690
691       git-diff-files [<pattern>...]
692           compares the index and the files on the filesystem.
693
694       The "git-diff-tree" command begins its output by printing the hash of
695       what is being compared. After that, all the commands print one output
696       line per changed file.
697
698       An output line is formatted this way:
699
700           in-place edit  :100644 100644 bcd1234... 0123456... M file0
701           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
702           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
703           create         :000000 100644 0000000... 1234567... A file4
704           delete         :100644 000000 1234567... 0000000... D file5
705           unmerged       :000000 000000 0000000... 0000000... U file6
706
707
708       That is, from the left to the right:
709
710        1. a colon.
711
712        2. mode for "src"; 000000 if creation or unmerged.
713
714        3. a space.
715
716        4. mode for "dst"; 000000 if deletion or unmerged.
717
718        5. a space.
719
720        6. sha1 for "src"; 0{40} if creation or unmerged.
721
722        7. a space.
723
724        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
725
726        9. a space.
727
728       10. status, followed by optional "score" number.
729
730       11. a tab or a NUL when -z option is used.
731
732       12. path for "src"
733
734       13. a tab or a NUL when -z option is used; only exists for C or R.
735
736       14. path for "dst"; only exists for C or R.
737
738       15. an LF or a NUL when -z option is used, to terminate the record.
739
740       Possible status letters are:
741
742       ·   A: addition of a file
743
744       ·   C: copy of a file into a new one
745
746       ·   D: deletion of a file
747
748       ·   M: modification of the contents or mode of a file
749
750       ·   R: renaming of a file
751
752       ·   T: change in the type of the file
753
754       ·   U: file is unmerged (you must complete the merge before it can be
755           committed)
756
757       ·   X: "unknown" change type (most probably a bug, please report it)
758
759       Status letters C and R are always followed by a score (denoting the
760       percentage of similarity between the source and target of the move or
761       copy). Status letter M may be followed by a score (denoting the
762       percentage of dissimilarity) for file rewrites.
763
764       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
765       out of sync with the index.
766
767       Example:
768
769           :100644 100644 5be4a4...... 000000...... M file.c
770
771
772       Without the -z option, pathnames with "unusual" characters are quoted
773       as explained for the configuration variable core.quotePath (see git-
774       config(1)). Using -z the filename is output verbatim and the line is
775       terminated by a NUL byte.
776

DIFF FORMAT FOR MERGES

778       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
779       --cc option to generate diff output also for merge commits. The output
780       differs from the format described above in the following way:
781
782        1. there is a colon for each parent
783
784        2. there are more "src" modes and "src" sha1
785
786        3. status is concatenated status characters for each parent
787
788        4. no optional "score" number
789
790        5. single path, only for "dst"
791
792       Example:
793
794           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
795
796
797       Note that combined diff lists only files which were modified from all
798       parents.
799

GENERATING PATCHES WITH -P

801       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
802       with a -p option, "git diff" without the --raw option, or "git log"
803       with the "-p" option, they do not produce the output described above;
804       instead they produce a patch file. You can customize the creation of
805       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
806       environment variables.
807
808       What the -p option produces is slightly different from the traditional
809       diff format:
810
811        1. It is preceded with a "git diff" header that looks like this:
812
813               diff --git a/file1 b/file2
814
815           The a/ and b/ filenames are the same unless rename/copy is
816           involved. Especially, even for a creation or a deletion, /dev/null
817           is not used in place of the a/ or b/ filenames.
818
819           When rename/copy is involved, file1 and file2 show the name of the
820           source file of the rename/copy and the name of the file that
821           rename/copy produces, respectively.
822
823        2. It is followed by one or more extended header lines:
824
825               old mode <mode>
826               new mode <mode>
827               deleted file mode <mode>
828               new file mode <mode>
829               copy from <path>
830               copy to <path>
831               rename from <path>
832               rename to <path>
833               similarity index <number>
834               dissimilarity index <number>
835               index <hash>..<hash> <mode>
836
837           File modes are printed as 6-digit octal numbers including the file
838           type and file permission bits.
839
840           Path names in extended headers do not include the a/ and b/
841           prefixes.
842
843           The similarity index is the percentage of unchanged lines, and the
844           dissimilarity index is the percentage of changed lines. It is a
845           rounded down integer, followed by a percent sign. The similarity
846           index value of 100% is thus reserved for two equal files, while
847           100% dissimilarity means that no line from the old file made it
848           into the new one.
849
850           The index line includes the SHA-1 checksum before and after the
851           change. The <mode> is included if the file mode does not change;
852           otherwise, separate lines indicate the old and the new mode.
853
854        3. Pathnames with "unusual" characters are quoted as explained for the
855           configuration variable core.quotePath (see git-config(1)).
856
857        4. All the file1 files in the output refer to files before the commit,
858           and all the file2 files refer to files after the commit. It is
859           incorrect to apply each change to each file sequentially. For
860           example, this patch will swap a and b:
861
862               diff --git a/a b/b
863               rename from a
864               rename to b
865               diff --git a/b b/a
866               rename from b
867               rename to a
868

COMBINED DIFF FORMAT

870       Any diff-generating command can take the -c or --cc option to produce a
871       combined diff when showing a merge. This is the default format when
872       showing merges with git-diff(1) or git-show(1). Note also that you can
873       give the -m option to any of these commands to force generation of
874       diffs with individual parents of a merge.
875
876       A combined diff format looks like this:
877
878           diff --combined describe.c
879           index fabadb8,cc95eb0..4866510
880           --- a/describe.c
881           +++ b/describe.c
882           @@@ -98,20 -98,12 +98,20 @@@
883                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
884             }
885
886           - static void describe(char *arg)
887            -static void describe(struct commit *cmit, int last_one)
888           ++static void describe(char *arg, int last_one)
889             {
890            +      unsigned char sha1[20];
891            +      struct commit *cmit;
892                   struct commit_list *list;
893                   static int initialized = 0;
894                   struct commit_name *n;
895
896            +      if (get_sha1(arg, sha1) < 0)
897            +              usage(describe_usage);
898            +      cmit = lookup_commit_reference(sha1);
899            +      if (!cmit)
900            +              usage(describe_usage);
901            +
902                   if (!initialized) {
903                           initialized = 1;
904                           for_each_ref(get_name);
905
906
907
908        1. It is preceded with a "git diff" header, that looks like this (when
909           -c option is used):
910
911               diff --combined file
912
913           or like this (when --cc option is used):
914
915               diff --cc file
916
917        2. It is followed by one or more extended header lines (this example
918           shows a merge with two parents):
919
920               index <hash>,<hash>..<hash>
921               mode <mode>,<mode>..<mode>
922               new file mode <mode>
923               deleted file mode <mode>,<mode>
924
925           The mode <mode>,<mode>..<mode> line appears only if at least one of
926           the <mode> is different from the rest. Extended headers with
927           information about detected contents movement (renames and copying
928           detection) are designed to work with diff of two <tree-ish> and are
929           not used by combined diff format.
930
931        3. It is followed by two-line from-file/to-file header
932
933               --- a/file
934               +++ b/file
935
936           Similar to two-line header for traditional unified diff format,
937           /dev/null is used to signal created or deleted files.
938
939        4. Chunk header format is modified to prevent people from accidentally
940           feeding it to patch -p1. Combined diff format was created for
941           review of merge commit changes, and was not meant for apply. The
942           change is similar to the change in the extended index header:
943
944               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
945
946           There are (number of parents + 1) @ characters in the chunk header
947           for combined diff format.
948
949       Unlike the traditional unified diff format, which shows two files A and
950       B with a single column that has - (minus — appears in A but removed in
951       B), + (plus — missing in A but added to B), or " " (space — unchanged)
952       prefix, this format compares two or more files file1, file2,... with
953       one file X, and shows how X differs from each of fileN. One column for
954       each of fileN is prepended to the output line to note how X’s line is
955       different from it.
956
957       A - character in the column N means that the line appears in fileN but
958       it does not appear in the result. A + character in the column N means
959       that the line appears in the result, and fileN does not have that line
960       (in other words, the line was added, from the point of view of that
961       parent).
962
963       In the above example output, the function signature was changed from
964       both files (hence two - removals from both file1 and file2, plus ++ to
965       mean one line that was added does not appear in either file1 or file2).
966       Also eight other lines are the same from file1 but do not appear in
967       file2 (hence prefixed with +).
968
969       When shown by git diff-tree -c, it compares the parents of a merge
970       commit with the merge result (i.e. file1..fileN are the parents). When
971       shown by git diff-files -c, it compares the two unresolved merge
972       parents with the working tree file (i.e. file1 is stage 2 aka "our
973       version", file2 is stage 3 aka "their version").
974

OTHER DIFF FORMATS

976       The --summary option describes newly added, deleted, renamed and copied
977       files. The --stat option adds diffstat(1) graph to the output. These
978       options can be combined with other options, such as -p, and are meant
979       for human consumption.
980
981       When showing a change that involves a rename or a copy, --stat output
982       formats the pathnames compactly by combining common prefix and suffix
983       of the pathnames. For example, a change that moves arch/i386/Makefile
984       to arch/x86/Makefile while modifying 4 lines will be shown like this:
985
986           arch/{i386 => x86}/Makefile    |   4 +--
987
988
989       The --numstat option gives the diffstat(1) information but is designed
990       for easier machine consumption. An entry in --numstat output looks like
991       this:
992
993           1       2       README
994           3       1       arch/{i386 => x86}/Makefile
995
996
997       That is, from left to right:
998
999        1. the number of added lines;
1000
1001        2. a tab;
1002
1003        3. the number of deleted lines;
1004
1005        4. a tab;
1006
1007        5. pathname (possibly with rename/copy information);
1008
1009        6. a newline.
1010
1011       When -z output option is in effect, the output is formatted this way:
1012
1013           1       2       README NUL
1014           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1015
1016
1017       That is:
1018
1019        1. the number of added lines;
1020
1021        2. a tab;
1022
1023        3. the number of deleted lines;
1024
1025        4. a tab;
1026
1027        5. a NUL (only exists if renamed/copied);
1028
1029        6. pathname in preimage;
1030
1031        7. a NUL (only exists if renamed/copied);
1032
1033        8. pathname in postimage (only exists if renamed/copied);
1034
1035        9. a NUL.
1036
1037       The extra NUL before the preimage path in renamed case is to allow
1038       scripts that read the output to tell if the current record being read
1039       is a single-path record or a rename/copy record without reading ahead.
1040       After reading added and deleted lines, reading up to NUL would yield
1041       the pathname, but if that is NUL, the record will show two paths.
1042

EXAMPLES

1044       Various ways to check your working tree
1045
1046               $ git diff            (1)
1047               $ git diff --cached   (2)
1048               $ git diff HEAD       (3)
1049
1050           1. Changes in the working tree not yet staged for the next commit.
1051           2. Changes between the index and your last commit; what you would
1052           be committing if you run "git commit" without "-a" option.
1053           3. Changes in the working tree since your last commit; what you
1054           would be committing if you run "git commit -a"
1055
1056       Comparing with arbitrary commits
1057
1058               $ git diff test            (1)
1059               $ git diff HEAD -- ./test  (2)
1060               $ git diff HEAD^ HEAD      (3)
1061
1062           1. Instead of using the tip of the current branch, compare with the
1063           tip of "test" branch.
1064           2. Instead of comparing with the tip of "test" branch, compare with
1065           the tip of the current branch, but limit the comparison to the file
1066           "test".
1067           3. Compare the version before the last commit and the last commit.
1068
1069       Comparing branches
1070
1071               $ git diff topic master    (1)
1072               $ git diff topic..master   (2)
1073               $ git diff topic...master  (3)
1074
1075           1. Changes between the tips of the topic and the master branches.
1076           2. Same as above.
1077           3. Changes that occurred on the master branch since when the topic
1078           branch was started off it.
1079
1080       Limiting the diff output
1081
1082               $ git diff --diff-filter=MRC            (1)
1083               $ git diff --name-status                (2)
1084               $ git diff arch/i386 include/asm-i386   (3)
1085
1086           1. Show only modification, rename, and copy, but not addition or
1087           deletion.
1088           2. Show only names and the nature of change, but not actual diff
1089           output.
1090           3. Limit diff output to named subtrees.
1091
1092       Munging the diff output
1093
1094               $ git diff --find-copies-harder -B -C  (1)
1095               $ git diff -R                          (2)
1096
1097           1. Spend extra cycles to find renames, copies and complete rewrites
1098           (very expensive).
1099           2. Output diff in reverse.
1100

SEE ALSO

1102       diff(1), git-difftool(1), git-log(1), gitdiffcore(7), git-format-
1103       patch(1), git-apply(1)
1104

GIT

1106       Part of the git(1) suite
1107
1108
1109
1110Git 2.18.1                        05/14/2019                       GIT-DIFF(1)
Impressum