[PATCH] The diff-raw format updates.
[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
20 An output line is formatted this way:
21
22   ':' <mode> ' ' <mode> ' ' <sha1> ' ' <sha1> I <path> I <path> L
23
24 By default, I and L are '\t' and '\n' respectively.  When '-z'
25 flag is in effect, both I and L are '\0'.
26
27 In each <mode>, <sha1> and <path> pair, left hand side describes
28 the left hand side of what is being compared (<tree-ish> in
29 git-diff-cache, <tree-ish-1> in git-diff-tree, cache contents in
30 git-diff-files).  Non-existence is shown by having 000000 in the
31 <mode> column.  That is, 000000 appears as the first <mode> for
32 newly created files, and as the second <mode> for deleted files.
33
34 Usually two <path> are the same.  When rename/copy detection is
35 used, however, an "create" and another "delete" records can be
36 merged into a single record that has two <path>, old name and
37 new name.
38
39 <sha1> is shown as all 0's if new is a file on the filesystem
40 and it is out of sync with the cache.  Example:
41
42   :100644 100644 5be4a4...... 000000......    file.c    file.c
43
44
45 Generating patches with -p
46 --------------------------
47
48 When "git-diff-cache", "git-diff-tree", or "git-diff-files" are run
49 with a '-p' option, they do not produce the output described above
50 instead they produce a patch file.
51
52 The patch generation can be customized at two levels.  This
53 customization also applies to "git-diff-helper".
54
55 1. When the environment variable 'GIT_EXTERNAL_DIFF' is not set,
56    these commands internally invoke "diff" like this:
57
58       diff -L a/<path> -L a/<path> -pu <old> <new>
59 +
60 For added files, `/dev/null` is used for <old>.  For removed
61 files, `/dev/null` is used for <new>
62 +
63 The "diff" formatting options can be customized via the
64 environment variable 'GIT_DIFF_OPTS'.  For example, if you
65 prefer context diff:
66
67       GIT_DIFF_OPTS=-c git-diff-cache -p $(cat .git/HEAD)
68
69
70 2. When the environment variable 'GIT_EXTERNAL_DIFF' is set, the
71    program named by it is called, instead of the diff invocation
72    described above.
73 +
74 For a path that is added, removed, or modified,
75 'GIT_EXTERNAL_DIFF' is called with 7 parameters:
76
77      path old-file old-hex old-mode new-file new-hex new-mode
78 +
79 where:
80
81      <old|new>-file:: are files GIT_EXTERNAL_DIFF can use to read the
82                       contents of <old|ne>,
83      <old|new>-hex:: are the 40-hexdigit SHA1 hashes,
84      <old|new>-mode:: are the octal representation of the file modes.
85
86
87 The file parameters can point at the user's working file
88 (e.g. `new-file` in "git-diff-files"), `/dev/null` (e.g. `old-file`
89 when a new file is added), or a temporary file (e.g. `old-file` in the
90 cache).  'GIT_EXTERNAL_DIFF' should not worry about unlinking the
91 temporary file --- it is removed when 'GIT_EXTERNAL_DIFF' exits.
92
93 For a path that is unmerged, 'GIT_EXTERNAL_DIFF' is called with 1
94 parameter, <path>.