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