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