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