index-pack: be careful after fixing up the header/footer
[git/dscho.git] / Documentation / diff-format.txt
blob400cbb3b1c120b93278472678ee7bdb87a74f95b
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 include::diff-generate-patch.txt[]
89 other diff formats
90 ------------------
92 The `--summary` option describes newly added, deleted, renamed and
93 copied files.  The `--stat` option adds diffstat(1) graph to the
94 output.  These options can be combined with other options, such as
95 `-p`, and are meant for human consumption.
97 When showing a change that involves a rename or a copy, `--stat` output
98 formats the pathnames compactly by combining common prefix and suffix of
99 the pathnames.  For example, a change that moves `arch/i386/Makefile` to
100 `arch/x86/Makefile` while modifying 4 lines will be shown like this:
102 ------------------------------------
103 arch/{i386 => x86}/Makefile    |   4 +--
104 ------------------------------------
106 The `--numstat` option gives the diffstat(1) information but is designed
107 for easier machine consumption.  An entry in `--numstat` output looks
108 like this:
110 ----------------------------------------
111 1       2       README
112 3       1       arch/{i386 => x86}/Makefile
113 ----------------------------------------
115 That is, from left to right:
117 . the number of added lines;
118 . a tab;
119 . the number of deleted lines;
120 . a tab;
121 . pathname (possibly with rename/copy information);
122 . a newline.
124 When `-z` output option is in effect, the output is formatted this way:
126 ----------------------------------------
127 1       2       README NUL
128 3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
129 ----------------------------------------
131 That is:
133 . the number of added lines;
134 . a tab;
135 . the number of deleted lines;
136 . a tab;
137 . a NUL (only exists if renamed/copied);
138 . pathname in preimage;
139 . a NUL (only exists if renamed/copied);
140 . pathname in postimage (only exists if renamed/copied);
141 . a NUL.
143 The extra `NUL` before the preimage path in renamed case is to allow
144 scripts that read the output to tell if the current record being read is
145 a single-path record or a rename/copy record without reading ahead.
146 After reading added and deleted lines, reading up to `NUL` would yield
147 the pathname, but if that is `NUL`, the record will show two paths.