Documentation / diff-format.txton commit Finally implement "git log --follow" (750f7b6)
   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 index.
  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 index 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 index.
  51
  52Example:
  53
  54------------------------------------------------
  55:100644 100644 5be4a4...... 000000...... M file.c
  56------------------------------------------------
  57
  58When `-z` option is not used, TAB, LF, and backslash characters
  59in pathnames are represented as `\t`, `\n`, and `\\`,
  60respectively.
  61
  62diff format for merges
  63----------------------
  64
  65"git-diff-tree" and "git-diff-files" can take '-c' or '--cc' option
  66to generate diff output also for merge commits.  The output differs
  67from the format described above in the following way:
  68
  69. there is a colon for each parent
  70. there are more "src" modes and "src" sha1
  71. status is concatenated status characters for each parent
  72. no optional "score" number
  73. single path, only for "dst"
  74
  75Example:
  76
  77------------------------------------------------
  78::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c
  79------------------------------------------------
  80
  81Note that 'combined diff' lists only files which were modified from
  82all parents.
  83
  84
  85Generating patches with -p
  86--------------------------
  87
  88When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
  89with a '-p' option, they do not produce the output described above;
  90instead they produce a patch file.  You can customize the creation
  91of such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
  92environment variables.
  93
  94What the -p option produces is slightly different from the traditional
  95diff format.
  96
  971.   It is preceded with a "git diff" header, that looks like
  98     this:
  99
 100       diff --git a/file1 b/file2
 101+
 102The `a/` and `b/` filenames are the same unless rename/copy is
 103involved.  Especially, even for a creation or a deletion,
 104`/dev/null` is _not_ used in place of `a/` or `b/` filenames.
 105+
 106When rename/copy is involved, `file1` and `file2` show the
 107name of the source file of the rename/copy and the name of
 108the file that rename/copy produces, respectively.
 109
 1102.   It is followed by one or more extended header lines:
 111
 112       old mode <mode>
 113       new mode <mode>
 114       deleted file mode <mode>
 115       new file mode <mode>
 116       copy from <path>
 117       copy to <path>
 118       rename from <path>
 119       rename to <path>
 120       similarity index <number>
 121       dissimilarity index <number>
 122       index <hash>..<hash> <mode>
 123
 1243.  TAB, LF, double quote and backslash characters in pathnames
 125    are represented as `\t`, `\n`, `\"` and `\\`, respectively.
 126    If there is need for such substitution then the whole
 127    pathname is put in double quotes.
 128
 129
 130combined diff format
 131--------------------
 132
 133git-diff-tree and git-diff-files can take '-c' or '--cc' option
 134to produce 'combined diff', which looks like this:
 135
 136------------
 137diff --combined describe.c
 138index fabadb8,cc95eb0..4866510
 139--- a/describe.c
 140+++ b/describe.c
 141@@@ -98,20 -98,12 +98,20 @@@
 142        return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
 143  }
 144
 145- static void describe(char *arg)
 146 -static void describe(struct commit *cmit, int last_one)
 147++static void describe(char *arg, int last_one)
 148  {
 149 +      unsigned char sha1[20];
 150 +      struct commit *cmit;
 151        struct commit_list *list;
 152        static int initialized = 0;
 153        struct commit_name *n;
 154
 155 +      if (get_sha1(arg, sha1) < 0)
 156 +              usage(describe_usage);
 157 +      cmit = lookup_commit_reference(sha1);
 158 +      if (!cmit)
 159 +              usage(describe_usage);
 160 +
 161        if (!initialized) {
 162                initialized = 1;
 163                for_each_ref(get_name);
 164------------
 165
 1661.   It is preceded with a "git diff" header, that looks like
 167     this (when '-c' option is used):
 168
 169       diff --combined file
 170+
 171or like this (when '--cc' option is used):
 172
 173       diff --c file
 174
 1752.   It is followed by one or more extended header lines
 176     (this example shows a merge with two parents):
 177
 178       index <hash>,<hash>..<hash>
 179       mode <mode>,<mode>..<mode>
 180       new file mode <mode>
 181       deleted file mode <mode>,<mode>
 182+
 183The `mode <mode>,<mode>..<mode>` line appears only if at least one of
 184the <mode> is different from the rest. Extended headers with
 185information about detected contents movement (renames and
 186copying detection) are designed to work with diff of two
 187<tree-ish> and are not used by combined diff format.
 188
 1893.   It is followed by two-line from-file/to-file header
 190
 191       --- a/file
 192       +++ b/file
 193+
 194Similar to two-line header for traditional 'unified' diff
 195format, `/dev/null` is used to signal created or deleted
 196files.
 197
 1984.   Chunk header format is modified to prevent people from
 199     accidentally feeding it to `patch -p1`. Combined diff format
 200     was created for review of merge commit changes, and was not
 201     meant for apply. The change is similar to the change in the
 202     extended 'index' header:
 203
 204       @@@ <from-file-range> <from-file-range> <to-file-range> @@@
 205+
 206There are (number of parents + 1) `@` characters in the chunk
 207header for combined diff format.
 208
 209Unlike the traditional 'unified' diff format, which shows two
 210files A and B with a single column that has `-` (minus --
 211appears in A but removed in B), `+` (plus -- missing in A but
 212added to B), or `" "` (space -- unchanged) prefix, this format
 213compares two or more files file1, file2,... with one file X, and
 214shows how X differs from each of fileN.  One column for each of
 215fileN is prepended to the output line to note how X's line is
 216different from it.
 217
 218A `-` character in the column N means that the line appears in
 219fileN but it does not appear in the result.  A `+` character
 220in the column N means that the line appears in the last file,
 221and fileN does not have that line (in other words, the line was
 222added, from the point of view of that parent).
 223
 224In the above example output, the function signature was changed
 225from both files (hence two `-` removals from both file1 and
 226file2, plus `++` to mean one line that was added does not appear
 227in either file1 nor file2).  Also two other lines are the same
 228from file1 but do not appear in file2 (hence prefixed with ` +`).
 229
 230When shown by `git diff-tree -c`, it compares the parents of a
 231merge commit with the merge result (i.e. file1..fileN are the
 232parents).  When shown by `git diff-files -c`, it compares the
 233two unresolved merge parents with the working tree file
 234(i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
 235"their version").