]>
Commit | Line | Data |
---|---|---|
215a7ad1 | 1 | The output format from "git-diff-index", "git-diff-tree" and |
8db9307c | 2 | "git-diff-files" are very similar. |
03ea2802 DG |
3 | |
4 | These commands all compare two sets of things; what are | |
5 | compared are different: | |
6 | ||
215a7ad1 | 7 | git-diff-index <tree-ish>:: |
03ea2802 DG |
8 | compares the <tree-ish> and the files on the filesystem. |
9 | ||
215a7ad1 | 10 | git-diff-index --cached <tree-ish>:: |
03ea2802 DG |
11 | compares the <tree-ish> and the cache. |
12 | ||
13 | git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]:: | |
14 | compares the trees named by the two arguments. | |
15 | ||
16 | git-diff-files [<pattern>...]:: | |
17 | compares the cache and the files on the filesystem. | |
18 | ||
03ea2802 | 19 | |
81e50eab | 20 | An output line is formatted this way: |
03ea2802 | 21 | |
8db9307c | 22 | ------------------------------------------------ |
b6d8f309 JH |
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 | |
8db9307c | 26 | create :000000 100644 0000000... 1234567... A file4 |
b6d8f309 JH |
27 | delete :100644 000000 1234567... 0000000... D file5 |
28 | unmerged :000000 000000 0000000... 0000000... U file6 | |
8db9307c | 29 | ------------------------------------------------ |
b6d8f309 JH |
30 | |
31 | That is, from the left to the right: | |
32 | ||
8db9307c JH |
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. | |
03ea2802 | 48 | |
81e50eab | 49 | <sha1> is shown as all 0's if new is a file on the filesystem |
8db9307c | 50 | and it is out of sync with the cache. |
03ea2802 | 51 | |
8db9307c JH |
52 | Example: |
53 | ||
54 | ------------------------------------------------ | |
55 | :100644 100644 5be4a4...... 000000...... M file.c | |
56 | ------------------------------------------------ | |
03ea2802 DG |
57 | |
58 | Generating patches with -p | |
59 | -------------------------- | |
60 | ||
215a7ad1 | 61 | When "git-diff-index", "git-diff-tree", or "git-diff-files" are run |
1a93a766 | 62 | with a '-p' option, they do not produce the output described above; |
03ea2802 DG |
63 | instead they produce a patch file. |
64 | ||
65 | The patch generation can be customized at two levels. This | |
99665af5 | 66 | customization also applies to "git-diff-helper". |
03ea2802 DG |
67 | |
68 | 1. When the environment variable 'GIT_EXTERNAL_DIFF' is not set, | |
69 | these commands internally invoke "diff" like this: | |
70 | ||
2c6e4771 | 71 | diff -L a/<path> -L b/<path> -pu <old> <new> |
2cf565c5 DG |
72 | + |
73 | For added files, `/dev/null` is used for <old>. For removed | |
74 | files, `/dev/null` is used for <new> | |
75 | + | |
76 | The "diff" formatting options can be customized via the | |
77 | environment variable 'GIT_DIFF_OPTS'. For example, if you | |
78 | prefer context diff: | |
03ea2802 | 79 | |
215a7ad1 | 80 | GIT_DIFF_OPTS=-c git-diff-index -p $(cat .git/HEAD) |
03ea2802 DG |
81 | |
82 | ||
83 | 2. When the environment variable 'GIT_EXTERNAL_DIFF' is set, the | |
84 | program named by it is called, instead of the diff invocation | |
85 | described above. | |
86 | + | |
87 | For a path that is added, removed, or modified, | |
88 | 'GIT_EXTERNAL_DIFF' is called with 7 parameters: | |
89 | ||
90 | path old-file old-hex old-mode new-file new-hex new-mode | |
91 | + | |
92 | where: | |
93 | ||
94 | <old|new>-file:: are files GIT_EXTERNAL_DIFF can use to read the | |
95 | contents of <old|ne>, | |
96 | <old|new>-hex:: are the 40-hexdigit SHA1 hashes, | |
97 | <old|new>-mode:: are the octal representation of the file modes. | |
98 | ||
99 | + | |
100 | The file parameters can point at the user's working file | |
101 | (e.g. `new-file` in "git-diff-files"), `/dev/null` (e.g. `old-file` | |
102 | when a new file is added), or a temporary file (e.g. `old-file` in the | |
103 | cache). 'GIT_EXTERNAL_DIFF' should not worry about unlinking the | |
104 | temporary file --- it is removed when 'GIT_EXTERNAL_DIFF' exits. | |
105 | ||
106 | For a path that is unmerged, 'GIT_EXTERNAL_DIFF' is called with 1 | |
107 | parameter, <path>. | |
1a93a766 JH |
108 | |
109 | ||
2c6e4771 | 110 | Git specific extension to diff format |
1a93a766 JH |
111 | ------------------------------------- |
112 | ||
113 | What -p option produces is slightly different from the | |
114 | traditional diff format. | |
115 | ||
8db9307c | 116 | 1. It is preceeded with a "git diff" header, that looks like |
1a93a766 JH |
117 | this: |
118 | ||
119 | diff --git a/file1 b/file2 | |
8db9307c JH |
120 | + |
121 | The `a/` and `b/` filenames are the same unless rename/copy is | |
122 | involved. Especially, even for a creation or a deletion, | |
123 | `/dev/null` is _not_ used in place of `a/` or `b/` filenames. | |
124 | + | |
125 | When rename/copy is involved, `file1` and `file2` shows the | |
126 | name of the source file of the rename/copy and the name of | |
127 | the file that rename/copy produces, respectively. | |
1a93a766 | 128 | |
8db9307c | 129 | 2. It is followed by extended header lines that are one or |
1a93a766 JH |
130 | more of: |
131 | ||
132 | old mode <mode> | |
133 | new mode <mode> | |
134 | deleted file mode <mode> | |
135 | new file mode <mode> | |
136 | copy from <path> | |
137 | copy to <path> | |
138 | rename from <path> | |
139 | rename to <path> | |
140 | similarity index <number> | |
141 | dissimilarity index <number> |