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