]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/diff-format.txt
t4034: abstract away SHA-1-specific constants
[thirdparty/git.git] / Documentation / diff-format.txt
CommitLineData
f552e51e
DK
1Raw output format
2-----------------
3
4The raw output format from "git-diff-index", "git-diff-tree",
9e6c7230 5"git-diff-files" and "git diff --raw" are very similar.
03ea2802 6
a6080a0a 7These commands all compare two sets of things; what is
f73ae1fc 8compared differs:
03ea2802 9
215a7ad1 10git-diff-index <tree-ish>::
03ea2802
DG
11 compares the <tree-ish> and the files on the filesystem.
12
215a7ad1 13git-diff-index --cached <tree-ish>::
5f3aa197 14 compares the <tree-ish> and the index.
03ea2802
DG
15
16git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]::
17 compares the trees named by the two arguments.
18
19git-diff-files [<pattern>...]::
5f3aa197 20 compares the index and the files on the filesystem.
03ea2802 21
6a5d0b0a 22The "git-diff-tree" command begins its output by printing the hash of
f552e51e
DK
23what is being compared. After that, all the commands print one output
24line per changed file.
03ea2802 25
81e50eab 26An output line is formatted this way:
03ea2802 27
8db9307c 28------------------------------------------------
f9ea6e45
GH
29in-place edit :100644 100644 bcd1234 0123456 M file0
30copy-edit :100644 100644 abcd123 1234567 C68 file1 file2
31rename-edit :100644 100644 abcd123 1234567 R86 file1 file3
32create :000000 100644 0000000 1234567 A file4
33delete :100644 000000 1234567 0000000 D file5
34unmerged :000000 000000 0000000 0000000 U file6
8db9307c 35------------------------------------------------
b6d8f309
JH
36
37That is, from the left to the right:
38
8db9307c
JH
39. a colon.
40. mode for "src"; 000000 if creation or unmerged.
41. a space.
42. mode for "dst"; 000000 if deletion or unmerged.
43. a space.
44. sha1 for "src"; 0\{40\} if creation or unmerged.
45. a space.
46. sha1 for "dst"; 0\{40\} if creation, unmerged or "look at work tree".
47. a space.
48. status, followed by optional "score" number.
23f8239b 49. a tab or a NUL when `-z` option is used.
8db9307c 50. path for "src"
23f8239b 51. a tab or a NUL when `-z` option is used; only exists for C or R.
8db9307c 52. path for "dst"; only exists for C or R.
23f8239b 53. an LF or a NUL when `-z` option is used, to terminate the record.
03ea2802 54
a5a323f3
YD
55Possible status letters are:
56
57- A: addition of a file
58- C: copy of a file into a new one
59- D: deletion of a file
60- M: modification of the contents or mode of a file
61- R: renaming of a file
62- T: change in the type of the file
63- U: file is unmerged (you must complete the merge before it can
64be committed)
65- X: "unknown" change type (most probably a bug, please report it)
66
04c8ce9c 67Status letters C and R are always followed by a score (denoting the
a5a323f3 68percentage of similarity between the source and target of the move or
ac1c2d9a
JH
69copy). Status letter M may be followed by a score (denoting the
70percentage of dissimilarity) for file rewrites.
a5a323f3 71
f73ae1fc 72<sha1> is shown as all 0's if a file is new on the filesystem
5f3aa197 73and it is out of sync with the index.
03ea2802 74
8db9307c
JH
75Example:
76
77------------------------------------------------
f9ea6e45 78:100644 100644 5be4a4a 0000000 M file.c
8db9307c 79------------------------------------------------
03ea2802 80
860cd699
AH
81Without the `-z` option, pathnames with "unusual" characters are
82quoted as explained for the configuration variable `core.quotePath`
83(see linkgit:git-config[1]). Using `-z` the filename is output
84verbatim and the line is terminated by a NUL byte.
d88156e9 85
3b559eab
JN
86diff format for merges
87----------------------
88
9e6c7230 89"git-diff-tree", "git-diff-files" and "git-diff --raw"
bcf9626a 90can take `-c` or `--cc` option
3b559eab
JN
91to generate diff output also for merge commits. The output differs
92from the format described above in the following way:
93
94. there is a colon for each parent
95. there are more "src" modes and "src" sha1
96. status is concatenated status characters for each parent
97. no optional "score" number
d76ce4f7 98. tab-separated pathname(s) of the file
3b559eab 99
d76ce4f7
EN
100For `-c` and `--cc`, only the destination or final path is shown even
101if the file was renamed on any side of history. With
102`--combined-all-paths`, the name of the path in each parent is shown
103followed by the name of the path in the merge commit.
104
105Examples for `-c` and `--cc` without `--combined-all-paths`:
106------------------------------------------------
107::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c
108::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM bar.sh
109::100644 100644 100644 e07d6c5 9042e82 ee91881 RR phooey.c
110------------------------------------------------
111
112Examples when `--combined-all-paths` added to either `-c` or `--cc`:
3b559eab
JN
113
114------------------------------------------------
d76ce4f7
EN
115::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c desc.c desc.c
116::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM foo.sh bar.sh bar.sh
117::100644 100644 100644 e07d6c5 9042e82 ee91881 RR fooey.c fuey.c phooey.c
3b559eab
JN
118------------------------------------------------
119
120Note that 'combined diff' lists only files which were modified from
121all parents.
122
d88156e9 123
272bd3cf 124include::diff-generate-patch.txt[]
f604652e
JH
125
126
127other diff formats
128------------------
129
130The `--summary` option describes newly added, deleted, renamed and
131copied files. The `--stat` option adds diffstat(1) graph to the
132output. These options can be combined with other options, such as
133`-p`, and are meant for human consumption.
134
135When showing a change that involves a rename or a copy, `--stat` output
136formats the pathnames compactly by combining common prefix and suffix of
137the pathnames. For example, a change that moves `arch/i386/Makefile` to
138`arch/x86/Makefile` while modifying 4 lines will be shown like this:
139
140------------------------------------
141arch/{i386 => x86}/Makefile | 4 +--
142------------------------------------
143
144The `--numstat` option gives the diffstat(1) information but is designed
145for easier machine consumption. An entry in `--numstat` output looks
146like this:
147
148----------------------------------------
1491 2 README
1503 1 arch/{i386 => x86}/Makefile
151----------------------------------------
152
153That is, from left to right:
154
155. the number of added lines;
156. a tab;
157. the number of deleted lines;
158. a tab;
159. pathname (possibly with rename/copy information);
160. a newline.
161
162When `-z` output option is in effect, the output is formatted this way:
163
164----------------------------------------
1651 2 README NUL
1663 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
167----------------------------------------
168
169That is:
170
171. the number of added lines;
172. a tab;
173. the number of deleted lines;
174. a tab;
175. a NUL (only exists if renamed/copied);
176. pathname in preimage;
177. a NUL (only exists if renamed/copied);
178. pathname in postimage (only exists if renamed/copied);
179. a NUL.
180
181The extra `NUL` before the preimage path in renamed case is to allow
182scripts that read the output to tell if the current record being read is
183a single-path record or a rename/copy record without reading ahead.
184After reading added and deleted lines, reading up to `NUL` would yield
185the pathname, but if that is `NUL`, the record will show two paths.