Documentation / diff-format.txton commit [PATCH 2/2] core-git documentation update (03ea280)
   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
  19The following desription uses "old" and "new" to mean those
  20compared entities.
  21
  22For files in old but not in new (i.e. removed):
  23
  24    -<mode> \t <type> \t <object> \t <path>
  25
  26For files not in old but in new (i.e. added):
  27
  28    +<mode> \t <type> \t <object> \t <path>
  29
  30For files that differ:
  31
  32    *<old-mode>-><new-mode> \t <type> \t <old-sha1>-><new-sha1> \t <path>
  33
  34<new-sha1> is shown as all 0's if new is a file on the
  35filesystem and it is out of sync with the cache.  Example:
  36
  37  *100644->100644 blob    5be4a4.......->000000.......      file.c
  38
  39
  40Generating patches with -p
  41--------------------------
  42
  43When "git-diff-cache", "git-diff-tree", or "git-diff-files" are run
  44with a '-p' option, they do not produce the output described above
  45instead they produce a patch file.
  46
  47The patch generation can be customized at two levels.  This
  48customization also applies to "git-diff-tree-helper".
  49
  501. When the environment variable 'GIT_EXTERNAL_DIFF' is not set,
  51   these commands internally invoke "diff" like this:
  52
  53      diff -L a/<path> -L a/<path> -pu <old> <new>
  54
  55   For added files, `/dev/null` is used for <old>.  For removed
  56   files, `/dev/null` is used for <new>
  57
  58   The "diff" formatting options can be customized via the
  59   environment variable 'GIT_DIFF_OPTS'.  For example, if you
  60   prefer context diff:
  61
  62          GIT_DIFF_OPTS=-c git-diff-cache -p $(cat .git/HEAD)
  63
  64
  652. When the environment variable 'GIT_EXTERNAL_DIFF' is set, the
  66   program named by it is called, instead of the diff invocation
  67   described above.
  68+
  69For a path that is added, removed, or modified,
  70'GIT_EXTERNAL_DIFF' is called with 7 parameters:
  71
  72     path old-file old-hex old-mode new-file new-hex new-mode
  73+
  74where:
  75
  76     <old|new>-file:: are files GIT_EXTERNAL_DIFF can use to read the
  77                      contents of <old|ne>,
  78     <old|new>-hex:: are the 40-hexdigit SHA1 hashes,
  79     <old|new>-mode:: are the octal representation of the file modes.
  80
  81+ 
  82The file parameters can point at the user's working file
  83(e.g. `new-file` in "git-diff-files"), `/dev/null` (e.g. `old-file`
  84when a new file is added), or a temporary file (e.g. `old-file` in the
  85cache).  'GIT_EXTERNAL_DIFF' should not worry about unlinking the
  86temporary file --- it is removed when 'GIT_EXTERNAL_DIFF' exits.
  87
  88For a path that is unmerged, 'GIT_EXTERNAL_DIFF' is called with 1
  89parameter, <path>.