[PATCH 1/4] split core-git.txt and update
[git.git] / Documentation / diff-format.txt
1 The output format from "git-diff-cache", "git-diff-tree" and
2 "git-diff-files" is very similar.
3
4 These commands all compare two sets of things; what are
5 compared are different:
6
7 git-diff-cache <tree-ish>::
8         compares the <tree-ish> and the files on the filesystem.
9
10 git-diff-cache --cached <tree-ish>::
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
19 The following desription uses "old" and "new" to mean those
20 compared entities.
21
22 For files in old but not in new (i.e. removed):
23
24     -<mode> \t <type> \t <object> \t <path>
25
26 For files not in old but in new (i.e. added):
27
28     +<mode> \t <type> \t <object> \t <path>
29
30 For 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
35 filesystem and it is out of sync with the cache.  Example:
36
37   *100644->100644 blob    5be4a4.......->000000.......      file.c
38
39
40 Generating patches with -p
41 --------------------------
42
43 When "git-diff-cache", "git-diff-tree", or "git-diff-files" are run
44 with a '-p' option, they do not produce the output described above
45 instead they produce a patch file.
46
47 The patch generation can be customized at two levels.  This
48 customization also applies to "git-diff-tree-helper".
49
50 1. 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
65 2. 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 +
69 For 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 +
74 where:
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
82 The 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`
84 when a new file is added), or a temporary file (e.g. `old-file` in the
85 cache).  'GIT_EXTERNAL_DIFF' should not worry about unlinking the
86 temporary file --- it is removed when 'GIT_EXTERNAL_DIFF' exits.
87
88 For a path that is unmerged, 'GIT_EXTERNAL_DIFF' is called with 1
89 parameter, <path>.