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