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] [<common diff options>]
10       [<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 for git
16       diff-index and git diff-tree.
17

OPTIONS

19       -p, -u
20           Generate patch (see section on generating patches).
21
22       -U<n>, --unified=<n>
23           Generate diffs with <n> lines of context instead of the usual
24           three. Implies -p.
25
26       --raw
27           Generate the raw format. This is the default.
28
29       --patch-with-raw
30           Synonym for -p --raw.
31
32       --patience
33           Generate a diff using the "patience diff" algorithm.
34
35       --stat[=width[,name-width]]
36           Generate a diffstat. You can override the default output width for
37           80-column terminal by --stat=width. The width of the filename part
38           can be controlled by giving another width to it separated by a
39           comma.
40
41       --numstat
42           Similar to --stat, but shows number of added and deleted lines in
43           decimal notation and pathname without abbreviation, to make it more
44           machine friendly. For binary files, outputs two - instead of saying
45           0 0.
46
47       --shortstat
48           Output only the last line of the --stat format containing total
49           number of modified files, as well as number of added and deleted
50           lines.
51
52       --dirstat[=limit]
53           Output the distribution of relative amount of changes (number of
54           lines added or removed) for each sub-directory. Directories with
55           changes below a cut-off percent (3% by default) are not shown. The
56           cut-off percent can be set with --dirstat=limit. Changes in a child
57           directory is not counted for the parent directory, unless
58           --cumulative is used.
59
60       --dirstat-by-file[=limit]
61           Same as --dirstat, but counts changed files instead of lines.
62
63       --summary
64           Output a condensed summary of extended header information such as
65           creations, renames and mode changes.
66
67       --patch-with-stat
68           Synonym for -p --stat.
69
70       -z
71           When --raw, --numstat, --name-only or --name-status has been given,
72           do not munge pathnames and use NULs as output field terminators.
73
74           Without this option, each pathname output will have TAB, LF, double
75           quotes, and backslash characters replaced with \t, \n, \", and \\,
76           respectively, and the pathname will be enclosed in double quotes if
77           any of those replacements occurred.
78
79       --name-only
80           Show only names of changed files.
81
82       --name-status
83           Show only names and status of changed files. See the description of
84           the --diff-filter option on what the status letters mean.
85
86       --submodule[=<format>]
87           Chose the output format for submodule differences. <format> can be
88           one of short and log.  short just shows pairs of commit names, this
89           format is used when this option is not given.  log is the default
90           value for this option and lists the commits in that commit range
91           like the summary option of git-submodule(1) does.
92
93       --color[=<when>]
94           Show colored diff. The value must be always (the default), never,
95           or auto.
96
97       --no-color
98           Turn off colored diff, even when the configuration file gives the
99           default to color output. Same as --color=never.
100
101       --color-words[=<regex>]
102           Show colored word diff, i.e., color words which have changed. By
103           default, words are separated by whitespace.
104
105           When a <regex> is specified, every non-overlapping match of the
106           <regex> is considered a word. Anything between these matches is
107           considered whitespace and ignored(!) for the purposes of finding
108           differences. You may want to append |[^[:space:]] to your regular
109           expression to make sure that it matches all non-whitespace
110           characters. A match that contains a newline is silently
111           truncated(!) at the newline.
112
113           The regex can also be set via a diff driver or configuration
114           option, see gitattributes(1) or git-config(1). Giving it explicitly
115           overrides any diff driver or configuration setting. Diff drivers
116           override configuration settings.
117
118       --no-renames
119           Turn off rename detection, even when the configuration file gives
120           the default to do so.
121
122       --check
123           Warn if changes introduce trailing whitespace or an indent that
124           uses a space before a tab. Exits with non-zero status if problems
125           are found. Not compatible with --exit-code.
126
127       --full-index
128           Instead of the first handful of characters, show the full pre- and
129           post-image blob object names on the "index" line when generating
130           patch format output.
131
132       --binary
133           In addition to --full-index, output a binary diff that can be
134           applied with git-apply.
135
136       --abbrev[=<n>]
137           Instead of showing the full 40-byte hexadecimal object name in
138           diff-raw format output and diff-tree header lines, show only a
139           partial prefix. This is independent of the --full-index option
140           above, which controls the diff-patch output format. Non default
141           number of digits can be specified with --abbrev=<n>.
142
143       -B
144           Break complete rewrite changes into pairs of delete and create.
145
146       -M
147           Detect renames.
148
149       -C
150           Detect copies as well as renames. See also --find-copies-harder.
151
152       --diff-filter=[ACDMRTUXB*]
153           Select only files that are Added (A), Copied (C), Deleted (D),
154           Modified (M), Renamed (R), have their type (i.e. regular file,
155           symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
156           (X), or have had their pairing Broken (B). Any combination of the
157           filter characters may be used. When * (All-or-none) is added to the
158           combination, all paths are selected if there is any file that
159           matches other criteria in the comparison; if there is no file that
160           matches other criteria, nothing is selected.
161
162       --find-copies-harder
163           For performance reasons, by default, -C option finds copies only if
164           the original file of the copy was modified in the same changeset.
165           This flag makes the command inspect unmodified files as candidates
166           for the source of copy. This is a very expensive operation for
167           large projects, so use it with caution. Giving more than one -C
168           option has the same effect.
169
170       -l<num>
171           The -M and -C options require O(n^2) processing time where n is the
172           number of potential rename/copy targets. This option prevents
173           rename/copy detection from running if the number of rename/copy
174           targets exceeds the specified number.
175
176       -S<string>
177           Look for differences that introduce or remove an instance of
178           <string>. Note that this is different than the string simply
179           appearing in diff output; see the pickaxe entry in gitdiffcore(7)
180           for more details.
181
182       --pickaxe-all
183           When -S finds a change, show all the changes in that changeset, not
184           just the files that contain the change in <string>.
185
186       --pickaxe-regex
187           Make the <string> not a plain string but an extended POSIX regex to
188           match.
189
190       -O<orderfile>
191           Output the patch in the order specified in the <orderfile>, which
192           has one shell glob pattern per line.
193
194       -R
195           Swap two inputs; that is, show differences from index or on-disk
196           file to tree contents.
197
198       --relative[=<path>]
199           When run from a subdirectory of the project, it can be told to
200           exclude changes outside the directory and show pathnames relative
201           to it with this option. When you are not in a subdirectory (e.g. in
202           a bare repository), you can name which subdirectory to make the
203           output relative to by giving a <path> as an argument.
204
205       -a, --text
206           Treat all files as text.
207
208       --ignore-space-at-eol
209           Ignore changes in whitespace at EOL.
210
211       -b, --ignore-space-change
212           Ignore changes in amount of whitespace. This ignores whitespace at
213           line end, and considers all other sequences of one or more
214           whitespace characters to be equivalent.
215
216       -w, --ignore-all-space
217           Ignore whitespace when comparing lines. This ignores differences
218           even if one line has whitespace where the other line has none.
219
220       --inter-hunk-context=<lines>
221           Show the context between diff hunks, up to the specified number of
222           lines, thereby fusing hunks that are close to each other.
223
224       --exit-code
225           Make the program exit with codes similar to diff(1). That is, it
226           exits with 1 if there were differences and 0 means no differences.
227
228       --quiet
229           Disable all output of the program. Implies --exit-code.
230
231       --ext-diff
232           Allow an external diff helper to be executed. If you set an
233           external diff driver with gitattributes(5), you need to use this
234           option with git-log(1) and friends.
235
236       --no-ext-diff
237           Disallow external diff drivers.
238
239       --ignore-submodules
240           Ignore changes to submodules in the diff generation.
241
242       --src-prefix=<prefix>
243           Show the given source prefix instead of "a/".
244
245       --dst-prefix=<prefix>
246           Show the given destination prefix instead of "b/".
247
248       --no-prefix
249           Do not show any source or destination prefix.
250
251       For more detailed explanation on these common options, see also
252       gitdiffcore(7).
253
254       -1 --base, -2 --ours, -3 --theirs, -0
255           Diff against the "base" version, "our branch" or "their branch"
256           respectively. With these options, diffs for merged entries are not
257           shown.
258
259           The default is to diff against our branch (-2) and the cleanly
260           resolved paths. The option -0 can be given to omit diff output for
261           unmerged entries and just show "Unmerged".
262
263       -c, --cc
264           This compares stage 2 (our branch), stage 3 (their branch) and the
265           working tree file and outputs a combined diff, similar to the way
266           diff-tree shows a merge commit with these flags.
267
268       -q
269           Remain silent even on nonexistent files
270

RAW OUTPUT FORMAT

272       The raw output format from "git-diff-index", "git-diff-tree",
273       "git-diff-files" and "git diff --raw" are very similar.
274
275       These commands all compare two sets of things; what is compared
276       differs:
277
278       git-diff-index <tree-ish>
279           compares the <tree-ish> and the files on the filesystem.
280
281       git-diff-index --cached <tree-ish>
282           compares the <tree-ish> and the index.
283
284       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
285           compares the trees named by the two arguments.
286
287       git-diff-files [<pattern>...]
288           compares the index and the files on the filesystem.
289
290       The "git-diff-tree" command begins its output by printing the hash of
291       what is being compared. After that, all the commands print one output
292       line per changed file.
293
294       An output line is formatted this way:
295
296           in-place edit  :100644 100644 bcd1234... 0123456... M file0
297           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
298           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
299           create         :000000 100644 0000000... 1234567... A file4
300           delete         :100644 000000 1234567... 0000000... D file5
301           unmerged       :000000 000000 0000000... 0000000... U file6
302
303
304       That is, from the left to the right:
305
306        1. a colon.
307
308        2. mode for "src"; 000000 if creation or unmerged.
309
310        3. a space.
311
312        4. mode for "dst"; 000000 if deletion or unmerged.
313
314        5. a space.
315
316        6. sha1 for "src"; 0{40} if creation or unmerged.
317
318        7. a space.
319
320        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
321
322        9. a space.
323
324       10. status, followed by optional "score" number.
325
326       11. a tab or a NUL when -z option is used.
327
328       12. path for "src"
329
330       13. a tab or a NUL when -z option is used; only exists for C or R.
331
332       14. path for "dst"; only exists for C or R.
333
334       15. an LF or a NUL when -z option is used, to terminate the record.
335
336       Possible status letters are:
337
338       ·   A: addition of a file
339
340       ·   C: copy of a file into a new one
341
342       ·   D: deletion of a file
343
344       ·   M: modification of the contents or mode of a file
345
346       ·   R: renaming of a file
347
348       ·   T: change in the type of the file
349
350       ·   U: file is unmerged (you must complete the merge before it can be
351           committed)
352
353       ·   X: "unknown" change type (most probably a bug, please report it)
354
355       Status letters C and R are always followed by a score (denoting the
356       percentage of similarity between the source and target of the move or
357       copy), and are the only ones to be so.
358
359       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
360       out of sync with the index.
361
362       Example:
363
364           :100644 100644 5be4a4...... 000000...... M file.c
365
366
367       When -z option is not used, TAB, LF, and backslash characters in
368       pathnames are represented as \t, \n, and \\, respectively.
369

DIFF FORMAT FOR MERGES

371       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
372       --cc option to generate diff output also for merge commits. The output
373       differs from the format described above in the following way:
374
375        1. there is a colon for each parent
376
377        2. there are more "src" modes and "src" sha1
378
379        3. status is concatenated status characters for each parent
380
381        4. no optional "score" number
382
383        5. single path, only for "dst"
384
385       Example:
386
387           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
388
389
390       Note that combined diff lists only files which were modified from all
391       parents.
392

GENERATING PATCHES WITH -P

394       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
395       with a -p option, "git diff" without the --raw option, or "git log"
396       with the "-p" option, they do not produce the output described above;
397       instead they produce a patch file. You can customize the creation of
398       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
399       environment variables.
400
401       What the -p option produces is slightly different from the traditional
402       diff format.
403
404        1. It is preceded with a "git diff" header, that looks like this:
405
406               diff --git a/file1 b/file2
407
408           The a/ and b/ filenames are the same unless rename/copy is
409           involved. Especially, even for a creation or a deletion, /dev/null
410           is not used in place of a/ or b/ filenames.
411
412           When rename/copy is involved, file1 and file2 show the name of the
413           source file of the rename/copy and the name of the file that
414           rename/copy produces, respectively.
415
416        2. It is followed by one or more extended header lines:
417
418               old mode <mode>
419               new mode <mode>
420               deleted file mode <mode>
421               new file mode <mode>
422               copy from <path>
423               copy to <path>
424               rename from <path>
425               rename to <path>
426               similarity index <number>
427               dissimilarity index <number>
428               index <hash>..<hash> <mode>
429
430        3. TAB, LF, double quote and backslash characters in pathnames are
431           represented as \t, \n, \" and \\, respectively. If there is need
432           for such substitution then the whole pathname is put in double
433           quotes.
434
435       The similarity index is the percentage of unchanged lines, and the
436       dissimilarity index is the percentage of changed lines. It is a rounded
437       down integer, followed by a percent sign. The similarity index value of
438       100% is thus reserved for two equal files, while 100% dissimilarity
439       means that no line from the old file made it into the new one.
440

COMBINED DIFF FORMAT

442       "git-diff-tree", "git-diff-files" and "git-diff" can take -c or --cc
443       option to produce combined diff. For showing a merge commit with "git
444       log -p", this is the default format; you can force showing full diff
445       with the -m option. A combined diff format looks like this:
446
447           diff --combined describe.c
448           index fabadb8,cc95eb0..4866510
449           --- a/describe.c
450           +++ b/describe.c
451           @@@ -98,20 -98,12 +98,20 @@@
452                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
453             }
454
455           - static void describe(char *arg)
456            -static void describe(struct commit *cmit, int last_one)
457           ++static void describe(char *arg, int last_one)
458             {
459            +      unsigned char sha1[20];
460            +      struct commit *cmit;
461                   struct commit_list *list;
462                   static int initialized = 0;
463                   struct commit_name *n;
464
465            +      if (get_sha1(arg, sha1) < 0)
466            +              usage(describe_usage);
467            +      cmit = lookup_commit_reference(sha1);
468            +      if (!cmit)
469            +              usage(describe_usage);
470            +
471                   if (!initialized) {
472                           initialized = 1;
473                           for_each_ref(get_name);
474
475
476
477        1. It is preceded with a "git diff" header, that looks like this (when
478           -c option is used):
479
480               diff --combined file
481
482           or like this (when --cc option is used):
483
484               diff --cc file
485
486        2. It is followed by one or more extended header lines (this example
487           shows a merge with two parents):
488
489               index <hash>,<hash>..<hash>
490               mode <mode>,<mode>..<mode>
491               new file mode <mode>
492               deleted file mode <mode>,<mode>
493
494           The mode <mode>,<mode>..<mode> line appears only if at least one of
495           the <mode> is different from the rest. Extended headers with
496           information about detected contents movement (renames and copying
497           detection) are designed to work with diff of two <tree-ish> and are
498           not used by combined diff format.
499
500        3. It is followed by two-line from-file/to-file header
501
502               --- a/file
503               +++ b/file
504
505           Similar to two-line header for traditional unified diff format,
506           /dev/null is used to signal created or deleted files.
507
508        4. Chunk header format is modified to prevent people from accidentally
509           feeding it to patch -p1. Combined diff format was created for
510           review of merge commit changes, and was not meant for apply. The
511           change is similar to the change in the extended index header:
512
513               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
514
515           There are (number of parents + 1) @ characters in the chunk header
516           for combined diff format.
517
518       Unlike the traditional unified diff format, which shows two files A and
519       B with a single column that has - (minus — appears in A but removed in
520       B), + (plus — missing in A but added to B), or " " (space — unchanged)
521       prefix, this format compares two or more files file1, file2,... with
522       one file X, and shows how X differs from each of fileN. One column for
523       each of fileN is prepended to the output line to note how X’s line is
524       different from it.
525
526       A - character in the column N means that the line appears in fileN but
527       it does not appear in the result. A + character in the column N means
528       that the line appears in the result, and fileN does not have that line
529       (in other words, the line was added, from the point of view of that
530       parent).
531
532       In the above example output, the function signature was changed from
533       both files (hence two - removals from both file1 and file2, plus ++ to
534       mean one line that was added does not appear in either file1 nor
535       file2). Also eight other lines are the same from file1 but do not
536       appear in file2 (hence prefixed with +).
537
538       When shown by git diff-tree -c, it compares the parents of a merge
539       commit with the merge result (i.e. file1..fileN are the parents). When
540       shown by git diff-files -c, it compares the two unresolved merge
541       parents with the working tree file (i.e. file1 is stage 2 aka "our
542       version", file2 is stage 3 aka "their version").
543

OTHER DIFF FORMATS

545       The --summary option describes newly added, deleted, renamed and copied
546       files. The --stat option adds diffstat(1) graph to the output. These
547       options can be combined with other options, such as -p, and are meant
548       for human consumption.
549
550       When showing a change that involves a rename or a copy, --stat output
551       formats the pathnames compactly by combining common prefix and suffix
552       of the pathnames. For example, a change that moves arch/i386/Makefile
553       to arch/x86/Makefile while modifying 4 lines will be shown like this:
554
555           arch/{i386 => x86}/Makefile    |   4 +--
556
557
558       The --numstat option gives the diffstat(1) information but is designed
559       for easier machine consumption. An entry in --numstat output looks like
560       this:
561
562           1       2       README
563           3       1       arch/{i386 => x86}/Makefile
564
565
566       That is, from left to right:
567
568        1. the number of added lines;
569
570        2. a tab;
571
572        3. the number of deleted lines;
573
574        4. a tab;
575
576        5. pathname (possibly with rename/copy information);
577
578        6. a newline.
579
580       When -z output option is in effect, the output is formatted this way:
581
582           1       2       README NUL
583           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
584
585
586       That is:
587
588        1. the number of added lines;
589
590        2. a tab;
591
592        3. the number of deleted lines;
593
594        4. a tab;
595
596        5. a NUL (only exists if renamed/copied);
597
598        6. pathname in preimage;
599
600        7. a NUL (only exists if renamed/copied);
601
602        8. pathname in postimage (only exists if renamed/copied);
603
604        9. a NUL.
605
606       The extra NUL before the preimage path in renamed case is to allow
607       scripts that read the output to tell if the current record being read
608       is a single-path record or a rename/copy record without reading ahead.
609       After reading added and deleted lines, reading up to NUL would yield
610       the pathname, but if that is NUL, the record will show two paths.
611

AUTHOR

613       Written by Linus Torvalds <torvalds@osdl.org[1]>
614

DOCUMENTATION

616       Documentation by David Greaves, Junio C Hamano and the git-list
617       <git@vger.kernel.org[2]>.
618

GIT

620       Part of the git(1) suite
621

NOTES

623        1. torvalds@osdl.org
624           mailto:torvalds@osdl.org
625
626        2. git@vger.kernel.org
627           mailto:git@vger.kernel.org
628
629
630
631Git 1.7.1                         08/16/2017                 GIT-DIFF-FILES(1)
Impressum