1GIT-DIFF-FILES(1)                 Git Manual                 GIT-DIFF-FILES(1)
2
3
4

NAME

6       git-diff-files - Compares files in the working tree and the index
7

SYNOPSIS

9       git-diff-files [-q] [-0|-1|-2|-3|-c|--cc|--no-index] [<common diff
10       options>] [<path>...]
11

DESCRIPTION

13       Compares the files in the working tree and the index. When paths are
14       specified, compares only those named paths. Otherwise all entries in
15       the index are compared. The output format is the same as
16       "git-diff-index" and "git-diff-tree".
17

OPTIONS

19       -p
20           Generate patch (see section on generating patches)
21
22       -u
23           Synonym for "-p".
24
25       -U<n>
26           Shorthand for "--unified=<n>".
27
28       --unified=<n>
29           Generate diffs with <n> lines of context instead of the usual
30           three. Implies "-p".
31
32       --raw
33           Generate the raw format.
34
35       --patch-with-raw
36           Synonym for "-p --raw".
37
38       --stat[=width[,name-width]]
39           Generate a diffstat. You can override the default output width for
40           80-column terminal by "--stat=width". The width of the filename
41           part can be controlled by giving another width to it separated by a
42           comma.
43
44       --numstat
45           Similar to --stat, but shows number of added and deleted lines in
46           decimal notation and pathname without abbreviation, to make it more
47           machine friendly. For binary files, outputs two - instead of saying
48           0 0.
49
50       --shortstat
51           Output only the last line of the --stat format containing total
52           number of modified files, as well as number of added and deleted
53           lines.
54
55       --summary
56           Output a condensed summary of extended header information such as
57           creations, renames and mode changes.
58
59       --patch-with-stat
60           Synonym for "-p --stat".
61
62       -z
63           NUL-line termination on output. This affects the --raw output field
64           terminator. Also output from commands such as "git-log" will be
65           delimited with NUL between commits.
66
67       --name-only
68           Show only names of changed files.
69
70       --name-status
71           Show only names and status of changed files.
72
73       --color
74           Show colored diff.
75
76       --no-color
77           Turn off colored diff, even when the configuration file gives the
78           default to color output.
79
80       --color-words
81           Show colored word diff, i.e. color words which have changed.
82
83       --no-renames
84           Turn off rename detection, even when the configuration file gives
85           the default to do so.
86
87       --check
88           Warn if changes introduce trailing whitespace or an indent that
89           uses a space before a tab.
90
91       --full-index
92           Instead of the first handful characters, show full object name of
93           pre- and post-image blob on the "index" line when generating a
94           patch format output.
95
96       --binary
97           In addition to --full-index, output "binary diff" that can be
98           applied with "git apply".
99
100       --abbrev[=<n>]
101           Instead of showing the full 40-byte hexadecimal object name in
102           diff-raw format output and diff-tree header lines, show only
103           handful hexdigits prefix. This is independent of --full-index
104           option above, which controls the diff-patch output format. Non
105           default number of digits can be specified with --abbrev=<n>.
106
107       -B
108           Break complete rewrite changes into pairs of delete and create.
109
110       -M
111           Detect renames.
112
113       -C
114           Detect copies as well as renames. See also --find-copies-harder.
115
116       --diff-filter=[ACDMRTUXB*]
117           Select only files that are Added (A), Copied (C), Deleted (D),
118           Modified (M), Renamed (R), have their type (mode) changed (T), are
119           Unmerged (U), are Unknown (X), or have had their pairing Broken
120           (B). Any combination of the filter characters may be used. When *
121           (All-or-none) is added to the combination, all paths are selected
122           if there is any file that matches other criteria in the comparison;
123           if there is no file that matches other criteria, nothing is
124           selected.
125
126       --find-copies-harder
127           For performance reasons, by default, -C option finds copies only if
128           the original file of the copy was modified in the same changeset.
129           This flag makes the command inspect unmodified files as candidates
130           for the source of copy. This is a very expensive operation for
131           large projects, so use it with caution. Giving more than one -C
132           option has the same effect.
133
134       -l<num>
135           -M and -C options require O(n^2) processing time where n is the
136           number of potential rename/copy targets. This option prevents
137           rename/copy detection from running if the number of rename/copy
138           targets exceeds the specified number.
139
140       -S<string>
141           Look for differences that contain the change in <string>.
142
143       --pickaxe-all
144           When -S finds a change, show all the changes in that changeset, not
145           just the files that contain the change in <string>.
146
147       --pickaxe-regex
148           Make the <string> not a plain string but an extended POSIX regex to
149           match.
150
151       -O<orderfile>
152           Output the patch in the order specified in the <orderfile>, which
153           has one shell glob pattern per line.
154
155       -R
156           Swap two inputs; that is, show differences from index or on-disk
157           file to tree contents.
158
159       --text
160           Treat all files as text.
161
162       -a
163           Shorthand for "--text".
164
165       --ignore-space-at-eol
166           Ignore changes in white spaces at EOL.
167
168       --ignore-space-change
169           Ignore changes in amount of white space. This ignores white space
170           at line end, and consider all other sequences of one or more white
171           space characters to be equivalent.
172
173       -b
174           Shorthand for "--ignore-space-change".
175
176       --ignore-all-space
177           Ignore white space when comparing lines. This ignores difference
178           even if one line has white space where the other line has none.
179
180       -w
181           Shorthand for "--ignore-all-space".
182
183       --exit-code
184           Make the program exit with codes similar to diff(1). That is, it
185           exits with 1 if there were differences and 0 means no differences.
186
187       --quiet
188           Disable all output of the program. Implies --exit-code.
189
190       --ext-diff
191           Allow an external diff helper to be executed. If you set an
192           external diff driver with gitlink:gitattributes(5), you need to use
193           this option with gitlink:git-log(1) and friends.
194
195       --no-ext-diff
196           Disallow external diff drivers.
197       For more detailed explanation on these common options, see also
198       diffcore documentation[1].
199
200       -1 -2 -3 or --base --ours --theirs, and -0
201           Diff against the "base" version, "our branch" or "their branch"
202           respectively. With these options, diffs for merged entries are not
203           shown.
204
205           The default is to diff against our branch (-2) and the cleanly
206           resolved paths. The option -0 can be given to omit diff output for
207           unmerged entries and just show "Unmerged".
208
209       -c,--cc
210           This compares stage 2 (our branch), stage 3 (their branch) and the
211           working tree file and outputs a combined diff, similar to the way
212           diff-tree shows a merge commit with these flags.
213
214       --no-index
215           Compare the two given files / directories.
216
217       -q
218           Remain silent even on nonexistent files
219

OUTPUT FORMAT

221       The output format from "git-diff-index", "git-diff-tree" and
222       "git-diff-files" are very similar.
223
224       These commands all compare two sets of things; what is compared
225       differs:
226
227       git-diff-index <tree-ish>
228           compares the <tree-ish> and the files on the filesystem.
229
230       git-diff-index --cached <tree-ish>
231           compares the <tree-ish> and the index.
232
233       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
234           compares the trees named by the two arguments.
235
236       git-diff-files [<pattern>...]
237           compares the index and the files on the filesystem.
238       An output line is formatted this way:
239
240
241
242           in-place edit  :100644 100644 bcd1234... 0123456... M file0
243           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
244           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
245           create         :000000 100644 0000000... 1234567... A file4
246           delete         :100644 000000 1234567... 0000000... D file5
247           unmerged       :000000 000000 0000000... 0000000... U file6
248
249       That is, from the left to the right:
250
251
252        1.  a colon.
253
254        2.  mode for "src"; 000000 if creation or unmerged.
255
256        3.  a space.
257
258        4.  mode for "dst"; 000000 if deletion or unmerged.
259
260        5.  a space.
261
262        6.  sha1 for "src"; 0{40} if creation or unmerged.
263
264        7.  a space.
265
266        8.  sha1 for "dst"; 0{40} if creation, unmerged or "look at work
267           tree".
268
269        9.  a space.
270
271       10.  status, followed by optional "score" number.
272
273       11.  a tab or a NUL when -z option is used.
274
275       12.  path for "src"
276
277       13.  a tab or a NUL when -z option is used; only exists for C or R.
278
279       14.  path for "dst"; only exists for C or R.
280
281       15.  an LF or a NUL when -z option is used, to terminate the record.
282       <sha1> is shown as all 0´s if a file is new on the filesystem and it is
283       out of sync with the index.
284
285       Example:
286
287
288
289           :100644 100644 5be4a4...... 000000...... M file.c
290
291       When -z option is not used, TAB, LF, and backslash characters in
292       pathnames are represented as \t, \n, and \\, respectively.
293

DIFF FORMAT FOR MERGES

295       "git-diff-tree" and "git-diff-files" can take -c or --cc option to
296       generate diff output also for merge commits. The output differs from
297       the format described above in the following way:
298
299
300        1.  there is a colon for each parent
301
302        2.  there are more "src" modes and "src" sha1
303
304        3.  status is concatenated status characters for each parent
305
306        4.  no optional "score" number
307
308        5.  single path, only for "dst"
309       Example:
310
311
312
313           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
314
315       Note that combined diff lists only files which were modified from all
316       parents.
317

GENERATING PATCHES WITH -P

319       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
320       with a -p option, they do not produce the output described above;
321       instead they produce a patch file. You can customize the creation of
322       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
323       environment variables.
324
325       What the -p option produces is slightly different from the traditional
326       diff format.
327
328
329        1.  It is preceded with a "git diff" header, that looks like this:
330
331
332               diff --git a/file1 b/file2
333           The a/ and b/ filenames are the same unless rename/copy is
334           involved. Especially, even for a creation or a deletion, /dev/null
335           is not used in place of a/ or b/ filenames.
336
337           When rename/copy is involved, file1 and file2 show the name of the
338           source file of the rename/copy and the name of the file that
339           rename/copy produces, respectively.
340
341        2.  It is followed by one or more extended header lines:
342
343
344               old mode <mode>
345               new mode <mode>
346               deleted file mode <mode>
347               new file mode <mode>
348               copy from <path>
349               copy to <path>
350               rename from <path>
351               rename to <path>
352               similarity index <number>
353               dissimilarity index <number>
354               index <hash>..<hash> <mode>
355
356        3.  TAB, LF, double quote and backslash characters in pathnames are
357           represented as \t, \n, \" and \\, respectively. If there is need
358           for such substitution then the whole pathname is put in double
359           quotes.
360       The similarity index is the percentage of unchanged lines, and the
361       dissimilarity index is the percentage of changed lines. It is a rounded
362       down integer, followed by a percent sign. The similarity index value of
363       100% is thus reserved for two equal files, while 100% dissimilarity
364       means that no line from the old file made it into the new one.
365

COMBINED DIFF FORMAT

367       git-diff-tree and git-diff-files can take -c or --cc option to produce
368       combined diff, which looks like this:
369
370
371
372           diff --combined describe.c
373           index fabadb8,cc95eb0..4866510
374           --- a/describe.c
375           +++ b/describe.c
376           @@@ -98,20 -98,12 +98,20 @@@
377                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
378             }
379
380           - static void describe(char *arg)
381            -static void describe(struct commit *cmit, int last_one)
382           ++static void describe(char *arg, int last_one)
383             {
384            +      unsigned char sha1[20];
385            +      struct commit *cmit;
386                   struct commit_list *list;
387                   static int initialized = 0;
388                   struct commit_name *n;
389
390            +      if (get_sha1(arg, sha1) < 0)
391            +              usage(describe_usage);
392            +      cmit = lookup_commit_reference(sha1);
393            +      if (!cmit)
394            +              usage(describe_usage);
395            +
396                   if (!initialized) {
397                           initialized = 1;
398                           for_each_ref(get_name);
399
400
401        1.  It is preceded with a "git diff" header, that looks like this
402           (when -c option is used):
403
404
405               diff --combined file
406           or like this (when --cc option is used):
407
408
409               diff --c file
410
411        2.  It is followed by one or more extended header lines (this example
412           shows a merge with two parents):
413
414
415               index <hash>,<hash>..<hash>
416               mode <mode>,<mode>..<mode>
417               new file mode <mode>
418               deleted file mode <mode>,<mode>
419           The mode <mode>,<mode>..<mode> line appears only if at least one of
420           the <mode> is different from the rest. Extended headers with
421           information about detected contents movement (renames and copying
422           detection) are designed to work with diff of two <tree-ish> and are
423           not used by combined diff format.
424
425        3.  It is followed by two-line from-file/to-file header
426
427
428               --- a/file
429               +++ b/file
430           Similar to two-line header for traditional unified diff format,
431           /dev/null is used to signal created or deleted files.
432
433        4.  Chunk header format is modified to prevent people from
434           accidentally feeding it to patch -p1. Combined diff format was
435           created for review of merge commit changes, and was not meant for
436           apply. The change is similar to the change in the extended index
437           header:
438
439
440               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
441           There are (number of parents + 1) @ characters in the chunk header
442           for combined diff format.
443       Unlike the traditional unified diff format, which shows two files A and
444       B with a single column that has - (minus — appears in A but removed in
445       B), + (plus — missing in A but added to B), or " " (space — unchanged)
446       prefix, this format compares two or more files file1, file2,... with
447       one file X, and shows how X differs from each of fileN. One column for
448       each of fileN is prepended to the output line to note how X´s line is
449       different from it.
450
451       A - character in the column N means that the line appears in fileN but
452       it does not appear in the result. A + character in the column N means
453       that the line appears in the last file, and fileN does not have that
454       line (in other words, the line was added, from the point of view of
455       that parent).
456
457       In the above example output, the function signature was changed from
458       both files (hence two - removals from both file1 and file2, plus + to
459       mean one line that was added does not appear in either file1 nor
460       file2). Also two other lines are the same from file1 but do not appear
461       in file2 (hence prefixed with ).
462
463       When shown by git diff-tree -c, it compares the parents of a merge
464       commit with the merge result (i.e. file1..fileN are the parents). When
465       shown by git diff-files -c, it compares the two unresolved merge
466       parents with the working tree file (i.e. file1 is stage 2 aka "our
467       version", file2 is stage 3 aka "their version").
468

AUTHOR

470       Written by Linus Torvalds <torvalds@osdl.org>
471

DOCUMENTATION

473       Documentation by David Greaves, Junio C Hamano and the git-list
474       <git@vger.kernel.org>.
475

GIT

477       Part of the git(7) suite
478

NOTES

480        1. diffcore documentation
481           diffcore.html
482
483
484
485Git 1.5.3.3                       10/09/2007                 GIT-DIFF-FILES(1)
Impressum