Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | The output format from "git-diff-index", "git-diff-tree" and |
| 2 | "git-diff-files" are very similar. |
| 3 | |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 4 | These commands all compare two sets of things; what is |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 5 | compared differs: |
| 6 | |
| 7 | git-diff-index <tree-ish>:: |
| 8 | compares the <tree-ish> and the files on the filesystem. |
| 9 | |
| 10 | git-diff-index --cached <tree-ish>:: |
| 11 | compares the <tree-ish> and the index. |
| 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>...]:: |
| 17 | compares the index and the files on the filesystem. |
| 18 | |
| 19 | |
| 20 | An output line is formatted this way: |
| 21 | |
| 22 | ------------------------------------------------ |
| 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 |
| 26 | create :000000 100644 0000000... 1234567... A file4 |
| 27 | delete :100644 000000 1234567... 0000000... D file5 |
| 28 | unmerged :000000 000000 0000000... 0000000... U file6 |
| 29 | ------------------------------------------------ |
| 30 | |
| 31 | That is, from the left to the right: |
| 32 | |
| 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. |
| 48 | |
| 49 | <sha1> is shown as all 0's if a file is new on the filesystem |
| 50 | and it is out of sync with the index. |
| 51 | |
| 52 | Example: |
| 53 | |
| 54 | ------------------------------------------------ |
| 55 | :100644 100644 5be4a4...... 000000...... M file.c |
| 56 | ------------------------------------------------ |
| 57 | |
| 58 | When `-z` option is not used, TAB, LF, and backslash characters |
| 59 | in pathnames are represented as `\t`, `\n`, and `\\`, |
| 60 | respectively. |
| 61 | |
Junio C Hamano | 67fad6d | 2007-05-06 08:53:12 | [diff] [blame] | 62 | diff format for merges |
| 63 | ---------------------- |
| 64 | |
| 65 | "git-diff-tree" and "git-diff-files" can take '-c' or '--cc' option |
| 66 | to generate diff output also for merge commits. The output differs |
| 67 | from the format described above in the following way: |
| 68 | |
| 69 | . there is a colon for each parent |
| 70 | . there are more "src" modes and "src" sha1 |
| 71 | . status is concatenated status characters for each parent |
| 72 | . no optional "score" number |
| 73 | . single path, only for "dst" |
| 74 | |
| 75 | Example: |
| 76 | |
| 77 | ------------------------------------------------ |
| 78 | ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c |
| 79 | ------------------------------------------------ |
| 80 | |
| 81 | Note that 'combined diff' lists only files which were modified from |
| 82 | all parents. |
| 83 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | |
| 85 | Generating patches with -p |
| 86 | -------------------------- |
| 87 | |
| 88 | When "git-diff-index", "git-diff-tree", or "git-diff-files" are run |
| 89 | with a '-p' option, they do not produce the output described above; |
Junio C Hamano | 1c43712 | 2006-11-28 02:22:25 | [diff] [blame] | 90 | instead they produce a patch file. You can customize the creation |
| 91 | of such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS |
| 92 | environment variables. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 93 | |
Junio C Hamano | 1c43712 | 2006-11-28 02:22:25 | [diff] [blame] | 94 | What the -p option produces is slightly different from the traditional |
| 95 | diff format. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 96 | |
Junio C Hamano | 235a91e | 2006-01-07 01:13:58 | [diff] [blame] | 97 | 1. It is preceded with a "git diff" header, that looks like |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 98 | this: |
| 99 | |
Junio C Hamano | 1c43712 | 2006-11-28 02:22:25 | [diff] [blame] | 100 | diff --git a/file1 b/file2 |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 101 | + |
| 102 | The `a/` and `b/` filenames are the same unless rename/copy is |
| 103 | involved. Especially, even for a creation or a deletion, |
| 104 | `/dev/null` is _not_ used in place of `a/` or `b/` filenames. |
| 105 | + |
| 106 | When rename/copy is involved, `file1` and `file2` show the |
| 107 | name of the source file of the rename/copy and the name of |
| 108 | the file that rename/copy produces, respectively. |
| 109 | |
| 110 | 2. It is followed by one or more extended header lines: |
| 111 | |
| 112 | old mode <mode> |
| 113 | new mode <mode> |
| 114 | deleted file mode <mode> |
| 115 | new file mode <mode> |
| 116 | copy from <path> |
| 117 | copy to <path> |
| 118 | rename from <path> |
| 119 | rename to <path> |
| 120 | similarity index <number> |
| 121 | dissimilarity index <number> |
| 122 | index <hash>..<hash> <mode> |
| 123 | |
Junio C Hamano | a053d54 | 2006-10-27 09:29:13 | [diff] [blame] | 124 | 3. TAB, LF, double quote and backslash characters in pathnames |
| 125 | are represented as `\t`, `\n`, `\"` and `\\`, respectively. |
| 126 | If there is need for such substitution then the whole |
| 127 | pathname is put in double quotes. |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 128 | |
Junio C Hamano | d526ba9 | 2007-07-02 00:17:42 | [diff] [blame] | 129 | The similarity index is the percentage of unchanged lines, and |
| 130 | the dissimilarity index is the percentage of changed lines. It |
| 131 | is a rounded down integer, followed by a percent sign. The |
| 132 | similarity index value of 100% is thus reserved for two equal |
| 133 | files, while 100% dissimilarity means that no line from the old |
| 134 | file made it into the new one. |
| 135 | |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 136 | |
| 137 | combined diff format |
| 138 | -------------------- |
| 139 | |
| 140 | git-diff-tree and git-diff-files can take '-c' or '--cc' option |
| 141 | to produce 'combined diff', which looks like this: |
| 142 | |
| 143 | ------------ |
| 144 | diff --combined describe.c |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 145 | index fabadb8,cc95eb0..4866510 |
| 146 | --- a/describe.c |
| 147 | +++ b/describe.c |
| 148 | @@@ -98,20 -98,12 +98,20 @@@ |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 149 | return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1; |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 150 | } |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 151 | |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 152 | - static void describe(char *arg) |
| 153 | -static void describe(struct commit *cmit, int last_one) |
| 154 | ++static void describe(char *arg, int last_one) |
| 155 | { |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 156 | + unsigned char sha1[20]; |
| 157 | + struct commit *cmit; |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 158 | struct commit_list *list; |
| 159 | static int initialized = 0; |
| 160 | struct commit_name *n; |
| 161 | |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 162 | + if (get_sha1(arg, sha1) < 0) |
| 163 | + usage(describe_usage); |
| 164 | + cmit = lookup_commit_reference(sha1); |
| 165 | + if (!cmit) |
| 166 | + usage(describe_usage); |
| 167 | + |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 168 | if (!initialized) { |
| 169 | initialized = 1; |
| 170 | for_each_ref(get_name); |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 171 | ------------ |
| 172 | |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 173 | 1. It is preceded with a "git diff" header, that looks like |
| 174 | this (when '-c' option is used): |
| 175 | |
| 176 | diff --combined file |
| 177 | + |
| 178 | or like this (when '--cc' option is used): |
| 179 | |
| 180 | diff --c file |
| 181 | |
| 182 | 2. It is followed by one or more extended header lines |
| 183 | (this example shows a merge with two parents): |
| 184 | |
| 185 | index <hash>,<hash>..<hash> |
| 186 | mode <mode>,<mode>..<mode> |
| 187 | new file mode <mode> |
| 188 | deleted file mode <mode>,<mode> |
| 189 | + |
| 190 | The `mode <mode>,<mode>..<mode>` line appears only if at least one of |
Junio C Hamano | ee1e428 | 2007-02-04 08:32:04 | [diff] [blame] | 191 | the <mode> is different from the rest. Extended headers with |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 192 | information about detected contents movement (renames and |
| 193 | copying detection) are designed to work with diff of two |
| 194 | <tree-ish> and are not used by combined diff format. |
| 195 | |
| 196 | 3. It is followed by two-line from-file/to-file header |
| 197 | |
| 198 | --- a/file |
| 199 | +++ b/file |
| 200 | + |
| 201 | Similar to two-line header for traditional 'unified' diff |
| 202 | format, `/dev/null` is used to signal created or deleted |
| 203 | files. |
| 204 | |
| 205 | 4. Chunk header format is modified to prevent people from |
| 206 | accidentally feeding it to `patch -p1`. Combined diff format |
| 207 | was created for review of merge commit changes, and was not |
| 208 | meant for apply. The change is similar to the change in the |
| 209 | extended 'index' header: |
| 210 | |
| 211 | @@@ <from-file-range> <from-file-range> <to-file-range> @@@ |
| 212 | + |
| 213 | There are (number of parents + 1) `@` characters in the chunk |
| 214 | header for combined diff format. |
| 215 | |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 216 | Unlike the traditional 'unified' diff format, which shows two |
| 217 | files A and B with a single column that has `-` (minus -- |
| 218 | appears in A but removed in B), `+` (plus -- missing in A but |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 219 | added to B), or `" "` (space -- unchanged) prefix, this format |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 220 | compares two or more files file1, file2,... with one file X, and |
| 221 | shows how X differs from each of fileN. One column for each of |
| 222 | fileN is prepended to the output line to note how X's line is |
| 223 | different from it. |
| 224 | |
| 225 | A `-` character in the column N means that the line appears in |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 226 | fileN but it does not appear in the result. A `+` character |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 227 | in the column N means that the line appears in the last file, |
Junio C Hamano | 29f1431 | 2006-10-26 08:47:29 | [diff] [blame] | 228 | and fileN does not have that line (in other words, the line was |
| 229 | added, from the point of view of that parent). |
Junio C Hamano | fb56a96 | 2006-01-28 10:38:19 | [diff] [blame] | 230 | |
| 231 | In the above example output, the function signature was changed |
| 232 | from both files (hence two `-` removals from both file1 and |
| 233 | file2, plus `++` to mean one line that was added does not appear |
| 234 | in either file1 nor file2). Also two other lines are the same |
| 235 | from file1 but do not appear in file2 (hence prefixed with ` +`). |
| 236 | |
| 237 | When shown by `git diff-tree -c`, it compares the parents of a |
| 238 | merge commit with the merge result (i.e. file1..fileN are the |
| 239 | parents). When shown by `git diff-files -c`, it compares the |
| 240 | two unresolved merge parents with the working tree file |
| 241 | (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka |
| 242 | "their version"). |