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, --patch
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
38           part 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
57           child directory are 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       --word-diff[=<mode>]
102           Show a word diff, using the <mode> to delimit changed words. By
103           default, words are delimited by whitespace; see --word-diff-regex
104           below. The <mode> defaults to plain, and must be one of:
105
106           color
107               Highlight changed words using only colors. Implies --color.
108
109           plain
110               Show words as [-removed-] and {added}. Makes no attempts to
111               escape the delimiters if they appear in the input, so the
112               output may be ambiguous.
113
114           porcelain
115               Use a special line-based format intended for script
116               consumption. Added/removed/unchanged runs are printed in the
117               usual unified diff format, starting with a +/-/` ` character at
118               the beginning of the line and extending to the end of the line.
119               Newlines in the input are represented by a tilde ~ on a line of
120               its own.
121
122           none
123               Disable word diff again.
124
125           Note that despite the name of the first mode, color is used to
126           highlight the changed parts in all modes if enabled.
127
128       --word-diff-regex=<regex>
129           Use <regex> to decide what a word is, instead of considering runs
130           of non-whitespace to be a word. Also implies --word-diff unless it
131           was already enabled.
132
133           Every non-overlapping match of the <regex> is considered a word.
134           Anything between these matches is considered whitespace and
135           ignored(!) for the purposes of finding differences. You may want to
136           append |[^[:space:]] to your regular expression to make sure that
137           it matches all non-whitespace characters. A match that contains a
138           newline is silently truncated(!) at the newline.
139
140           The regex can also be set via a diff driver or configuration
141           option, see gitattributes(1) or git-config(1). Giving it explicitly
142           overrides any diff driver or configuration setting. Diff drivers
143           override configuration settings.
144
145       --color-words[=<regex>]
146           Equivalent to --word-diff=color plus (if a regex was specified)
147           --word-diff-regex=<regex>.
148
149       --no-renames
150           Turn off rename detection, even when the configuration file gives
151           the default to do so.
152
153       --check
154           Warn if changes introduce trailing whitespace or an indent that
155           uses a space before a tab. Exits with non-zero status if problems
156           are found. Not compatible with --exit-code.
157
158       --full-index
159           Instead of the first handful of characters, show the full pre- and
160           post-image blob object names on the "index" line when generating
161           patch format output.
162
163       --binary
164           In addition to --full-index, output a binary diff that can be
165           applied with git-apply.
166
167       --abbrev[=<n>]
168           Instead of showing the full 40-byte hexadecimal object name in
169           diff-raw format output and diff-tree header lines, show only a
170           partial prefix. This is independent of the --full-index option
171           above, which controls the diff-patch output format. Non default
172           number of digits can be specified with --abbrev=<n>.
173
174       -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
175           Break complete rewrite changes into pairs of delete and create.
176           This serves two purposes:
177
178           It affects the way a change that amounts to a total rewrite of a
179           file not as a series of deletion and insertion mixed together with
180           a very few lines that happen to match textually as the context, but
181           as a single deletion of everything old followed by a single
182           insertion of everything new, and the number m controls this aspect
183           of the -B option (defaults to 60%).  -B/70% specifies that less
184           than 30% of the original should remain in the result for git to
185           consider it a total rewrite (i.e. otherwise the resulting patch
186           will be a series of deletion and insertion mixed together with
187           context lines).
188
189           When used with -M, a totally-rewritten file is also considered as
190           the source of a rename (usually -M only considers a file that
191           disappeared as the source of a rename), and the number n controls
192           this aspect of the -B option (defaults to 50%).  -B20% specifies
193           that a change with addition and deletion compared to 20% or more of
194           the file’s size are eligible for being picked up as a possible
195           source of a rename to another file.
196
197       -M[<n>], --find-renames[=<n>]
198           Detect renames. If n is specified, it is a is a threshold on the
199           similarity index (i.e. amount of addition/deletions compared to the
200           file’s size). For example, -M90% means git should consider a
201           delete/add pair to be a rename if more than 90% of the file hasn’t
202           changed.
203
204       -C[<n>], --find-copies[=<n>]
205           Detect copies as well as renames. See also --find-copies-harder. If
206           n is specified, it has the same meaning as for -M<n>.
207
208       --find-copies-harder
209           For performance reasons, by default, -C option finds copies only if
210           the original file of the copy was modified in the same changeset.
211           This flag makes the command inspect unmodified files as candidates
212           for the source of copy. This is a very expensive operation for
213           large projects, so use it with caution. Giving more than one -C
214           option has the same effect.
215
216       -l<num>
217           The -M and -C options require O(n^2) processing time where n is the
218           number of potential rename/copy targets. This option prevents
219           rename/copy detection from running if the number of rename/copy
220           targets exceeds the specified number.
221
222       --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
223           Select only files that are Added (A), Copied (C), Deleted (D),
224           Modified (M), Renamed (R), have their type (i.e. regular file,
225           symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
226           (X), or have had their pairing Broken (B). Any combination of the
227           filter characters (including none) can be used. When *
228           (All-or-none) is added to the combination, all paths are selected
229           if there is any file that matches other criteria in the comparison;
230           if there is no file that matches other criteria, nothing is
231           selected.
232
233       -S<string>
234           Look for differences that introduce or remove an instance of
235           <string>. Note that this is different than the string simply
236           appearing in diff output; see the pickaxe entry in gitdiffcore(7)
237           for more details.
238
239       -G<regex>
240           Look for differences whose added or removed line matches the given
241           <regex>.
242
243       --pickaxe-all
244           When -S or -G finds a change, show all the changes in that
245           changeset, not just the files that contain the change in <string>.
246
247       --pickaxe-regex
248           Make the <string> not a plain string but an extended POSIX regex to
249           match.
250
251       -O<orderfile>
252           Output the patch in the order specified in the <orderfile>, which
253           has one shell glob pattern per line.
254
255       -R
256           Swap two inputs; that is, show differences from index or on-disk
257           file to tree contents.
258
259       --relative[=<path>]
260           When run from a subdirectory of the project, it can be told to
261           exclude changes outside the directory and show pathnames relative
262           to it with this option. When you are not in a subdirectory (e.g. in
263           a bare repository), you can name which subdirectory to make the
264           output relative to by giving a <path> as an argument.
265
266       -a, --text
267           Treat all files as text.
268
269       --ignore-space-at-eol
270           Ignore changes in whitespace at EOL.
271
272       -b, --ignore-space-change
273           Ignore changes in amount of whitespace. This ignores whitespace at
274           line end, and considers all other sequences of one or more
275           whitespace characters to be equivalent.
276
277       -w, --ignore-all-space
278           Ignore whitespace when comparing lines. This ignores differences
279           even if one line has whitespace where the other line has none.
280
281       --inter-hunk-context=<lines>
282           Show the context between diff hunks, up to the specified number of
283           lines, thereby fusing hunks that are close to each other.
284
285       --exit-code
286           Make the program exit with codes similar to diff(1). That is, it
287           exits with 1 if there were differences and 0 means no differences.
288
289       --quiet
290           Disable all output of the program. Implies --exit-code.
291
292       --ext-diff
293           Allow an external diff helper to be executed. If you set an
294           external diff driver with gitattributes(5), you need to use this
295           option with git-log(1) and friends.
296
297       --no-ext-diff
298           Disallow external diff drivers.
299
300       --ignore-submodules[=<when>]
301           Ignore changes to submodules in the diff generation. <when> can be
302           either "none", "untracked", "dirty" or "all", which is the default
303           Using "none" will consider the submodule modified when it either
304           contains untracked or modified files or its HEAD differs from the
305           commit recorded in the superproject and can be used to override any
306           settings of the ignore option in git-config(1) or gitmodules(5).
307           When "untracked" is used submodules are not considered dirty when
308           they only contain untracked content (but they are still scanned for
309           modified content). Using "dirty" ignores all changes to the work
310           tree of submodules, only changes to the commits stored in the
311           superproject are shown (this was the behavior until 1.7.0). Using
312           "all" hides all changes to submodules.
313
314       --src-prefix=<prefix>
315           Show the given source prefix instead of "a/".
316
317       --dst-prefix=<prefix>
318           Show the given destination prefix instead of "b/".
319
320       --no-prefix
321           Do not show any source or destination prefix.
322
323       For more detailed explanation on these common options, see also
324       gitdiffcore(7).
325
326       -1 --base, -2 --ours, -3 --theirs, -0
327           Diff against the "base" version, "our branch" or "their branch"
328           respectively. With these options, diffs for merged entries are not
329           shown.
330
331           The default is to diff against our branch (-2) and the cleanly
332           resolved paths. The option -0 can be given to omit diff output for
333           unmerged entries and just show "Unmerged".
334
335       -c, --cc
336           This compares stage 2 (our branch), stage 3 (their branch) and the
337           working tree file and outputs a combined diff, similar to the way
338           diff-tree shows a merge commit with these flags.
339
340       -q
341           Remain silent even on nonexistent files
342

RAW OUTPUT FORMAT

344       The raw output format from "git-diff-index", "git-diff-tree",
345       "git-diff-files" and "git diff --raw" are very similar.
346
347       These commands all compare two sets of things; what is compared
348       differs:
349
350       git-diff-index <tree-ish>
351           compares the <tree-ish> and the files on the filesystem.
352
353       git-diff-index --cached <tree-ish>
354           compares the <tree-ish> and the index.
355
356       git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
357           compares the trees named by the two arguments.
358
359       git-diff-files [<pattern>...]
360           compares the index and the files on the filesystem.
361
362       The "git-diff-tree" command begins its output by printing the hash of
363       what is being compared. After that, all the commands print one output
364       line per changed file.
365
366       An output line is formatted this way:
367
368           in-place edit  :100644 100644 bcd1234... 0123456... M file0
369           copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
370           rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
371           create         :000000 100644 0000000... 1234567... A file4
372           delete         :100644 000000 1234567... 0000000... D file5
373           unmerged       :000000 000000 0000000... 0000000... U file6
374
375
376       That is, from the left to the right:
377
378        1. a colon.
379
380        2. mode for "src"; 000000 if creation or unmerged.
381
382        3. a space.
383
384        4. mode for "dst"; 000000 if deletion or unmerged.
385
386        5. a space.
387
388        6. sha1 for "src"; 0{40} if creation or unmerged.
389
390        7. a space.
391
392        8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
393
394        9. a space.
395
396       10. status, followed by optional "score" number.
397
398       11. a tab or a NUL when -z option is used.
399
400       12. path for "src"
401
402       13. a tab or a NUL when -z option is used; only exists for C or R.
403
404       14. path for "dst"; only exists for C or R.
405
406       15. an LF or a NUL when -z option is used, to terminate the record.
407
408       Possible status letters are:
409
410       ·   A: addition of a file
411
412       ·   C: copy of a file into a new one
413
414       ·   D: deletion of a file
415
416       ·   M: modification of the contents or mode of a file
417
418       ·   R: renaming of a file
419
420       ·   T: change in the type of the file
421
422       ·   U: file is unmerged (you must complete the merge before it can be
423           committed)
424
425       ·   X: "unknown" change type (most probably a bug, please report it)
426
427       Status letters C and R are always followed by a score (denoting the
428       percentage of similarity between the source and target of the move or
429       copy), and are the only ones to be so.
430
431       <sha1> is shown as all 0’s if a file is new on the filesystem and it is
432       out of sync with the index.
433
434       Example:
435
436           :100644 100644 5be4a4...... 000000...... M file.c
437
438
439       When -z option is not used, TAB, LF, and backslash characters in
440       pathnames are represented as \t, \n, and \\, respectively.
441

DIFF FORMAT FOR MERGES

443       "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
444       --cc option to generate diff output also for merge commits. The output
445       differs from the format described above in the following way:
446
447        1. there is a colon for each parent
448
449        2. there are more "src" modes and "src" sha1
450
451        3. status is concatenated status characters for each parent
452
453        4. no optional "score" number
454
455        5. single path, only for "dst"
456
457       Example:
458
459           ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
460
461
462       Note that combined diff lists only files which were modified from all
463       parents.
464

GENERATING PATCHES WITH -P

466       When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
467       with a -p option, "git diff" without the --raw option, or "git log"
468       with the "-p" option, they do not produce the output described above;
469       instead they produce a patch file. You can customize the creation of
470       such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
471       environment variables.
472
473       What the -p option produces is slightly different from the traditional
474       diff format:
475
476        1. It is preceded with a "git diff" header that looks like this:
477
478               diff --git a/file1 b/file2
479
480           The a/ and b/ filenames are the same unless rename/copy is
481           involved. Especially, even for a creation or a deletion, /dev/null
482           is not used in place of the a/ or b/ filenames.
483
484           When rename/copy is involved, file1 and file2 show the name of the
485           source file of the rename/copy and the name of the file that
486           rename/copy produces, respectively.
487
488        2. It is followed by one or more extended header lines:
489
490               old mode <mode>
491               new mode <mode>
492               deleted file mode <mode>
493               new file mode <mode>
494               copy from <path>
495               copy to <path>
496               rename from <path>
497               rename to <path>
498               similarity index <number>
499               dissimilarity index <number>
500               index <hash>..<hash> <mode>
501
502           File modes are printed as 6-digit octal numbers including the file
503           type and file permission bits.
504
505           Path names in extended headers do not include the a/ and b/
506           prefixes.
507
508           The similarity index is the percentage of unchanged lines, and the
509           dissimilarity index is the percentage of changed lines. It is a
510           rounded down integer, followed by a percent sign. The similarity
511           index value of 100% is thus reserved for two equal files, while
512           100% dissimilarity means that no line from the old file made it
513           into the new one.
514
515           The index line includes the SHA-1 checksum before and after the
516           change. The <mode> is included if the file mode does not change;
517           otherwise, separate lines indicate the old and the new mode.
518
519        3. TAB, LF, double quote and backslash characters in pathnames are
520           represented as \t, \n, \" and \\, respectively. If there is need
521           for such substitution then the whole pathname is put in double
522           quotes.
523
524        4. All the file1 files in the output refer to files before the commit,
525           and all the file2 files refer to files after the commit. It is
526           incorrect to apply each change to each file sequentially. For
527           example, this patch will swap a and b:
528
529               diff --git a/a b/b
530               rename from a
531               rename to b
532               diff --git a/b b/a
533               rename from b
534               rename to a
535

COMBINED DIFF FORMAT

537       Any diff-generating command can take the ‘-c` or --cc option to produce
538       a combined diff when showing a merge. This is the default format when
539       showing merges with git-diff(1) or git-show(1). Note also that you can
540       give the `-m’ option to any of these commands to force generation of
541       diffs with individual parents of a merge.
542
543       A combined diff format looks like this:
544
545           diff --combined describe.c
546           index fabadb8,cc95eb0..4866510
547           --- a/describe.c
548           +++ b/describe.c
549           @@@ -98,20 -98,12 +98,20 @@@
550                   return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
551             }
552
553           - static void describe(char *arg)
554            -static void describe(struct commit *cmit, int last_one)
555           ++static void describe(char *arg, int last_one)
556             {
557            +      unsigned char sha1[20];
558            +      struct commit *cmit;
559                   struct commit_list *list;
560                   static int initialized = 0;
561                   struct commit_name *n;
562
563            +      if (get_sha1(arg, sha1) < 0)
564            +              usage(describe_usage);
565            +      cmit = lookup_commit_reference(sha1);
566            +      if (!cmit)
567            +              usage(describe_usage);
568            +
569                   if (!initialized) {
570                           initialized = 1;
571                           for_each_ref(get_name);
572
573
574
575        1. It is preceded with a "git diff" header, that looks like this (when
576           -c option is used):
577
578               diff --combined file
579
580           or like this (when --cc option is used):
581
582               diff --cc file
583
584        2. It is followed by one or more extended header lines (this example
585           shows a merge with two parents):
586
587               index <hash>,<hash>..<hash>
588               mode <mode>,<mode>..<mode>
589               new file mode <mode>
590               deleted file mode <mode>,<mode>
591
592           The mode <mode>,<mode>..<mode> line appears only if at least one of
593           the <mode> is different from the rest. Extended headers with
594           information about detected contents movement (renames and copying
595           detection) are designed to work with diff of two <tree-ish> and are
596           not used by combined diff format.
597
598        3. It is followed by two-line from-file/to-file header
599
600               --- a/file
601               +++ b/file
602
603           Similar to two-line header for traditional unified diff format,
604           /dev/null is used to signal created or deleted files.
605
606        4. Chunk header format is modified to prevent people from accidentally
607           feeding it to patch -p1. Combined diff format was created for
608           review of merge commit changes, and was not meant for apply. The
609           change is similar to the change in the extended index header:
610
611               @@@ <from-file-range> <from-file-range> <to-file-range> @@@
612
613           There are (number of parents + 1) @ characters in the chunk header
614           for combined diff format.
615
616       Unlike the traditional unified diff format, which shows two files A and
617       B with a single column that has - (minus — appears in A but removed in
618       B), + (plus — missing in A but added to B), or " " (space — unchanged)
619       prefix, this format compares two or more files file1, file2,... with
620       one file X, and shows how X differs from each of fileN. One column for
621       each of fileN is prepended to the output line to note how X’s line is
622       different from it.
623
624       A - character in the column N means that the line appears in fileN but
625       it does not appear in the result. A + character in the column N means
626       that the line appears in the result, and fileN does not have that line
627       (in other words, the line was added, from the point of view of that
628       parent).
629
630       In the above example output, the function signature was changed from
631       both files (hence two - removals from both file1 and file2, plus ++ to
632       mean one line that was added does not appear in either file1 nor
633       file2). Also eight other lines are the same from file1 but do not
634       appear in file2 (hence prefixed with +).
635
636       When shown by git diff-tree -c, it compares the parents of a merge
637       commit with the merge result (i.e. file1..fileN are the parents). When
638       shown by git diff-files -c, it compares the two unresolved merge
639       parents with the working tree file (i.e. file1 is stage 2 aka "our
640       version", file2 is stage 3 aka "their version").
641

OTHER DIFF FORMATS

643       The --summary option describes newly added, deleted, renamed and copied
644       files. The --stat option adds diffstat(1) graph to the output. These
645       options can be combined with other options, such as -p, and are meant
646       for human consumption.
647
648       When showing a change that involves a rename or a copy, --stat output
649       formats the pathnames compactly by combining common prefix and suffix
650       of the pathnames. For example, a change that moves arch/i386/Makefile
651       to arch/x86/Makefile while modifying 4 lines will be shown like this:
652
653           arch/{i386 => x86}/Makefile    |   4 +--
654
655
656       The --numstat option gives the diffstat(1) information but is designed
657       for easier machine consumption. An entry in --numstat output looks like
658       this:
659
660           1       2       README
661           3       1       arch/{i386 => x86}/Makefile
662
663
664       That is, from left to right:
665
666        1. the number of added lines;
667
668        2. a tab;
669
670        3. the number of deleted lines;
671
672        4. a tab;
673
674        5. pathname (possibly with rename/copy information);
675
676        6. a newline.
677
678       When -z output option is in effect, the output is formatted this way:
679
680           1       2       README NUL
681           3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
682
683
684       That is:
685
686        1. the number of added lines;
687
688        2. a tab;
689
690        3. the number of deleted lines;
691
692        4. a tab;
693
694        5. a NUL (only exists if renamed/copied);
695
696        6. pathname in preimage;
697
698        7. a NUL (only exists if renamed/copied);
699
700        8. pathname in postimage (only exists if renamed/copied);
701
702        9. a NUL.
703
704       The extra NUL before the preimage path in renamed case is to allow
705       scripts that read the output to tell if the current record being read
706       is a single-path record or a rename/copy record without reading ahead.
707       After reading added and deleted lines, reading up to NUL would yield
708       the pathname, but if that is NUL, the record will show two paths.
709

AUTHOR

711       Written by Linus Torvalds <torvalds@osdl.org[1]>
712

DOCUMENTATION

714       Documentation by David Greaves, Junio C Hamano and the git-list
715       <git@vger.kernel.org[2]>.
716

GIT

718       Part of the git(1) suite
719

NOTES

721        1. torvalds@osdl.org
722           mailto:torvalds@osdl.org
723
724        2. git@vger.kernel.org
725           mailto:git@vger.kernel.org
726
727
728
729Git 1.7.4.4                       04/11/2011                 GIT-DIFF-FILES(1)
Impressum