]>
Commit | Line | Data |
---|---|---|
215a7ad1 | 1 | The output format from "git-diff-index", "git-diff-tree" and |
8db9307c | 2 | "git-diff-files" are very similar. |
03ea2802 | 3 | |
f73ae1fc CM |
4 | These commands all compare two sets of things; what is |
5 | compared differs: | |
03ea2802 | 6 | |
215a7ad1 | 7 | git-diff-index <tree-ish>:: |
03ea2802 DG |
8 | compares the <tree-ish> and the files on the filesystem. |
9 | ||
215a7ad1 | 10 | git-diff-index --cached <tree-ish>:: |
5f3aa197 | 11 | compares the <tree-ish> and the index. |
03ea2802 DG |
12 | |
13 | git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]:: | |
14 | compares the trees named by the two arguments. | |
15 | ||
16 | git-diff-files [<pattern>...]:: | |
5f3aa197 | 17 | compares the index and the files on the filesystem. |
03ea2802 | 18 | |
03ea2802 | 19 | |
81e50eab | 20 | An output line is formatted this way: |
03ea2802 | 21 | |
8db9307c | 22 | ------------------------------------------------ |
b6d8f309 JH |
23 | in-place edit :100644 100644 bcd1234... 0123456... M file0 |
24 | copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2 | |
25 | rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3 | |
8db9307c | 26 | create :000000 100644 0000000... 1234567... A file4 |
b6d8f309 JH |
27 | delete :100644 000000 1234567... 0000000... D file5 |
28 | unmerged :000000 000000 0000000... 0000000... U file6 | |
8db9307c | 29 | ------------------------------------------------ |
b6d8f309 JH |
30 | |
31 | That is, from the left to the right: | |
32 | ||
8db9307c JH |
33 | . a colon. |
34 | . mode for "src"; 000000 if creation or unmerged. | |
35 | . a space. | |
36 | . mode for "dst"; 000000 if deletion or unmerged. | |
37 | . a space. | |
38 | . sha1 for "src"; 0\{40\} if creation or unmerged. | |
39 | . a space. | |
40 | . sha1 for "dst"; 0\{40\} if creation, unmerged or "look at work tree". | |
41 | . a space. | |
42 | . status, followed by optional "score" number. | |
43 | . a tab or a NUL when '-z' option is used. | |
44 | . path for "src" | |
45 | . a tab or a NUL when '-z' option is used; only exists for C or R. | |
46 | . path for "dst"; only exists for C or R. | |
47 | . an LF or a NUL when '-z' option is used, to terminate the record. | |
03ea2802 | 48 | |
f73ae1fc | 49 | <sha1> is shown as all 0's if a file is new on the filesystem |
5f3aa197 | 50 | and it is out of sync with the index. |
03ea2802 | 51 | |
8db9307c JH |
52 | Example: |
53 | ||
54 | ------------------------------------------------ | |
55 | :100644 100644 5be4a4...... 000000...... M file.c | |
56 | ------------------------------------------------ | |
03ea2802 | 57 | |
d88156e9 JH |
58 | When `-z` option is not used, TAB, LF, and backslash characters |
59 | in pathnames are represented as `\t`, `\n`, and `\\`, | |
60 | respectively. | |
61 | ||
62 | ||
03ea2802 DG |
63 | Generating patches with -p |
64 | -------------------------- | |
65 | ||
215a7ad1 | 66 | When "git-diff-index", "git-diff-tree", or "git-diff-files" are run |
1a93a766 | 67 | with a '-p' option, they do not produce the output described above; |
03ea2802 DG |
68 | instead they produce a patch file. |
69 | ||
5cfcd07c | 70 | The patch generation can be customized at two levels. |
03ea2802 DG |
71 | |
72 | 1. When the environment variable 'GIT_EXTERNAL_DIFF' is not set, | |
73 | these commands internally invoke "diff" like this: | |
74 | ||
2c6e4771 | 75 | diff -L a/<path> -L b/<path> -pu <old> <new> |
2cf565c5 DG |
76 | + |
77 | For added files, `/dev/null` is used for <old>. For removed | |
78 | files, `/dev/null` is used for <new> | |
79 | + | |
80 | The "diff" formatting options can be customized via the | |
81 | environment variable 'GIT_DIFF_OPTS'. For example, if you | |
82 | prefer context diff: | |
03ea2802 | 83 | |
27dedf0c | 84 | GIT_DIFF_OPTS=-c git-diff-index -p HEAD |
03ea2802 DG |
85 | |
86 | ||
87 | 2. When the environment variable 'GIT_EXTERNAL_DIFF' is set, the | |
88 | program named by it is called, instead of the diff invocation | |
89 | described above. | |
90 | + | |
91 | For a path that is added, removed, or modified, | |
92 | 'GIT_EXTERNAL_DIFF' is called with 7 parameters: | |
93 | ||
94 | path old-file old-hex old-mode new-file new-hex new-mode | |
95 | + | |
96 | where: | |
97 | ||
98 | <old|new>-file:: are files GIT_EXTERNAL_DIFF can use to read the | |
f73ae1fc | 99 | contents of <old|new>, |
03ea2802 DG |
100 | <old|new>-hex:: are the 40-hexdigit SHA1 hashes, |
101 | <old|new>-mode:: are the octal representation of the file modes. | |
102 | ||
103 | + | |
104 | The file parameters can point at the user's working file | |
105 | (e.g. `new-file` in "git-diff-files"), `/dev/null` (e.g. `old-file` | |
106 | when a new file is added), or a temporary file (e.g. `old-file` in the | |
5f3aa197 | 107 | index). 'GIT_EXTERNAL_DIFF' should not worry about unlinking the |
03ea2802 DG |
108 | temporary file --- it is removed when 'GIT_EXTERNAL_DIFF' exits. |
109 | ||
110 | For a path that is unmerged, 'GIT_EXTERNAL_DIFF' is called with 1 | |
111 | parameter, <path>. | |
1a93a766 JH |
112 | |
113 | ||
72e9340c | 114 | git specific extension to diff format |
1a93a766 JH |
115 | ------------------------------------- |
116 | ||
117 | What -p option produces is slightly different from the | |
118 | traditional diff format. | |
119 | ||
89438677 | 120 | 1. It is preceded with a "git diff" header, that looks like |
1a93a766 JH |
121 | this: |
122 | ||
123 | diff --git a/file1 b/file2 | |
8db9307c JH |
124 | + |
125 | The `a/` and `b/` filenames are the same unless rename/copy is | |
126 | involved. Especially, even for a creation or a deletion, | |
127 | `/dev/null` is _not_ used in place of `a/` or `b/` filenames. | |
128 | + | |
f73ae1fc | 129 | When rename/copy is involved, `file1` and `file2` show the |
8db9307c JH |
130 | name of the source file of the rename/copy and the name of |
131 | the file that rename/copy produces, respectively. | |
1a93a766 | 132 | |
f73ae1fc | 133 | 2. It is followed by one or more extended header lines: |
1a93a766 JH |
134 | |
135 | old mode <mode> | |
136 | new mode <mode> | |
137 | deleted file mode <mode> | |
138 | new file mode <mode> | |
139 | copy from <path> | |
140 | copy to <path> | |
141 | rename from <path> | |
142 | rename to <path> | |
143 | similarity index <number> | |
144 | dissimilarity index <number> | |
d88156e9 JH |
145 | index <hash>..<hash> <mode> |
146 | ||
147 | 3. TAB, LF, and backslash characters in pathnames are | |
148 | represented as `\t`, `\n`, and `\\`, respectively. | |
34801cab JH |
149 | |
150 | ||
151 | combined diff format | |
152 | -------------------- | |
153 | ||
154 | git-diff-tree and git-diff-files can take '-c' or '--cc' option | |
155 | to produce 'combined diff', which looks like this: | |
156 | ||
157 | ------------ | |
158 | diff --combined describe.c | |
159 | @@@ +98,7 @@@ | |
160 | return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1; | |
161 | } | |
162 | ||
163 | - static void describe(char *arg) | |
164 | -static void describe(struct commit *cmit, int last_one) | |
165 | ++static void describe(char *arg, int last_one) | |
166 | { | |
167 | + unsigned char sha1[20]; | |
168 | + struct commit *cmit; | |
169 | ------------ | |
170 | ||
171 | Unlike the traditional 'unified' diff format, which shows two | |
172 | files A and B with a single column that has `-` (minus -- | |
173 | appears in A but removed in B), `+` (plus -- missing in A but | |
174 | added to B), or ` ` (space -- unchanged) prefix, this format | |
175 | compares two or more files file1, file2,... with one file X, and | |
176 | shows how X differs from each of fileN. One column for each of | |
177 | fileN is prepended to the output line to note how X's line is | |
178 | different from it. | |
179 | ||
180 | A `-` character in the column N means that the line appears in | |
181 | fileN but it does not appear in the last file. A `+` character | |
182 | in the column N means that the line appears in the last file, | |
183 | and fileN does not have that line. | |
184 | ||
185 | In the above example output, the function signature was changed | |
186 | from both files (hence two `-` removals from both file1 and | |
187 | file2, plus `++` to mean one line that was added does not appear | |
188 | in either file1 nor file2). Also two other lines are the same | |
189 | from file1 but do not appear in file2 (hence prefixed with ` +`). | |
190 | ||
191 | When shown by `git diff-tree -c`, it compares the parents of a | |
192 | merge commit with the merge result (i.e. file1..fileN are the | |
193 | parents). When shown by `git diff-files -c`, it compares the | |
194 | two unresolved merge parents with the working tree file | |
195 | (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka | |
196 | "their version"). | |
197 |