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