1GIT-DIFF-TREE(1) Git Manual GIT-DIFF-TREE(1)
2
3
4
6 git-diff-tree - Compares the content and mode of blobs found via two
7 tree objects
8
10 git diff-tree [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty]
11 [-t] [-r] [-c | --cc] [--root] [<common diff options>]
12 <tree-ish> [<tree-ish>] [<path>...]
13
14
16 Compares the content and mode of the blobs found via two tree objects.
17
18 If there is only one <tree-ish> given, the commit is compared with its
19 parents (see --stdin below).
20
21 Note that git diff-tree can use the tree encapsulated in a commit
22 object.
23
25 -p, -u, --patch
26 Generate patch (see section on generating patches).
27
28 -U<n>, --unified=<n>
29 Generate diffs with <n> lines of context instead of the usual
30 three. Implies -p.
31
32 --raw
33 Generate the raw format. This is the default.
34
35 --patch-with-raw
36 Synonym for -p --raw.
37
38 --patience
39 Generate a diff using the "patience diff" algorithm.
40
41 --stat[=<width>[,<name-width>]]
42 Generate a diffstat. You can override the default output width for
43 80-column terminal by --stat=<width>. The width of the filename
44 part can be controlled by giving another width to it separated by a
45 comma.
46
47 --numstat
48 Similar to --stat, but shows number of added and deleted lines in
49 decimal notation and pathname without abbreviation, to make it more
50 machine friendly. For binary files, outputs two - instead of saying
51 0 0.
52
53 --shortstat
54 Output only the last line of the --stat format containing total
55 number of modified files, as well as number of added and deleted
56 lines.
57
58 --dirstat[=<limit>]
59 Output the distribution of relative amount of changes (number of
60 lines added or removed) for each sub-directory. Directories with
61 changes below a cut-off percent (3% by default) are not shown. The
62 cut-off percent can be set with --dirstat=<limit>. Changes in a
63 child directory are not counted for the parent directory, unless
64 --cumulative is used.
65
66 --dirstat-by-file[=<limit>]
67 Same as --dirstat, but counts changed files instead of lines.
68
69 --summary
70 Output a condensed summary of extended header information such as
71 creations, renames and mode changes.
72
73 --patch-with-stat
74 Synonym for -p --stat.
75
76 -z
77 When --raw, --numstat, --name-only or --name-status has been given,
78 do not munge pathnames and use NULs as output field terminators.
79
80 Without this option, each pathname output will have TAB, LF, double
81 quotes, and backslash characters replaced with \t, \n, \", and \\,
82 respectively, and the pathname will be enclosed in double quotes if
83 any of those replacements occurred.
84
85 --name-only
86 Show only names of changed files.
87
88 --name-status
89 Show only names and status of changed files. See the description of
90 the --diff-filter option on what the status letters mean.
91
92 --submodule[=<format>]
93 Chose the output format for submodule differences. <format> can be
94 one of short and log. short just shows pairs of commit names, this
95 format is used when this option is not given. log is the default
96 value for this option and lists the commits in that commit range
97 like the summary option of git-submodule(1) does.
98
99 --color[=<when>]
100 Show colored diff. The value must be always (the default), never,
101 or auto.
102
103 --no-color
104 Turn off colored diff, even when the configuration file gives the
105 default to color output. Same as --color=never.
106
107 --word-diff[=<mode>]
108 Show a word diff, using the <mode> to delimit changed words. By
109 default, words are delimited by whitespace; see --word-diff-regex
110 below. The <mode> defaults to plain, and must be one of:
111
112 color
113 Highlight changed words using only colors. Implies --color.
114
115 plain
116 Show words as [-removed-] and {added}. Makes no attempts to
117 escape the delimiters if they appear in the input, so the
118 output may be ambiguous.
119
120 porcelain
121 Use a special line-based format intended for script
122 consumption. Added/removed/unchanged runs are printed in the
123 usual unified diff format, starting with a +/-/` ` character at
124 the beginning of the line and extending to the end of the line.
125 Newlines in the input are represented by a tilde ~ on a line of
126 its own.
127
128 none
129 Disable word diff again.
130
131 Note that despite the name of the first mode, color is used to
132 highlight the changed parts in all modes if enabled.
133
134 --word-diff-regex=<regex>
135 Use <regex> to decide what a word is, instead of considering runs
136 of non-whitespace to be a word. Also implies --word-diff unless it
137 was already enabled.
138
139 Every non-overlapping match of the <regex> is considered a word.
140 Anything between these matches is considered whitespace and
141 ignored(!) for the purposes of finding differences. You may want to
142 append |[^[:space:]] to your regular expression to make sure that
143 it matches all non-whitespace characters. A match that contains a
144 newline is silently truncated(!) at the newline.
145
146 The regex can also be set via a diff driver or configuration
147 option, see gitattributes(1) or git-config(1). Giving it explicitly
148 overrides any diff driver or configuration setting. Diff drivers
149 override configuration settings.
150
151 --color-words[=<regex>]
152 Equivalent to --word-diff=color plus (if a regex was specified)
153 --word-diff-regex=<regex>.
154
155 --no-renames
156 Turn off rename detection, even when the configuration file gives
157 the default to do so.
158
159 --check
160 Warn if changes introduce trailing whitespace or an indent that
161 uses a space before a tab. Exits with non-zero status if problems
162 are found. Not compatible with --exit-code.
163
164 --full-index
165 Instead of the first handful of characters, show the full pre- and
166 post-image blob object names on the "index" line when generating
167 patch format output.
168
169 --binary
170 In addition to --full-index, output a binary diff that can be
171 applied with git-apply.
172
173 --abbrev[=<n>]
174 Instead of showing the full 40-byte hexadecimal object name in
175 diff-raw format output and diff-tree header lines, show only a
176 partial prefix. This is independent of the --full-index option
177 above, which controls the diff-patch output format. Non default
178 number of digits can be specified with --abbrev=<n>.
179
180 -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
181 Break complete rewrite changes into pairs of delete and create.
182 This serves two purposes:
183
184 It affects the way a change that amounts to a total rewrite of a
185 file not as a series of deletion and insertion mixed together with
186 a very few lines that happen to match textually as the context, but
187 as a single deletion of everything old followed by a single
188 insertion of everything new, and the number m controls this aspect
189 of the -B option (defaults to 60%). -B/70% specifies that less
190 than 30% of the original should remain in the result for git to
191 consider it a total rewrite (i.e. otherwise the resulting patch
192 will be a series of deletion and insertion mixed together with
193 context lines).
194
195 When used with -M, a totally-rewritten file is also considered as
196 the source of a rename (usually -M only considers a file that
197 disappeared as the source of a rename), and the number n controls
198 this aspect of the -B option (defaults to 50%). -B20% specifies
199 that a change with addition and deletion compared to 20% or more of
200 the file’s size are eligible for being picked up as a possible
201 source of a rename to another file.
202
203 -M[<n>], --find-renames[=<n>]
204 Detect renames. If n is specified, it is a is a threshold on the
205 similarity index (i.e. amount of addition/deletions compared to the
206 file’s size). For example, -M90% means git should consider a
207 delete/add pair to be a rename if more than 90% of the file hasn’t
208 changed.
209
210 -C[<n>], --find-copies[=<n>]
211 Detect copies as well as renames. See also --find-copies-harder. If
212 n is specified, it has the same meaning as for -M<n>.
213
214 --find-copies-harder
215 For performance reasons, by default, -C option finds copies only if
216 the original file of the copy was modified in the same changeset.
217 This flag makes the command inspect unmodified files as candidates
218 for the source of copy. This is a very expensive operation for
219 large projects, so use it with caution. Giving more than one -C
220 option has the same effect.
221
222 -l<num>
223 The -M and -C options require O(n^2) processing time where n is the
224 number of potential rename/copy targets. This option prevents
225 rename/copy detection from running if the number of rename/copy
226 targets exceeds the specified number.
227
228 --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
229 Select only files that are Added (A), Copied (C), Deleted (D),
230 Modified (M), Renamed (R), have their type (i.e. regular file,
231 symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
232 (X), or have had their pairing Broken (B). Any combination of the
233 filter characters (including none) can be used. When *
234 (All-or-none) is added to the combination, all paths are selected
235 if there is any file that matches other criteria in the comparison;
236 if there is no file that matches other criteria, nothing is
237 selected.
238
239 -S<string>
240 Look for differences that introduce or remove an instance of
241 <string>. Note that this is different than the string simply
242 appearing in diff output; see the pickaxe entry in gitdiffcore(7)
243 for more details.
244
245 -G<regex>
246 Look for differences whose added or removed line matches the given
247 <regex>.
248
249 --pickaxe-all
250 When -S or -G finds a change, show all the changes in that
251 changeset, not just the files that contain the change in <string>.
252
253 --pickaxe-regex
254 Make the <string> not a plain string but an extended POSIX regex to
255 match.
256
257 -O<orderfile>
258 Output the patch in the order specified in the <orderfile>, which
259 has one shell glob pattern per line.
260
261 -R
262 Swap two inputs; that is, show differences from index or on-disk
263 file to tree contents.
264
265 --relative[=<path>]
266 When run from a subdirectory of the project, it can be told to
267 exclude changes outside the directory and show pathnames relative
268 to it with this option. When you are not in a subdirectory (e.g. in
269 a bare repository), you can name which subdirectory to make the
270 output relative to by giving a <path> as an argument.
271
272 -a, --text
273 Treat all files as text.
274
275 --ignore-space-at-eol
276 Ignore changes in whitespace at EOL.
277
278 -b, --ignore-space-change
279 Ignore changes in amount of whitespace. This ignores whitespace at
280 line end, and considers all other sequences of one or more
281 whitespace characters to be equivalent.
282
283 -w, --ignore-all-space
284 Ignore whitespace when comparing lines. This ignores differences
285 even if one line has whitespace where the other line has none.
286
287 --inter-hunk-context=<lines>
288 Show the context between diff hunks, up to the specified number of
289 lines, thereby fusing hunks that are close to each other.
290
291 --exit-code
292 Make the program exit with codes similar to diff(1). That is, it
293 exits with 1 if there were differences and 0 means no differences.
294
295 --quiet
296 Disable all output of the program. Implies --exit-code.
297
298 --ext-diff
299 Allow an external diff helper to be executed. If you set an
300 external diff driver with gitattributes(5), you need to use this
301 option with git-log(1) and friends.
302
303 --no-ext-diff
304 Disallow external diff drivers.
305
306 --ignore-submodules[=<when>]
307 Ignore changes to submodules in the diff generation. <when> can be
308 either "none", "untracked", "dirty" or "all", which is the default
309 Using "none" will consider the submodule modified when it either
310 contains untracked or modified files or its HEAD differs from the
311 commit recorded in the superproject and can be used to override any
312 settings of the ignore option in git-config(1) or gitmodules(5).
313 When "untracked" is used submodules are not considered dirty when
314 they only contain untracked content (but they are still scanned for
315 modified content). Using "dirty" ignores all changes to the work
316 tree of submodules, only changes to the commits stored in the
317 superproject are shown (this was the behavior until 1.7.0). Using
318 "all" hides all changes to submodules.
319
320 --src-prefix=<prefix>
321 Show the given source prefix instead of "a/".
322
323 --dst-prefix=<prefix>
324 Show the given destination prefix instead of "b/".
325
326 --no-prefix
327 Do not show any source or destination prefix.
328
329 For more detailed explanation on these common options, see also
330 gitdiffcore(7).
331
332 <tree-ish>
333 The id of a tree object.
334
335 <path>...
336 If provided, the results are limited to a subset of files matching
337 one of these prefix strings. i.e., file matches
338 /^<pattern1>|<pattern2>|.../ Note that this parameter does not
339 provide any wildcard or regexp features.
340
341 -r
342 recurse into sub-trees
343
344 -t
345 show tree entry itself as well as subtrees. Implies -r.
346
347 --root
348 When --root is specified the initial commit will be shown as a big
349 creation event. This is equivalent to a diff against the NULL tree.
350
351 --stdin
352 When --stdin is specified, the command does not take <tree-ish>
353 arguments from the command line. Instead, it reads lines containing
354 either two <tree>, one <commit>, or a list of <commit> from its
355 standard input. (Use a single space as separator.)
356
357 When two trees are given, it compares the first tree with the
358 second. When a single commit is given, it compares the commit with
359 its parents. The remaining commits, when given, are used as if they
360 are parents of the first commit.
361
362 When comparing two trees, the ID of both trees (separated by a
363 space and terminated by a newline) is printed before the
364 difference. When comparing commits, the ID of the first (or only)
365 commit, followed by a newline, is printed.
366
367 The following flags further affect the behavior when comparing
368 commits (but not trees).
369
370 -m
371 By default, git diff-tree --stdin does not show differences for
372 merge commits. With this flag, it shows differences to that commit
373 from all of its parents. See also -c.
374
375 -s
376 By default, git diff-tree --stdin shows differences, either in
377 machine-readable form (without -p) or in patch form (with -p). This
378 output can be suppressed. It is only useful with -v flag.
379
380 -v
381 This flag causes git diff-tree --stdin to also show the commit
382 message before the differences.
383
384 --pretty[=<format>], --format=<format>
385 Pretty-print the contents of the commit logs in a given format,
386 where <format> can be one of oneline, short, medium, full, fuller,
387 email, raw and format:<string>. See the "PRETTY FORMATS" section
388 for some additional details for each format. When omitted, the
389 format defaults to medium.
390
391 Note: you can specify the default pretty format in the repository
392 configuration (see git-config(1)).
393
394 --abbrev-commit
395 Instead of showing the full 40-byte hexadecimal commit object name,
396 show only a partial prefix. Non default number of digits can be
397 specified with "--abbrev=<n>" (which also modifies diff output, if
398 it is displayed).
399
400 This should make "--pretty=oneline" a whole lot more readable for
401 people using 80-column terminals.
402
403 --oneline
404 This is a shorthand for "--pretty=oneline --abbrev-commit" used
405 together.
406
407 --encoding[=<encoding>]
408 The commit objects record the encoding used for the log message in
409 their encoding header; this option can be used to tell the command
410 to re-code the commit log message in the encoding preferred by the
411 user. For non plumbing commands this defaults to UTF-8.
412
413 --no-notes, --show-notes[=<ref>]
414 Show the notes (see git-notes(1)) that annotate the commit, when
415 showing the commit log message. This is the default for git log,
416 git show and git whatchanged commands when there is no --pretty,
417 --format nor --oneline option is given on the command line.
418
419 With an optional argument, add this ref to the list of notes. The
420 ref is taken to be in refs/notes/ if it is not qualified.
421
422 --[no-]standard-notes
423 Enable or disable populating the notes ref list from the
424 core.notesRef and notes.displayRef variables (or corresponding
425 environment overrides). Enabled by default. See git-config(1).
426
427 --no-commit-id
428
429 git diff-tree outputs a line with the commit ID when applicable.
430 This flag suppressed the commit ID output.
431
432 -c
433 This flag changes the way a merge commit is displayed (which means
434 it is useful only when the command is given one <tree-ish>, or
435 --stdin). It shows the differences from each of the parents to the
436 merge result simultaneously instead of showing pairwise diff
437 between a parent and the result one at a time (which is what the -m
438 option does). Furthermore, it lists only files which were modified
439 from all parents.
440
441 --cc
442 This flag changes the way a merge commit patch is displayed, in a
443 similar way to the -c option. It implies the -c and -p options and
444 further compresses the patch output by omitting uninteresting hunks
445 whose the contents in the parents have only two variants and the
446 merge result picks one of them without modification. When all hunks
447 are uninteresting, the commit itself and the commit log message is
448 not shown, just like in any other "empty diff" case.
449
450 --always
451 Show the commit itself and the commit log message even if the diff
452 itself is empty.
453
455 If the commit is a merge, and if the pretty-format is not oneline,
456 email or raw, an additional line is inserted before the Author: line.
457 This line begins with "Merge: " and the sha1s of ancestral commits are
458 printed, separated by spaces. Note that the listed commits may not
459 necessarily be the list of the direct parent commits if you have
460 limited your view of history: for example, if you are only interested
461 in changes related to a certain directory or file.
462
463 There are several built-in formats, and you can define additional
464 formats by setting a pretty.<name> config option to either another
465 format name, or a format: string, as described below (see git-
466 config(1)). Here are the details of the built-in formats:
467
468 · oneline
469
470 <sha1> <title line>
471
472 This is designed to be as compact as possible.
473
474 · short
475
476 commit <sha1>
477 Author: <author>
478
479 <title line>
480
481 · medium
482
483 commit <sha1>
484 Author: <author>
485 Date: <author date>
486
487 <title line>
488
489 <full commit message>
490
491 · full
492
493 commit <sha1>
494 Author: <author>
495 Commit: <committer>
496
497 <title line>
498
499 <full commit message>
500
501 · fuller
502
503 commit <sha1>
504 Author: <author>
505 AuthorDate: <author date>
506 Commit: <committer>
507 CommitDate: <committer date>
508
509 <title line>
510
511 <full commit message>
512
513 · email
514
515 From <sha1> <date>
516 From: <author>
517 Date: <author date>
518 Subject: [PATCH] <title line>
519
520 <full commit message>
521
522 · raw
523
524 The raw format shows the entire commit exactly as stored in the
525 commit object. Notably, the SHA1s are displayed in full, regardless
526 of whether --abbrev or --no-abbrev are used, and parents
527 information show the true parent commits, without taking grafts nor
528 history simplification into account.
529
530 · format:<string>
531
532 The format:<string> format allows you to specify which information
533 you want to show. It works a little bit like printf format, with
534 the notable exception that you get a newline with %n instead of \n.
535
536 E.g, format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"
537 would show something like this:
538
539 The author of fe6e0ee was Junio C Hamano, 23 hours ago
540 The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
541
542 The placeholders are:
543
544 · %H: commit hash
545
546 · %h: abbreviated commit hash
547
548 · %T: tree hash
549
550 · %t: abbreviated tree hash
551
552 · %P: parent hashes
553
554 · %p: abbreviated parent hashes
555
556 · %an: author name
557
558 · %aN: author name (respecting .mailmap, see git-shortlog(1) or
559 git-blame(1))
560
561 · %ae: author email
562
563 · %aE: author email (respecting .mailmap, see git-shortlog(1) or
564 git-blame(1))
565
566 · %ad: author date (format respects --date= option)
567
568 · %aD: author date, RFC2822 style
569
570 · %ar: author date, relative
571
572 · %at: author date, UNIX timestamp
573
574 · %ai: author date, ISO 8601 format
575
576 · %cn: committer name
577
578 · %cN: committer name (respecting .mailmap, see git-shortlog(1)
579 or git-blame(1))
580
581 · %ce: committer email
582
583 · %cE: committer email (respecting .mailmap, see git-shortlog(1)
584 or git-blame(1))
585
586 · %cd: committer date
587
588 · %cD: committer date, RFC2822 style
589
590 · %cr: committer date, relative
591
592 · %ct: committer date, UNIX timestamp
593
594 · %ci: committer date, ISO 8601 format
595
596 · %d: ref names, like the --decorate option of git-log(1)
597
598 · %e: encoding
599
600 · %s: subject
601
602 · %f: sanitized subject line, suitable for a filename
603
604 · %b: body
605
606 · %B: raw body (unwrapped subject and body)
607
608 · %N: commit notes
609
610 · %gD: reflog selector, e.g., refs/stash@{1}
611
612 · %gd: shortened reflog selector, e.g., stash@{1}
613
614 · %gs: reflog subject
615
616 · %Cred: switch color to red
617
618 · %Cgreen: switch color to green
619
620 · %Cblue: switch color to blue
621
622 · %Creset: reset color
623
624 · %C(...): color specification, as described in color.branch.*
625 config option
626
627 · %m: left, right or boundary mark
628
629 · %n: newline
630
631 · %%: a raw %
632
633 · %x00: print a byte from a hex code
634
635 · %w([<w>[,<i1>[,<i2>]]]): switch line wrapping, like the -w
636 option of git-shortlog(1).
637
638 Note
639 Some placeholders may depend on other options given to the revision
640 traversal engine. For example, the %g* reflog options will insert
641 an empty string unless we are traversing reflog entries (e.g., by
642 git log -g). The %d placeholder will use the "short" decoration
643 format if --decorate was not already provided on the command line.
644
645 If you add a + (plus sign) after % of a placeholder, a line-feed is
646 inserted immediately before the expansion if and only if the
647 placeholder expands to a non-empty string.
648
649 If you add a - (minus sign) after % of a placeholder, line-feeds that
650 immediately precede the expansion are deleted if and only if the
651 placeholder expands to an empty string.
652
653 If you add a ` ` (space) after % of a placeholder, a space is inserted
654 immediately before the expansion if and only if the placeholder expands
655 to a non-empty string.
656
657 · tformat:
658
659 The tformat: format works exactly like format:, except that it
660 provides "terminator" semantics instead of "separator" semantics.
661 In other words, each commit has the message terminator character
662 (usually a newline) appended, rather than a separator placed
663 between entries. This means that the final entry of a single-line
664 format will be properly terminated with a new line, just as the
665 "oneline" format does. For example:
666
667 $ git log -2 --pretty=format:%h 4da45bef \
668 | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
669 4da45be
670 7134973 -- NO NEWLINE
671
672 $ git log -2 --pretty=tformat:%h 4da45bef \
673 | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
674 4da45be
675 7134973
676
677 In addition, any unrecognized string that has a % in it is
678 interpreted as if it has tformat: in front of it. For example,
679 these two are equivalent:
680
681 $ git log -2 --pretty=tformat:%h 4da45bef
682 $ git log -2 --pretty=%h 4da45bef
683
684
686 If you’re only interested in differences in a subset of files, for
687 example some architecture-specific files, you might do:
688
689 git diff-tree -r <tree-ish> <tree-ish> arch/ia64 include/asm-ia64
690
691 and it will only show you what changed in those two directories.
692
693 Or if you are searching for what changed in just kernel/sched.c, just
694 do
695
696 git diff-tree -r <tree-ish> <tree-ish> kernel/sched.c
697
698 and it will ignore all differences to other files.
699
700 The pattern is always the prefix, and is matched exactly. There are no
701 wildcards. Even stricter, it has to match a complete path component.
702 I.e. "foo" does not pick up foobar.h. "foo" does match foo/bar.h so it
703 can be used to name subdirectories.
704
705 An example of normal usage is:
706
707 torvalds@ppc970:~/git> git diff-tree 5319e4......
708 *100664->100664 blob ac348b.......->a01513....... git-fsck-objects.c
709
710 which tells you that the last commit changed just one file (it’s from
711 this one:
712
713 commit 3c6f7ca19ad4043e9e72fa94106f352897e651a8
714 tree 5319e4d609cdd282069cc4dce33c1db559539b03
715 parent b4e628ea30d5ab3606119d2ea5caeab141d38df7
716 author Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
717 committer Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
718
719 Make "git-fsck-objects" print out all the root commits it finds.
720
721 Once I do the reference tracking, I'll also make it print out all the
722 HEAD commits it finds, which is even more interesting.
723
724
725 in case you care).
726
728 The raw output format from "git-diff-index", "git-diff-tree",
729 "git-diff-files" and "git diff --raw" are very similar.
730
731 These commands all compare two sets of things; what is compared
732 differs:
733
734 git-diff-index <tree-ish>
735 compares the <tree-ish> and the files on the filesystem.
736
737 git-diff-index --cached <tree-ish>
738 compares the <tree-ish> and the index.
739
740 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
741 compares the trees named by the two arguments.
742
743 git-diff-files [<pattern>...]
744 compares the index and the files on the filesystem.
745
746 The "git-diff-tree" command begins its output by printing the hash of
747 what is being compared. After that, all the commands print one output
748 line per changed file.
749
750 An output line is formatted this way:
751
752 in-place edit :100644 100644 bcd1234... 0123456... M file0
753 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
754 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
755 create :000000 100644 0000000... 1234567... A file4
756 delete :100644 000000 1234567... 0000000... D file5
757 unmerged :000000 000000 0000000... 0000000... U file6
758
759
760 That is, from the left to the right:
761
762 1. a colon.
763
764 2. mode for "src"; 000000 if creation or unmerged.
765
766 3. a space.
767
768 4. mode for "dst"; 000000 if deletion or unmerged.
769
770 5. a space.
771
772 6. sha1 for "src"; 0{40} if creation or unmerged.
773
774 7. a space.
775
776 8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
777
778 9. a space.
779
780 10. status, followed by optional "score" number.
781
782 11. a tab or a NUL when -z option is used.
783
784 12. path for "src"
785
786 13. a tab or a NUL when -z option is used; only exists for C or R.
787
788 14. path for "dst"; only exists for C or R.
789
790 15. an LF or a NUL when -z option is used, to terminate the record.
791
792 Possible status letters are:
793
794 · A: addition of a file
795
796 · C: copy of a file into a new one
797
798 · D: deletion of a file
799
800 · M: modification of the contents or mode of a file
801
802 · R: renaming of a file
803
804 · T: change in the type of the file
805
806 · U: file is unmerged (you must complete the merge before it can be
807 committed)
808
809 · X: "unknown" change type (most probably a bug, please report it)
810
811 Status letters C and R are always followed by a score (denoting the
812 percentage of similarity between the source and target of the move or
813 copy), and are the only ones to be so.
814
815 <sha1> is shown as all 0’s if a file is new on the filesystem and it is
816 out of sync with the index.
817
818 Example:
819
820 :100644 100644 5be4a4...... 000000...... M file.c
821
822
823 When -z option is not used, TAB, LF, and backslash characters in
824 pathnames are represented as \t, \n, and \\, respectively.
825
827 "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
828 --cc option to generate diff output also for merge commits. The output
829 differs from the format described above in the following way:
830
831 1. there is a colon for each parent
832
833 2. there are more "src" modes and "src" sha1
834
835 3. status is concatenated status characters for each parent
836
837 4. no optional "score" number
838
839 5. single path, only for "dst"
840
841 Example:
842
843 ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c
844
845
846 Note that combined diff lists only files which were modified from all
847 parents.
848
850 When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
851 with a -p option, "git diff" without the --raw option, or "git log"
852 with the "-p" option, they do not produce the output described above;
853 instead they produce a patch file. You can customize the creation of
854 such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
855 environment variables.
856
857 What the -p option produces is slightly different from the traditional
858 diff format:
859
860 1. It is preceded with a "git diff" header that looks like this:
861
862 diff --git a/file1 b/file2
863
864 The a/ and b/ filenames are the same unless rename/copy is
865 involved. Especially, even for a creation or a deletion, /dev/null
866 is not used in place of the a/ or b/ filenames.
867
868 When rename/copy is involved, file1 and file2 show the name of the
869 source file of the rename/copy and the name of the file that
870 rename/copy produces, respectively.
871
872 2. It is followed by one or more extended header lines:
873
874 old mode <mode>
875 new mode <mode>
876 deleted file mode <mode>
877 new file mode <mode>
878 copy from <path>
879 copy to <path>
880 rename from <path>
881 rename to <path>
882 similarity index <number>
883 dissimilarity index <number>
884 index <hash>..<hash> <mode>
885
886 File modes are printed as 6-digit octal numbers including the file
887 type and file permission bits.
888
889 Path names in extended headers do not include the a/ and b/
890 prefixes.
891
892 The similarity index is the percentage of unchanged lines, and the
893 dissimilarity index is the percentage of changed lines. It is a
894 rounded down integer, followed by a percent sign. The similarity
895 index value of 100% is thus reserved for two equal files, while
896 100% dissimilarity means that no line from the old file made it
897 into the new one.
898
899 The index line includes the SHA-1 checksum before and after the
900 change. The <mode> is included if the file mode does not change;
901 otherwise, separate lines indicate the old and the new mode.
902
903 3. TAB, LF, double quote and backslash characters in pathnames are
904 represented as \t, \n, \" and \\, respectively. If there is need
905 for such substitution then the whole pathname is put in double
906 quotes.
907
908 4. All the file1 files in the output refer to files before the commit,
909 and all the file2 files refer to files after the commit. It is
910 incorrect to apply each change to each file sequentially. For
911 example, this patch will swap a and b:
912
913 diff --git a/a b/b
914 rename from a
915 rename to b
916 diff --git a/b b/a
917 rename from b
918 rename to a
919
921 Any diff-generating command can take the ‘-c` or --cc option to produce
922 a combined diff when showing a merge. This is the default format when
923 showing merges with git-diff(1) or git-show(1). Note also that you can
924 give the `-m’ option to any of these commands to force generation of
925 diffs with individual parents of a merge.
926
927 A combined diff format looks like this:
928
929 diff --combined describe.c
930 index fabadb8,cc95eb0..4866510
931 --- a/describe.c
932 +++ b/describe.c
933 @@@ -98,20 -98,12 +98,20 @@@
934 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
935 }
936
937 - static void describe(char *arg)
938 -static void describe(struct commit *cmit, int last_one)
939 ++static void describe(char *arg, int last_one)
940 {
941 + unsigned char sha1[20];
942 + struct commit *cmit;
943 struct commit_list *list;
944 static int initialized = 0;
945 struct commit_name *n;
946
947 + if (get_sha1(arg, sha1) < 0)
948 + usage(describe_usage);
949 + cmit = lookup_commit_reference(sha1);
950 + if (!cmit)
951 + usage(describe_usage);
952 +
953 if (!initialized) {
954 initialized = 1;
955 for_each_ref(get_name);
956
957
958
959 1. It is preceded with a "git diff" header, that looks like this (when
960 -c option is used):
961
962 diff --combined file
963
964 or like this (when --cc option is used):
965
966 diff --cc file
967
968 2. It is followed by one or more extended header lines (this example
969 shows a merge with two parents):
970
971 index <hash>,<hash>..<hash>
972 mode <mode>,<mode>..<mode>
973 new file mode <mode>
974 deleted file mode <mode>,<mode>
975
976 The mode <mode>,<mode>..<mode> line appears only if at least one of
977 the <mode> is different from the rest. Extended headers with
978 information about detected contents movement (renames and copying
979 detection) are designed to work with diff of two <tree-ish> and are
980 not used by combined diff format.
981
982 3. It is followed by two-line from-file/to-file header
983
984 --- a/file
985 +++ b/file
986
987 Similar to two-line header for traditional unified diff format,
988 /dev/null is used to signal created or deleted files.
989
990 4. Chunk header format is modified to prevent people from accidentally
991 feeding it to patch -p1. Combined diff format was created for
992 review of merge commit changes, and was not meant for apply. The
993 change is similar to the change in the extended index header:
994
995 @@@ <from-file-range> <from-file-range> <to-file-range> @@@
996
997 There are (number of parents + 1) @ characters in the chunk header
998 for combined diff format.
999
1000 Unlike the traditional unified diff format, which shows two files A and
1001 B with a single column that has - (minus — appears in A but removed in
1002 B), + (plus — missing in A but added to B), or " " (space — unchanged)
1003 prefix, this format compares two or more files file1, file2,... with
1004 one file X, and shows how X differs from each of fileN. One column for
1005 each of fileN is prepended to the output line to note how X’s line is
1006 different from it.
1007
1008 A - character in the column N means that the line appears in fileN but
1009 it does not appear in the result. A + character in the column N means
1010 that the line appears in the result, and fileN does not have that line
1011 (in other words, the line was added, from the point of view of that
1012 parent).
1013
1014 In the above example output, the function signature was changed from
1015 both files (hence two - removals from both file1 and file2, plus ++ to
1016 mean one line that was added does not appear in either file1 nor
1017 file2). Also eight other lines are the same from file1 but do not
1018 appear in file2 (hence prefixed with +).
1019
1020 When shown by git diff-tree -c, it compares the parents of a merge
1021 commit with the merge result (i.e. file1..fileN are the parents). When
1022 shown by git diff-files -c, it compares the two unresolved merge
1023 parents with the working tree file (i.e. file1 is stage 2 aka "our
1024 version", file2 is stage 3 aka "their version").
1025
1027 The --summary option describes newly added, deleted, renamed and copied
1028 files. The --stat option adds diffstat(1) graph to the output. These
1029 options can be combined with other options, such as -p, and are meant
1030 for human consumption.
1031
1032 When showing a change that involves a rename or a copy, --stat output
1033 formats the pathnames compactly by combining common prefix and suffix
1034 of the pathnames. For example, a change that moves arch/i386/Makefile
1035 to arch/x86/Makefile while modifying 4 lines will be shown like this:
1036
1037 arch/{i386 => x86}/Makefile | 4 +--
1038
1039
1040 The --numstat option gives the diffstat(1) information but is designed
1041 for easier machine consumption. An entry in --numstat output looks like
1042 this:
1043
1044 1 2 README
1045 3 1 arch/{i386 => x86}/Makefile
1046
1047
1048 That is, from left to right:
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. pathname (possibly with rename/copy information);
1059
1060 6. a newline.
1061
1062 When -z output option is in effect, the output is formatted this way:
1063
1064 1 2 README NUL
1065 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
1066
1067
1068 That is:
1069
1070 1. the number of added lines;
1071
1072 2. a tab;
1073
1074 3. the number of deleted lines;
1075
1076 4. a tab;
1077
1078 5. a NUL (only exists if renamed/copied);
1079
1080 6. pathname in preimage;
1081
1082 7. a NUL (only exists if renamed/copied);
1083
1084 8. pathname in postimage (only exists if renamed/copied);
1085
1086 9. a NUL.
1087
1088 The extra NUL before the preimage path in renamed case is to allow
1089 scripts that read the output to tell if the current record being read
1090 is a single-path record or a rename/copy record without reading ahead.
1091 After reading added and deleted lines, reading up to NUL would yield
1092 the pathname, but if that is NUL, the record will show two paths.
1093
1095 Written by Linus Torvalds <torvalds@osdl.org[1]>
1096
1098 Documentation by David Greaves, Junio C Hamano and the git-list
1099 <git@vger.kernel.org[2]>.
1100
1102 Part of the git(1) suite
1103
1105 1. torvalds@osdl.org
1106 mailto:torvalds@osdl.org
1107
1108 2. git@vger.kernel.org
1109 mailto:git@vger.kernel.org
1110
1111
1112
1113Git 1.7.4.4 04/11/2011 GIT-DIFF-TREE(1)