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