1GIT-DIFF-TREE(1)                  Git Manual                  GIT-DIFF-TREE(1)
2
3
4

NAME

6       git-diff-tree - Compares the content and mode of blobs found via two
7       tree objects
8

SYNOPSIS

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

DESCRIPTION

15       Compares the content and mode of the blobs found via two tree objects.
16
17       If there is only one <tree-ish> given, the commit is compared with its
18       parents (see --stdin below).
19
20       Note that "git-diff-tree" can use the tree encapsulated in a commit
21       object.
22

OPTIONS

24       -p
25           Generate patch (see section on generating patches)
26
27       -u
28           Synonym for "-p".
29
30       -U<n>
31           Shorthand for "--unified=<n>".
32
33       --unified=<n>
34           Generate diffs with <n> lines of context instead of the usual
35           three. Implies "-p".
36
37       --raw
38           Generate the raw format.
39
40       --patch-with-raw
41           Synonym for "-p --raw".
42
43       --stat[=width[,name-width]]
44           Generate a diffstat. You can override the default output width for
45           80-column terminal by "--stat=width". The width of the filename
46           part can be controlled by giving another width to it separated by a
47           comma.
48
49       --numstat
50           Similar to --stat, but shows number of added and deleted lines in
51           decimal notation and pathname without abbreviation, to make it more
52           machine friendly. For binary files, outputs two - instead of saying
53           0 0.
54
55       --shortstat
56           Output only the last line of the --stat format containing total
57           number of modified files, as well as number of added and deleted
58           lines.
59
60       --summary
61           Output a condensed summary of extended header information such as
62           creations, renames and mode changes.
63
64       --patch-with-stat
65           Synonym for "-p --stat".
66
67       -z
68           NUL-line termination on output. This affects the --raw output field
69           terminator. Also output from commands such as "git-log" will be
70           delimited with NUL between commits.
71
72       --name-only
73           Show only names of changed files.
74
75       --name-status
76           Show only names and status of changed files.
77
78       --color
79           Show colored diff.
80
81       --no-color
82           Turn off colored diff, even when the configuration file gives the
83           default to color output.
84
85       --color-words
86           Show colored word diff, i.e. color words which have changed.
87
88       --no-renames
89           Turn off rename detection, even when the configuration file gives
90           the default to do so.
91
92       --check
93           Warn if changes introduce trailing whitespace or an indent that
94           uses a space before a tab.
95
96       --full-index
97           Instead of the first handful characters, show full object name of
98           pre- and post-image blob on the "index" line when generating a
99           patch format output.
100
101       --binary
102           In addition to --full-index, output "binary diff" that can be
103           applied with "git apply".
104
105       --abbrev[=<n>]
106           Instead of showing the full 40-byte hexadecimal object name in
107           diff-raw format output and diff-tree header lines, show only
108           handful hexdigits prefix. This is independent of --full-index
109           option above, which controls the diff-patch output format. Non
110           default number of digits can be specified with --abbrev=<n>.
111
112       -B
113           Break complete rewrite changes into pairs of delete and create.
114
115       -M
116           Detect renames.
117
118       -C
119           Detect copies as well as renames. See also --find-copies-harder.
120
121       --diff-filter=[ACDMRTUXB*]
122           Select only files that are Added (A), Copied (C), Deleted (D),
123           Modified (M), Renamed (R), have their type (mode) changed (T), are
124           Unmerged (U), are Unknown (X), or have had their pairing Broken
125           (B). Any combination of the filter characters may be used. When *
126           (All-or-none) is added to the combination, all paths are selected
127           if there is any file that matches other criteria in the comparison;
128           if there is no file that matches other criteria, nothing is
129           selected.
130
131       --find-copies-harder
132           For performance reasons, by default, -C option finds copies only if
133           the original file of the copy was modified in the same changeset.
134           This flag makes the command inspect unmodified files as candidates
135           for the source of copy. This is a very expensive operation for
136           large projects, so use it with caution. Giving more than one -C
137           option has the same effect.
138
139       -l<num>
140           -M and -C options require O(n^2) processing time where n is the
141           number of potential rename/copy targets. This option prevents
142           rename/copy detection from running if the number of rename/copy
143           targets exceeds the specified number.
144
145       -S<string>
146           Look for differences that contain the change in <string>.
147
148       --pickaxe-all
149           When -S finds a change, show all the changes in that changeset, not
150           just the files that contain the change in <string>.
151
152       --pickaxe-regex
153           Make the <string> not a plain string but an extended POSIX regex to
154           match.
155
156       -O<orderfile>
157           Output the patch in the order specified in the <orderfile>, which
158           has one shell glob pattern per line.
159
160       -R
161           Swap two inputs; that is, show differences from index or on-disk
162           file to tree contents.
163
164       --text
165           Treat all files as text.
166
167       -a
168           Shorthand for "--text".
169
170       --ignore-space-at-eol
171           Ignore changes in white spaces at EOL.
172
173       --ignore-space-change
174           Ignore changes in amount of white space. This ignores white space
175           at line end, and consider all other sequences of one or more white
176           space characters to be equivalent.
177
178       -b
179           Shorthand for "--ignore-space-change".
180
181       --ignore-all-space
182           Ignore white space when comparing lines. This ignores difference
183           even if one line has white space where the other line has none.
184
185       -w
186           Shorthand for "--ignore-all-space".
187
188       --exit-code
189           Make the program exit with codes similar to diff(1). That is, it
190           exits with 1 if there were differences and 0 means no differences.
191
192       --quiet
193           Disable all output of the program. Implies --exit-code.
194
195       --ext-diff
196           Allow an external diff helper to be executed. If you set an
197           external diff driver with gitlink:gitattributes(5), you need to use
198           this option with gitlink:git-log(1) and friends.
199
200       --no-ext-diff
201           Disallow external diff drivers.
202       For more detailed explanation on these common options, see also
203       diffcore documentation[1].
204
205       <tree-ish>
206           The id of a tree object.
207
208       <path>...
209           If provided, the results are limited to a subset of files matching
210           one of these prefix strings. i.e., file matches
211           /^<pattern1>|<pattern2>|.../ Note that this parameter does not
212           provide any wildcard or regexp features.
213
214       -r
215           recurse into sub-trees
216
217       -t
218           show tree entry itself as well as subtrees. Implies -r.
219
220       --root
221           When --root is specified the initial commit will be showed as a big
222           creation event. This is equivalent to a diff against the NULL tree.
223
224       --stdin
225           When --stdin is specified, the command does not take <tree-ish>
226           arguments from the command line. Instead, it reads either one
227           <commit> or a pair of <tree-ish> separated with a single space from
228           its standard input.
229
230           When a single commit is given on one line of such input, it
231           compares the commit with its parents. The following flags further
232           affects its behavior. This does not apply to the case where two
233           <tree-ish> separated with a single space are given.
234
235       -m
236           By default, "git-diff-tree --stdin" does not show differences for
237           merge commits. With this flag, it shows differences to that commit
238           from all of its parents. See also -c.
239
240       -s
241           By default, "git-diff-tree --stdin" shows differences, either in
242           machine-readable form (without -p) or in patch form (with -p). This
243           output can be suppressed. It is only useful with -v flag.
244
245       -v
246           This flag causes "git-diff-tree --stdin" to also show the commit
247           message before the differences.
248
249       --pretty[=<format>]
250           Pretty-print the contents of the commit logs in a given format,
251           where <format> can be one of oneline, short, medium, full, fuller,
252           email, raw and format:<string>. When omitted, the format defaults
253           to medium.
254
255       --abbrev-commit
256           Instead of showing the full 40-byte hexadecimal commit object name,
257           show only handful hexdigits prefix. Non default number of digits
258           can be specified with "--abbrev=<n>" (which also modifies diff
259           output, if it is displayed).
260
261           This should make "--pretty=oneline" a whole lot more readable for
262           people using 80-column terminals.
263
264       --encoding[=<encoding>]
265           The commit objects record the encoding used for the log message in
266           their encoding header; this option can be used to tell the command
267           to re-code the commit log message in the encoding preferred by the
268           user. For non plumbing commands this defaults to UTF-8.
269
270       --no-commit-id
271           git-diff-tree outputs a line with the commit ID when applicable.
272           This flag suppressed the commit ID output.
273
274       -c
275           This flag changes the way a merge commit is displayed (which means
276           it is useful only when the command is given one <tree-ish>, or
277           --stdin). It shows the differences from each of the parents to the
278           merge result simultaneously instead of showing pairwise diff
279           between a parent and the result one at a time (which is what the -m
280           option does). Furthermore, it lists only files which were modified
281           from all parents.
282
283       --cc
284           This flag changes the way a merge commit patch is displayed, in a
285           similar way to the -c option. It implies the -c and -p options and
286           further compresses the patch output by omitting hunks that show
287           differences from only one parent, or show the same change from all
288           but one parent for an Octopus merge. When this optimization makes
289           all hunks disappear, the commit itself and the commit log message
290           is not shown, just like in any other "empty diff" case.
291
292       --always
293           Show the commit itself and the commit log message even if the diff
294           itself is empty.
295

PRETTY FORMATS

297       If the commit is a merge, and if the pretty-format is not oneline,
298       email or raw, an additional line is inserted before the Author: line.
299       This line begins with "Merge: " and the sha1s of ancestral commits are
300       printed, separated by spaces. Note that the listed commits may not
301       necessarily be the list of the direct parent commits if you have
302       limited your view of history: for example, if you are only interested
303       in changes related to a certain directory or file.
304
305       Here are some additional details for each format:
306
307
308       ·   oneline
309
310
311               <sha1> <title line>
312           This is designed to be as compact as possible.
313
314       ·   short
315
316
317               commit <sha1>
318               Author: <author>
319
320               <title line>
321
322       ·   medium
323
324
325               commit <sha1>
326               Author: <author>
327               Date: <date>
328
329               <title line>
330
331               <full commit message>
332
333       ·   full
334
335
336               commit <sha1>
337               Author: <author>
338               Commit: <committer>
339
340               <title line>
341
342               <full commit message>
343
344       ·   fuller
345
346
347               commit <sha1>
348               Author: <author>
349               AuthorDate: <date & time>
350               Commit: <committer>
351               CommitDate: <date & time>
352
353               <title line>
354
355               <full commit message>
356
357       ·   email
358
359
360               From <sha1> <date>
361               From: <author>
362               Date: <date & time>
363               Subject: [PATCH] <title line>
364
365               <full commit message>
366
367       ·   raw
368
369           The raw format shows the entire commit exactly as stored in the
370           commit object. Notably, the SHA1s are displayed in full, regardless
371           of whether --abbrev or --no-abbrev are used, and parents
372           information show the true parent commits, without taking grafts nor
373           history simplification into account.
374
375       ·   format:
376
377           The format: format allows you to specify which information you want
378           to show. It works a little bit like printf format, with the notable
379           exception that you get a newline with %n instead of \n.
380
381           E.g, format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"
382           would show something like this:
383
384
385
386               The author of fe6e0ee was Junio C Hamano, 23 hours ago
387               The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
388
389
390           The placeholders are:
391
392
393           ·   %H: commit hash
394
395           ·   %h: abbreviated commit hash
396
397           ·   %T: tree hash
398
399           ·   %t: abbreviated tree hash
400
401           ·   %P: parent hashes
402
403           ·   %p: abbreviated parent hashes
404
405           ·   %an: author name
406
407           ·   %ae: author email
408
409           ·   %ad: author date
410
411           ·   %aD: author date, RFC2822 style
412
413           ·   %ar: author date, relative
414
415           ·   %at: author date, UNIX timestamp
416
417           ·   %ai: author date, ISO 8601 format
418
419           ·   %cn: committer name
420
421           ·   %ce: committer email
422
423           ·   %cd: committer date
424
425           ·   %cD: committer date, RFC2822 style
426
427           ·   %cr: committer date, relative
428
429           ·   %ct: committer date, UNIX timestamp
430
431           ·   %ci: committer date, ISO 8601 format
432
433           ·   %e: encoding
434
435           ·   %s: subject
436
437           ·   %b: body
438
439           ·   %Cred: switch color to red
440
441           ·   %Cgreen: switch color to green
442
443           ·   %Cblue: switch color to blue
444
445           ·   %Creset: reset color
446
447           ·   %m: left, right or boundary mark
448
449           ·   %n: newline
450

LIMITING OUTPUT

452       If you´re only interested in differences in a subset of files, for
453       example some architecture-specific files, you might do:
454
455
456           git-diff-tree -r <tree-ish> <tree-ish> arch/ia64 include/asm-ia64
457       and it will only show you what changed in those two directories.
458
459       Or if you are searching for what changed in just kernel/sched.c, just
460       do
461
462
463           git-diff-tree -r <tree-ish> <tree-ish> kernel/sched.c
464       and it will ignore all differences to other files.
465
466       The pattern is always the prefix, and is matched exactly. There are no
467       wildcards. Even stricter, it has to match a complete path component.
468       I.e. "foo" does not pick up foobar.h. "foo" does match foo/bar.h so it
469       can be used to name subdirectories.
470
471       An example of normal usage is:
472
473
474           torvalds@ppc970:~/git> git-diff-tree 5319e4......
475           *100664->100664 blob    ac348b.......->a01513.......      git-fsck-objects.c
476       which tells you that the last commit changed just one file (it´s from
477       this one:
478
479
480
481           commit 3c6f7ca19ad4043e9e72fa94106f352897e651a8
482           tree 5319e4d609cdd282069cc4dce33c1db559539b03
483           parent b4e628ea30d5ab3606119d2ea5caeab141d38df7
484           author Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
485           committer Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
486
487           Make "git-fsck-objects" print out all the root commits it finds.
488
489           Once I do the reference tracking, I´ll also make it print out all the
490           HEAD commits it finds, which is even more interesting.
491
492       in case you care).
493

OUTPUT FORMAT

495       The output format from "git-diff-index", "git-diff-tree" and
496       "git-diff-files" are very similar.
497
498       These commands all compare two sets of things; what is compared
499       differs:
500
501       git-diff-index <tree-ish>
502           compares the <tree-ish> and the files on the filesystem.
503
504       git-diff-index --cached <tree-ish>
505           compares the <tree-ish> and the index.
506
507       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
508           compares the trees named by the two arguments.
509
510       git-diff-files [<pattern>...]
511           compares the index and the files on the filesystem.
512       An output line is formatted this way:
513
514
515
516           in-place edit  :100644 100644 bcd1234... 0123456... M file0
517           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
518           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
519           create         :000000 100644 0000000... 1234567... A file4
520           delete         :100644 000000 1234567... 0000000... D file5
521           unmerged       :000000 000000 0000000... 0000000... U file6
522
523       That is, from the left to the right:
524
525
526        1.  a colon.
527
528        2.  mode for "src"; 000000 if creation or unmerged.
529
530        3.  a space.
531
532        4.  mode for "dst"; 000000 if deletion or unmerged.
533
534        5.  a space.
535
536        6.  sha1 for "src"; 0{40} if creation or unmerged.
537
538        7.  a space.
539
540        8.  sha1 for "dst"; 0{40} if creation, unmerged or "look at work
541           tree".
542
543        9.  a space.
544
545       10.  status, followed by optional "score" number.
546
547       11.  a tab or a NUL when -z option is used.
548
549       12.  path for "src"
550
551       13.  a tab or a NUL when -z option is used; only exists for C or R.
552
553       14.  path for "dst"; only exists for C or R.
554
555       15.  an LF or a NUL when -z option is used, to terminate the record.
556       <sha1> is shown as all 0´s if a file is new on the filesystem and it is
557       out of sync with the index.
558
559       Example:
560
561
562
563           :100644 100644 5be4a4...... 000000...... M file.c
564
565       When -z option is not used, TAB, LF, and backslash characters in
566       pathnames are represented as \t, \n, and \\, respectively.
567

DIFF FORMAT FOR MERGES

569       "git-diff-tree" and "git-diff-files" can take -c or --cc option to
570       generate diff output also for merge commits. The output differs from
571       the format described above in the following way:
572
573
574        1.  there is a colon for each parent
575
576        2.  there are more "src" modes and "src" sha1
577
578        3.  status is concatenated status characters for each parent
579
580        4.  no optional "score" number
581
582        5.  single path, only for "dst"
583       Example:
584
585
586
587           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
588
589       Note that combined diff lists only files which were modified from all
590       parents.
591

GENERATING PATCHES WITH -P

593       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
594       with a -p option, they do not produce the output described above;
595       instead they produce a patch file. You can customize the creation of
596       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
597       environment variables.
598
599       What the -p option produces is slightly different from the traditional
600       diff format.
601
602
603        1.  It is preceded with a "git diff" header, that looks like this:
604
605
606               diff --git a/file1 b/file2
607           The a/ and b/ filenames are the same unless rename/copy is
608           involved. Especially, even for a creation or a deletion, /dev/null
609           is not used in place of a/ or b/ filenames.
610
611           When rename/copy is involved, file1 and file2 show the name of the
612           source file of the rename/copy and the name of the file that
613           rename/copy produces, respectively.
614
615        2.  It is followed by one or more extended header lines:
616
617
618               old mode <mode>
619               new mode <mode>
620               deleted file mode <mode>
621               new file mode <mode>
622               copy from <path>
623               copy to <path>
624               rename from <path>
625               rename to <path>
626               similarity index <number>
627               dissimilarity index <number>
628               index <hash>..<hash> <mode>
629
630        3.  TAB, LF, double quote and backslash characters in pathnames are
631           represented as \t, \n, \" and \\, respectively. If there is need
632           for such substitution then the whole pathname is put in double
633           quotes.
634       The similarity index is the percentage of unchanged lines, and the
635       dissimilarity index is the percentage of changed lines. It is a rounded
636       down integer, followed by a percent sign. The similarity index value of
637       100% is thus reserved for two equal files, while 100% dissimilarity
638       means that no line from the old file made it into the new one.
639

COMBINED DIFF FORMAT

641       git-diff-tree and git-diff-files can take -c or --cc option to produce
642       combined diff, which looks like this:
643
644
645
646           diff --combined describe.c
647           index fabadb8,cc95eb0..4866510
648           --- a/describe.c
649           +++ b/describe.c
650           @@@ -98,20 -98,12 +98,20 @@@
651                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
652             }
653
654           - static void describe(char *arg)
655            -static void describe(struct commit *cmit, int last_one)
656           ++static void describe(char *arg, int last_one)
657             {
658            +      unsigned char sha1[20];
659            +      struct commit *cmit;
660                   struct commit_list *list;
661                   static int initialized = 0;
662                   struct commit_name *n;
663
664            +      if (get_sha1(arg, sha1) < 0)
665            +              usage(describe_usage);
666            +      cmit = lookup_commit_reference(sha1);
667            +      if (!cmit)
668            +              usage(describe_usage);
669            +
670                   if (!initialized) {
671                           initialized = 1;
672                           for_each_ref(get_name);
673
674
675        1.  It is preceded with a "git diff" header, that looks like this
676           (when -c option is used):
677
678
679               diff --combined file
680           or like this (when --cc option is used):
681
682
683               diff --c file
684
685        2.  It is followed by one or more extended header lines (this example
686           shows a merge with two parents):
687
688
689               index <hash>,<hash>..<hash>
690               mode <mode>,<mode>..<mode>
691               new file mode <mode>
692               deleted file mode <mode>,<mode>
693           The mode <mode>,<mode>..<mode> line appears only if at least one of
694           the <mode> is different from the rest. Extended headers with
695           information about detected contents movement (renames and copying
696           detection) are designed to work with diff of two <tree-ish> and are
697           not used by combined diff format.
698
699        3.  It is followed by two-line from-file/to-file header
700
701
702               --- a/file
703               +++ b/file
704           Similar to two-line header for traditional unified diff format,
705           /dev/null is used to signal created or deleted files.
706
707        4.  Chunk header format is modified to prevent people from
708           accidentally feeding it to patch -p1. Combined diff format was
709           created for review of merge commit changes, and was not meant for
710           apply. The change is similar to the change in the extended index
711           header:
712
713
714               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
715           There are (number of parents + 1) @ characters in the chunk header
716           for combined diff format.
717       Unlike the traditional unified diff format, which shows two files A and
718       B with a single column that has - (minus — appears in A but removed in
719       B), + (plus — missing in A but added to B), or " " (space — unchanged)
720       prefix, this format compares two or more files file1, file2,... with
721       one file X, and shows how X differs from each of fileN. One column for
722       each of fileN is prepended to the output line to note how X´s line is
723       different from it.
724
725       A - character in the column N means that the line appears in fileN but
726       it does not appear in the result. A + character in the column N means
727       that the line appears in the last file, and fileN does not have that
728       line (in other words, the line was added, from the point of view of
729       that parent).
730
731       In the above example output, the function signature was changed from
732       both files (hence two - removals from both file1 and file2, plus + to
733       mean one line that was added does not appear in either file1 nor
734       file2). Also two other lines are the same from file1 but do not appear
735       in file2 (hence prefixed with ).
736
737       When shown by git diff-tree -c, it compares the parents of a merge
738       commit with the merge result (i.e. file1..fileN are the parents). When
739       shown by git diff-files -c, it compares the two unresolved merge
740       parents with the working tree file (i.e. file1 is stage 2 aka "our
741       version", file2 is stage 3 aka "their version").
742

AUTHOR

744       Written by Linus Torvalds <torvalds@osdl.org>
745

DOCUMENTATION

747       Documentation by David Greaves, Junio C Hamano and the git-list
748       <git@vger.kernel.org>.
749

GIT

751       Part of the git(7) suite
752

NOTES

754        1. diffcore documentation
755           diffcore.html
756
757
758
759Git 1.5.3.3                       10/09/2007                  GIT-DIFF-TREE(1)
Impressum