git-diff-tree
git-diff-tree(1) ================
NAME ---- git-diff-tree - Compares the content and mode of blobs found via two tree objects
SYNOPSIS --------
’git diff-tree’ [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty]
[-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base]
[<common-diff-options>] <tree-ish> [<tree-ish>] [<path>…]
DESCRIPTION ----------- Compare the content and mode of blobs found via two tree objects.
If there is only one <tree-ish> given, the commit is compared with its parents (see --stdin below).
Note that ’git diff-tree’ can use the tree encapsulated in a commit object.
OPTIONS ------- include::diff-options.adoc[]
<tree-ish>
The id of a tree object.
<path>…
If provided, the results are limited to a subset of files matching one of the provided pathspecs.
-r
Recurse into sub-trees.
-t
Show tree entry itself as well as subtrees. Implies -r.
--root
When --root is specified the initial commit will be shown as a big creation event. This is equivalent to a diff against the NULL tree.
--merge-base
Instead of comparing the <tree-ish>s directly, use the merge base between the two <tree-ish>s as the "before" side. There must be two <tree-ish>s given and they must both be commits.
--stdin
When --stdin is specified, the command does not take <tree-ish> arguments from the command line. Instead, it reads lines containing either two <tree>, one <commit>, or a list of <commit> from its standard input. (Use a single space as separator.)
When two trees are given, it compares the first tree with the second. When a single commit is given, it compares the commit with its parents. The remaining commits, when given, are used as if they are parents of the first commit.
When comparing two trees, the ID of both trees (separated by a space and terminated by a newline) is printed before the difference. When comparing commits, the ID of the first (or only) commit, followed by a newline, is printed.
The following flags further affect the behavior when comparing commits (but not trees).
-m
By default, ’git diff-tree --stdin’ does not show differences for merge commits. With this flag, it shows differences to that commit from all of its parents. See also -c.
-s
By default, ’git diff-tree --stdin’ shows differences, either in machine-readable form (without -p) or in patch form (with -p). This output can be suppressed. It is only useful with the -v flag.
-v
This flag causes ’git diff-tree --stdin’ to also show the commit message before the differences.
--pretty[=<format>]
--format=<format>
Pretty-print the contents of the commit logs in a given format, where ’<format>’ can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>. When <format> is none of the above, and has %<placeholder> in it, it acts as if --pretty=tformat:<format> were given.
See the "PRETTY FORMATS" section for some additional details for each format. When =<format> part is omitted, it defaults to medium.
NOTE: you can specify the default pretty format in the repository configuration (see linkgit:git-config[1]).
--abbrev-commit
Instead of showing the full 40-byte hexadecimal commit object name, show a prefix that names the object uniquely. --abbrev=<n> (which also modifies diff output, if it is displayed) option can be used to specify the minimum length of the prefix.
This should make --pretty=oneline a whole lot more readable for people using 80-column terminals.
--no-abbrev-commit
Show the full 40-byte hexadecimal commit object name. This negates --abbrev-commit, either explicit or implied by other options such as --oneline. It also overrides the log.abbrevCommit variable.
--oneline
This is a shorthand for --pretty=oneline --abbrev-commit used together.
--encoding=<encoding>
Commit objects record the character encoding used for the log message in their encoding header; this option can be used to tell the command to re-code the commit log message in the encoding preferred by the user. For non plumbing commands this defaults to UTF-8. Note that if an object claims to be encoded in X and we are outputting in X, we will output the object verbatim; this means that invalid sequences in the original commit may be copied to the output. Likewise, if iconv(3) fails to convert the commit, we will quietly output the original object verbatim.
--expand-tabs=<n>
--expand-tabs
--no-expand-tabs
Perform a tab expansion (replace each tab with enough spaces to fill to the next display column that is a multiple of <n>) in the log message before showing it in the output. --expand-tabs is a short-hand for --expand-tabs=8, and --no-expand-tabs is a short-hand for --expand-tabs=0, which disables tab expansion.
By default, tabs are expanded in pretty formats that indent the log message by 4 spaces (i.e. medium, which is the default, full, and fuller).
ifndef::git-rev-list[] --notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. ifndef::with-breaking-changes[] This is the default for git log, git show and git whatchanged commands when there is no --pretty, --format, or --oneline option given on the command line. endif::with-breaking-changes[] ifdef::with-breaking-changes[] This is the default for git log and git show commands when there is no --pretty, --format, or --oneline option given on the command line. endif::with-breaking-changes[]
By default, the notes shown are from the notes refs listed in the core.notesRef and notes.displayRef variables (or corresponding environment overrides). See linkgit:git-config[1] for more details.
With an optional ’<ref>’ argument, use the ref to find the notes to display. The ref can specify the full refname when it begins with refs/notes/; when it begins with notes/, refs/ and otherwise refs/notes/ is prefixed to form the full name of the ref.
Multiple --notes options can be combined to control which notes are being displayed. Examples: “--notes=foo” will show only notes from refs/notes/foo; “--notes=foo --notes” will show both notes from "refs/notes/foo" and from the default notes ref(s).
--no-notes
Do not show notes. This negates the above --notes option, by resetting the list of notes refs from which notes are shown. Options are parsed in the order given on the command line, so e.g. “--notes --notes=foo --no-notes --notes=bar” will only show notes from refs/notes/bar.
--show-notes-by-default
Show the default notes unless options for displaying specific notes are given.
--show-notes[=<ref>]
--standard-notes
--no-standard-notes
These options are deprecated. Use the above --notes/--no-notes options instead. endif::git-rev-list[]
--show-signature
Check the validity of a signed commit object by passing the signature to gpg --verify and show the output.
--no-commit-id
’git diff-tree’ outputs a line with the commit ID when applicable. This flag suppresses the commit ID output.
-c
This flag changes the way a merge commit is displayed (which means it is useful only when the command is given one <tree-ish>, or --stdin). It shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time (which is what the -m option does). Furthermore, it lists only files which were modified from all parents.
--cc
This flag changes the way a merge commit patch is displayed, in a similar way to the -c option. It implies the -c and -p options and further compresses the patch output by omitting uninteresting hunks whose contents in the parents have only two variants and the merge result picks one of them without modification. When all hunks are uninteresting, the commit itself and the commit log message are not shown, just like in any other "empty diff" case.
--combined-all-paths
This flag causes combined diffs (used for merge commits) to list the name of the file from all parents. It thus only has effect when -c or --cc are specified, and is likely only useful if filename changes are detected (i.e. when either rename or copy detection have been requested).
--always
Show the commit itself and the commit log message even if the diff itself is empty.
PRETTY FORMATS --------------
If the commit is a merge, and if the pretty-format is not oneline, email or raw, an additional line is inserted before the Author: line. This line begins with "Merge: " and the hashes of ancestral commits are printed, separated by spaces. Note that the listed commits may not necessarily be the list of the ’direct’ parent commits if you have limited your view of history: for example, if you are only interested in changes related to a certain directory or file.
There are several built-in formats, and you can define additional formats by setting a pretty.<name> config option to either another format name, or a format: string, as described below (see linkgit:git-config[1]). Here are the details of the built-in formats:
oneline
<hash> <title-line>
This is designed to be as compact as possible.
short
commit <hash> Author: <author>
<title-line>
medium
commit <hash> Author: <author> Date: <author-date>
<title-line>
<full-commit-message>
full
commit <hash> Author: <author> Commit: <committer>
<title-line>
<full-commit-message>
fuller
commit <hash> Author: <author> AuthorDate: <author-date> Commit: <committer> CommitDate: <committer-date>
<title-line>
<full-commit-message>
reference
<abbrev-hash> (<title-line>, <short-author-date>)
This format is used to refer to another commit in a commit message and is the same as --pretty=\'format:%C(auto)%h (%s, %ad)'. By default, the date is formatted with --date=short unless another --date option is explicitly specified. As with any format: with format placeholders, its output is not affected by other options like --decorate and --walk-reflogs.
email
From <hash> <date> From: <author> Date: <author-date> Subject: [PATCH] <title-line>
<full-commit-message>
mboxrd
Like email, but lines in the commit message starting with "From " (preceded by zero or more ">") are quoted with ">" so they aren’t confused as starting a new commit.
raw
The raw format shows the entire commit exactly as stored in the commit object. Notably, the hashes are displayed in full, regardless of whether --abbrev or --no-abbrev are used, and ’parents’ information show the true parent commits, without taking grafts or history simplification into account. Note that this format affects the way commits are displayed, but not the way the diff is shown e.g. with git log --raw. To get full object names in a raw diff format, use --no-abbrev.
format:<format-string>
The format:<format-string> format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of n.
E.g, ’format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"’ would show something like this:
The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
The placeholders are:
-
Placeholders that expand to a single literal character:
%n
newline%%
a raw %%x00
%x followed by two hexadecimal digits is replaced with a byte with the hexadecimal digits’ value (we will call this "literal formatting code" in the rest of this document).- Placeholders that affect formatting of later placeholders: +
%Cred
switch color to red%Cgreen
switch color to green%Cblue
switch color to blue%Creset
reset color%C(<spec>)
color specification, as described under Values in the "CONFIGURATION FILE" section of linkgit:git-config[1]. By default, colors are shown only when enabled for log output (bycolor.diff,color.ui, or--color, and respecting theautosettings of the former if we are going to a terminal). %C(auto,<spec>) is accepted as a historical synonym for the default (e.g., %C(auto,red)). Specifying %C(always,<spec>) will show the colors even when color is not otherwise enabled (though consider just using--color=alwaysto enable color for the whole output, including this format and anything else git might color).autoalone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.%m
left (<), right (>) or boundary (-) mark%w(
[<w>[,<i1>[,<i2>]]])
switch line wrapping, like the-woption of linkgit:git-shortlog[1].%<(
<n>[,(trunc|ltrunc|mtrunc)])
make the next placeholder take at least N column widths, padding spaces on the right if necessary. Optionally truncate (with ellipsis..) at the left (ltrunc)..ft, the middle (mtrunc)mi..le, or the end (trunc)rig.., if the output is longer than <n> columns. Note 1: that truncating only works correctly with <n> >= 2. Note 2: spaces around the <n> and <m> (see below) values are optional. Note 3: Emojis and other wide characters will take two display columns, which may over-run column boundaries. Note 4: decomposed character combining marks may be misplaced at padding boundaries.%<|(<m> )
make the next placeholder take at least until <m> th display column, padding spaces on the right if necessary. Use negative <m> values for column positions measured from the right hand edge of the terminal window.%>(<n>)
%>|(<m>)
similar to %<(<n>), %<|(<m>) respectively, but padding spaces on the left%>>(<n>)
%>>|(<m>)
similar to %>(<n>), %>|(<m>) respectively, except that if the next placeholder takes more spaces than given and there are spaces on its left, use those spaces%><(<n>)
%><|(<m>)
similar to %<(<n>), %<|(<m>) respectively, but padding both sides (i.e. the text is centered)- Placeholders that expand to information extracted from the commit: +
%H
commit hash%h
abbreviated commit hash%T
tree hash%t
abbreviated tree hash%P
parent hashes%p
abbreviated parent hashes%an
author name%aN
author name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%ae
author email%aE
author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%al
author email local-part (the part before the@sign)%aL
author local-part (see %al) respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%ad
author date (format respects --date= option)%aD
author date, RFC2822 style%ar
author date, relative%at
author date, UNIX timestamp%ai
author date, ISO 8601-like format%aI
author date, strict ISO 8601 format%as
author date, short format (YYYY-MM-DD)%ah
author date, human style (like the--date=humanoption of linkgit:git-rev-list[1])%cn
committer name%cN
committer name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%ce
committer email%cE
committer email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%cl
committer email local-part (the part before the@sign)%cL
committer local-part (see %cl) respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%cd
committer date (format respects --date= option)%cD
committer date, RFC2822 style%cr
committer date, relative%ct
committer date, UNIX timestamp%ci
committer date, ISO 8601-like format%cI
committer date, strict ISO 8601 format%cs
committer date, short format (YYYY-MM-DD)%ch
committer date, human style (like the--date=humanoption of linkgit:git-rev-list[1])%d
ref names, like the --decorate option of linkgit:git-log[1]%D
ref names without the " (", ")" wrapping.%(count)
the number of a patch within a patch series. Used only in--commit-list-formatinformat-patch%(total)
the total number of patches in a patch series. Used only in--commit-list-formatinformat-patch%(decorate
[:<option>,…])
ref names with custom decorations. Thedecoratestring may be followed by a colon and zero or more comma-separated options. Option values may contain literal formatting codes. These must be used for commas (%x2C) and closing parentheses (%x29), due to their role in the option syntax.prefix=<value>;; Shown before the list of ref names. Defaults to " (".suffix=<value>;; Shown after the list of ref names. Defaults to ")".separator=<value>;; Shown between ref names. Defaults to ", ".pointer=<value>;; Shown between HEAD and the branch it points to, if any. Defaults to " → ".tag=<value>;; Shown before tag names. Defaults to "tag:".
For example, to produce decorations with no wrapping or tag annotations, and spaces as separators: --------------------- %(decorate:prefix=,suffix=,tag=,separator= ) ---------------------%(describe
[:<option>,…])
human-readable name, like linkgit:git-describe[1]; empty string for undescribable commits. Thedescribestring may be followed by a colon and zero or more comma-separated options. Descriptions can be inconsistent when tags are added or removed at the same time.tags[=<bool-value>];; Instead of only considering annotated tags, consider lightweight tags as well.abbrev=<number>;; Instead of using the default number of hexadecimal digits (which will vary according to the number of objects in the repository with a default of 7) of the abbreviated object name, use <number> digits, or as many digits as needed to form a unique object name.match=<pattern>;; Only consider tags matching the givenglob(7)<pattern>, excluding therefs/tags/prefix.exclude=<pattern>;; Do not consider tags matching the givenglob(7)<pattern>, excluding therefs/tags/prefix.%S
ref name given on the command line by which the commit was reached (likegitlog--source), only works withgitlog%e
encoding%s
subject%f
sanitized subject line, suitable for a filename%b
body%B
raw body (unwrapped subject and body) ifndef::git-rev-list[]%N
commit notes endif::git-rev-list[]%GG
raw verification message from GPG for a signed commit%G?
show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature%GS
show the name of the signer for a signed commit%GK
show the key used to sign a signed commit%GF
show the fingerprint of the key used to sign a signed commit%GP
show the fingerprint of the primary key whose subkey was used to sign a signed commit%GT
show the trust level for the key used to sign a signed commit%gD
reflog selector, e.g.,refs/stash@{1}orrefs/stash@{2minutesago}; the format follows the rules described for the-goption. The portion before the@is the refname as given on the command line (sogitlog-grefs/heads/masterwould yieldrefs/heads/master@{0}).%gd
shortened reflog selector; same as%gD, but the refname portion is shortened for human readability (sorefs/heads/masterbecomes justmaster).%gn
reflog identity name%gN
reflog identity name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%ge
reflog identity email%gE
reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])%gs
reflog subject%(trailers
[:<option>,…])
display the trailers of the body as interpreted by linkgit:git-interpret-trailers[1]. Thetrailersstring may be followed by a colon and zero or more comma-separated options. If any option is provided multiple times, the last occurrence wins.key=<key>;; only show trailers with specified <key>. Matching is done case-insensitively and trailing colon is optional. If option is given multiple times trailer lines matching any of the keys are shown. This option automatically enables theonlyoption so that non-trailer lines in the trailer block are hidden. If that is not desired it can be disabled withonly=false. E.g., %(trailers:key=Reviewed-by) shows trailer lines with keyReviewed-by.only[=<bool>];; select whether non-trailer lines from the trailer block should be included.separator=<sep>;; specify the separator inserted between trailer lines. Defaults to a line feed character. The string <sep> may contain the literal formatting codes described above. To use comma as separator one must use%x2Cas it would otherwise be parsed as next option. E.g., %(trailers:key=Ticket,separator=%x2C ) shows all trailer lines whose key isTicketseparated by a comma and a space.unfold[=<bool>];; make it behave as if interpret-trailer’s--unfoldoption was given. E.g., %(trailers:only,unfold=true) unfolds and shows all trailer lines.keyonly[=<bool>];; only show the key part of the trailer.valueonly[=<bool>];; only show the value part of the trailer.key_value_separator=<sep>;; specify the separator inserted between the key and value of each trailer. Defaults to ": ". Otherwise it shares the same semantics asseparator=<sep>above.[!NOTE] Some placeholders may depend on other options given to the revision traversal engine. For example, the %g* reflog options will insert an empty string unless we are traversing reflog entries (e.g., by
gitlog-g). The %d and %D placeholders will use the "short" decoration format if--decoratewas not already provided on the command line.The boolean options accept an optional value
[=<bool-value>]. The values taken by--type=boollinkgit:git-config[1], likeyesandoff, are all accepted. Giving a boolean option without=<value>is equivalent to giving it with=true.If you add a
+(plus sign) after % of a placeholder, a line-feed is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string.If you add a
-(minus sign) after % of a placeholder, all consecutive line-feeds immediately preceding the expansion are deleted if and only if the placeholder expands to an empty string.If you add a
’’(space) after % of a placeholder, a space is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string.
tformat:
The tformat: format works exactly like format:, except that it provides "terminator" semantics instead of "separator" semantics. In other words, each commit has the message terminator character (usually a newline) appended, rather than a separator placed between entries. This means that the final entry of a single-line format will be properly terminated with a new line, just as the "oneline" format does. For example:
$ git log -2 --pretty=format:%h 4da45bef \
| perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973 -- NO NEWLINE
$ git log -2 --pretty=tformat:%h 4da45bef \
| perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973
In addition, any unrecognized string that has a % in it is interpreted as if it has tformat: in front of it. For example, these two are equivalent:
$ git log -2 --pretty=tformat:%h 4da45bef
$ git log -2 --pretty=%h 4da45bef
Raw output format -----------------
The raw output format from git-diff-index, git-diff-tree, git-diff-files and git diff --raw are very similar.
These commands all compare two sets of things; what is compared differs:
git-diff-index <tree-ish>
compares the <tree-ish> and the files on the filesystem.
git-diff-index --cached <tree-ish>
compares the <tree-ish> and the index.
git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
compares the trees named by the two arguments.
git-diff-files [<pattern>…]
compares the index and the files on the filesystem.
All the commands print one output line per changed file, except git diff-files in the case of an unmerged file, which prints both an "unmerged" and an "in-place edit" line.
An output line is formatted this way:
in-place edit :100644 100644 bcd1234 0123456 M file0
copy-edit :100644 100644 abcd123 1234567 C68 file1 file2
rename-edit :100644 100644 abcd123 1234567 R86 file1 file3
create :000000 100644 0000000 1234567 A file4
delete :100644 000000 1234567 0000000 D file5
unmerged :000000 000000 0000000 0000000 U file6
That is, from the left to the right:
-
a colon.
-
mode for "src"; 000000 if creation, or if "src" is from the index and is unmerged.
-
a space.
-
mode for "dst"; 000000 if deletion, or if "dst" is from the index and is unmerged.
-
a space.
-
sha1 for "src"; 0{40} if creation, or if "src" is from the index and is unmerged.
-
a space.
-
sha1 for "dst"; 0{40} if deletion, if "dst" is from the index and is unmerged, or if "dst" is from the work tree and is out of sync with the index.
-
a space.
-
status, followed by optional "score" number.
-
a tab or a NUL when
-zoption is used. -
path for "src"
-
a tab or a NUL when
-zoption is used; only exists for C or R. -
path for "dst"; only exists for C or R.
-
an LF or a NUL when
-zoption is used, to terminate the record.
Possible status letters are:
-
A: addition of a file -
C: copy of a file into a new one -
D: deletion of a file -
M: modification of the contents or mode of a file -
R: renaming of a file -
T: change in the type of the file (regular file, symbolic link or submodule) -
U: file is unmerged (you must complete the merge before it can be committed) -
X: "unknown" change type (most probably a bug, please report it)
Status letters C and R are always followed by a score (denoting the percentage of similarity between the source and target of the move or copy). Status letter M may be followed by a score (denoting the percentage of dissimilarity) for file rewrites.
The sha1 for "dst" is shown as all 0’s if a file on the filesystem is out of sync with the index.
Example:
:100644 100644 5be4a4a 0000000 M file.c
Without the -z option, pathnames with "unusual" characters are quoted as explained for the configuration variable core.quotePath (see linkgit:git-config[1]). Using -z the filename is output verbatim and the line is terminated by a NUL byte.
diff format for merges ----------------------
git-diff-tree, git-diff-files and git-diff --raw can take -c or --cc option to generate diff output also for merge commits. The output differs from the format described above in the following way:
-
there is a colon for each parent
-
there are more "src" modes and "src" sha1
-
status is concatenated status characters for each parent
-
no optional "score" number
-
tab-separated pathname(s) of the file
For -c and --cc, only the destination or final path is shown even if the file was renamed on any side of history. With --combined-all-paths, the name of the path in each parent is shown followed by the name of the path in the merge commit.
Examples for -c and --cc without --combined-all-paths:
::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c
::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM bar.sh
::100644 100644 100644 e07d6c5 9042e82 ee91881 RR phooey.c
Examples when --combined-all-paths added to either -c or --cc:
::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c desc.c desc.c
::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM foo.sh bar.sh bar.sh
::100644 100644 100644 e07d6c5 9042e82 ee91881 RR fooey.c fuey.c phooey.c
Note that ’combined diff’ lists only files which were modified from all parents.
Generating patch text with -p -----------------------------
Running linkgit:git-diff[1], linkgit:git-log[1], linkgit:git-show[1], linkgit:git-diff-index[1], linkgit:git-diff-tree[1], or linkgit:git-diff-files[1] with the -p option produces patch text. You can customize the creation of patch text via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables (see linkgit:git[1]), and the diff attribute (see linkgit:gitattributes[5]).
What the -p option produces is slightly different from the traditional diff format:
- It is preceded by a "git diff" header that looks like this:
diff --git a/file1 b/file2
The a/ and b/ filenames are the same unless rename/copy is involved. Especially, even for a creation or a deletion, /dev/null is not used in place of the a/ or b/ filenames.
When a rename/copy is involved, file1 and file2 show the name of the source file of the rename/copy and the name of the file that the rename/copy produces, respectively.
-
It is followed by one or more extended header lines:
old mode <mode> new mode <mode> deleted file mode <mode> new file mode <mode> copy from <path> copy to <path> rename from <path> rename to <path> similarity index <number> dissimilarity index <number> index <hash>..<hash> <mode>
File modes <mode> are printed as 6-digit octal numbers including the file type and file permission bits.
Path names in extended headers do not include the
a/andb/prefixes.The similarity index is the percentage of unchanged lines, and the dissimilarity index is the percentage of changed lines. It is a rounded down integer, followed by a percent sign. The similarity index value of 100% is thus reserved for two equal files, while 100% dissimilarity means that no line from the old file made it into the new one.
The index line includes the blob object names before and after the change. The <mode> is included if the file mode does not change; otherwise, separate lines indicate the old and the new mode.
- Pathnames with "unusual" characters are quoted as explained for the configuration variable
core.quotePath(see linkgit:git-config[1]).
- All the
file1files in the output refer to files before the commit, and all thefile2files refer to files after the commit. It is incorrect to apply each change to each file sequentially. For example, this patch will swap a and b:
diff --git a/a b/b
rename from a
rename to b
diff --git a/b b/a
rename from b
rename to a
- Hunk headers mention the name of the function to which the hunk applies. See "Defining a custom hunk-header" in linkgit:gitattributes[5] for details of how to tailor this to specific languages.
Combined diff format --------------------
Any diff-generating command can take the -c or --cc option to produce a ’combined diff’ when showing a merge. This is the default format when showing merges with linkgit:git-diff[1] or linkgit:git-show[1]. Note also that you can give suitable --diff-merges option to any of these commands to force generation of diffs in a specific format.
A "combined diff" format looks like this:
diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
}
- static void describe(char *arg)
-static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
{
+ unsigned char sha1[20];
+ struct commit *cmit;
struct commit_list *list;
static int initialized = 0;
struct commit_name *n;
+ if (get_sha1(arg, sha1) < 0)
+ usage(describe_usage);
+ cmit = lookup_commit_reference(sha1);
+ if (!cmit)
+ usage(describe_usage);
+
if (!initialized) {
initialized = 1;
for_each_ref(get_name);
- It is preceded by a "git diff" header, that looks like this (when the
-coption is used):
diff --combined file
or like this (when the --cc option is used):
diff --cc file
-
It is followed by one or more extended header lines (this example shows a merge with two parents):
index <hash>,<hash>..<hash> mode <mode>,<mode>..<mode> new file mode <mode> deleted file mode <mode>,<mode>
The
mode<mode>,<mode>..<mode>line appears only if at least one of the <mode> is different from the rest. Extended headers with information about detected content movement (renames and copying detection) are designed to work with the diff of two <tree-ish> and are not used by combined diff format.
- It is followed by a two-line from-file/to-file header:
-
a/file +++ b/file
Similar to the two-line header for the traditional ’unified’ diff format,
/dev/nullis used to signal created or deleted files.However, if the --combined-all-paths option is provided, instead of a two-line from-file/to-file, you get an N+1 line from-file/to-file header, where N is the number of parents in the merge commit:
-
a/file
-
a/file
-
a/file +++ b/file
This extended format can be useful if rename or copy detection is active, to allow you to see the original name of the file in different parents.
- Chunk header format is modified to prevent people from accidentally feeding it to
patch-p1. Combined diff format was created for review of merge commit changes, and was not meant to be applied. The change is similar to the change in the extended ’index’ header:
@@@ <from-file-range> <from-file-range> <to-file-range> @@@
There are (number of parents + 1) @ characters in the chunk header for combined diff format.
Unlike the traditional ’unified’ diff format, which shows two files A and B with a single column that has - (minus -- appears in A but removed in B), + (plus — missing in A but added to B), or " " (space — unchanged) prefix, this format compares two or more files file1, file2,… with one file X, and shows how X differs from each of fileN. One column for each of fileN is prepended to the output line to note how X’s line is different from it.
A - character in the column N means that the line appears in fileN but it does not appear in the result. A + character in the column N means that the line appears in the result, and fileN does not have that line (in other words, the line was added, from the point of view of that parent).
In the above example output, the function signature was changed from both files (hence two - removals from both file1 and file2, plus ++ to mean one line that was added does not appear in either file1 or file2). Also, eight other lines are the same from file1 but do not appear in file2 (hence prefixed with +).
When shown by git diff-tree -c, it compares the parents of a merge commit with the merge result (i.e. file1..fileN are the parents). When shown by git diff-files -c, it compares the two unresolved merge parents with the working tree file (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka "their version").
other diff formats ------------------
The --summary option describes newly added, deleted, renamed and copied files. The --stat option adds diffstat(1) graph to the output. These options can be combined with other options, such as -p, and are meant for human consumption.
When showing a change that involves a rename or a copy, --stat output formats the pathnames compactly by combining common prefix and suffix of the pathnames. For example, a change that moves arch/i386/Makefile to arch/x86/Makefile while modifying 4 lines will be shown like this:
arch/{i386 => x86}/Makefile | 4 +--
The --numstat option gives the diffstat(1) information but is designed for easier machine consumption. An entry in --numstat output looks like this:
1 2 README
3 1 arch/{i386 => x86}/Makefile
That is, from left to right:
-
the number of added lines;
-
a tab;
-
the number of deleted lines;
-
a tab;
-
pathname (possibly with rename/copy information);
-
a newline.
When -z output option is in effect, the output is formatted this way:
1 2 README NUL
3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
That is:
-
the number of added lines;
-
a tab;
-
the number of deleted lines;
-
a tab;
-
a NUL (only exists if renamed/copied);
-
pathname in preimage;
-
a NUL (only exists if renamed/copied);
-
pathname in postimage (only exists if renamed/copied);
-
a NUL.
The extra NUL before the preimage path in renamed case is to allow scripts that read the output to tell if the current record being read is a single-path record or a rename/copy record without reading ahead. After reading added and deleted lines, reading up to NUL would yield the pathname, but if that is NUL, the record will show two paths.
GIT --- Part of the linkgit:git[1] suite
谢谢你的反馈!