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