blame.c: Properly initialize strbuf after calling, textconv_object()
[git/dscho.git] / Documentation / diff-generate-patch.txt
blob8f9a2412fd44c80f2bf8d63271e2897ebeb3ddeb
1 Generating patches with -p
2 --------------------------
4 When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
5 with a '-p' option, "git diff" without the '--raw' option, or
6 "git log" with the "-p" option, they
7 do not produce the output described above; instead they produce a
8 patch file.  You can customize the creation of such patches via the
9 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.
11 What the -p option produces is slightly different from the traditional
12 diff format.
14 1.   It is preceded with a "git diff" header, that looks like
15      this:
17        diff --git a/file1 b/file2
19 The `a/` and `b/` filenames are the same unless rename/copy is
20 involved.  Especially, even for a creation or a deletion,
21 `/dev/null` is _not_ used in place of `a/` or `b/` filenames.
23 When rename/copy is involved, `file1` and `file2` show the
24 name of the source file of the rename/copy and the name of
25 the file that rename/copy produces, respectively.
27 2.   It is followed by one or more extended header lines:
29        old mode <mode>
30        new mode <mode>
31        deleted file mode <mode>
32        new file mode <mode>
33        copy from <path>
34        copy to <path>
35        rename from <path>
36        rename to <path>
37        similarity index <number>
38        dissimilarity index <number>
39        index <hash>..<hash> <mode>
41 3.  TAB, LF, double quote and backslash characters in pathnames
42     are represented as `\t`, `\n`, `\"` and `\\`, respectively.
43     If there is need for such substitution then the whole
44     pathname is put in double quotes.
46 The similarity index is the percentage of unchanged lines, and
47 the dissimilarity index is the percentage of changed lines.  It
48 is a rounded down integer, followed by a percent sign.  The
49 similarity index value of 100% is thus reserved for two equal
50 files, while 100% dissimilarity means that no line from the old
51 file made it into the new one.
54 combined diff format
55 --------------------
57 "git-diff-tree", "git-diff-files" and "git-diff" can take '-c' or
58 '--cc' option to produce 'combined diff'.  For showing a merge commit
59 with "git log -p", this is the default format; you can force showing
60 full diff with the '-m' option.
61 A 'combined diff' format looks like this:
63 ------------
64 diff --combined describe.c
65 index fabadb8,cc95eb0..4866510
66 --- a/describe.c
67 +++ b/describe.c
68 @@@ -98,20 -98,12 +98,20 @@@
69         return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
70   }
72 - static void describe(char *arg)
73  -static void describe(struct commit *cmit, int last_one)
74 ++static void describe(char *arg, int last_one)
75   {
76  +      unsigned char sha1[20];
77  +      struct commit *cmit;
78         struct commit_list *list;
79         static int initialized = 0;
80         struct commit_name *n;
82  +      if (get_sha1(arg, sha1) < 0)
83  +              usage(describe_usage);
84  +      cmit = lookup_commit_reference(sha1);
85  +      if (!cmit)
86  +              usage(describe_usage);
87  +
88         if (!initialized) {
89                 initialized = 1;
90                 for_each_ref(get_name);
91 ------------
93 1.   It is preceded with a "git diff" header, that looks like
94      this (when '-c' option is used):
96        diff --combined file
98 or like this (when '--cc' option is used):
100        diff --cc file
102 2.   It is followed by one or more extended header lines
103      (this example shows a merge with two parents):
105        index <hash>,<hash>..<hash>
106        mode <mode>,<mode>..<mode>
107        new file mode <mode>
108        deleted file mode <mode>,<mode>
110 The `mode <mode>,<mode>..<mode>` line appears only if at least one of
111 the <mode> is different from the rest. Extended headers with
112 information about detected contents movement (renames and
113 copying detection) are designed to work with diff of two
114 <tree-ish> and are not used by combined diff format.
116 3.   It is followed by two-line from-file/to-file header
118        --- a/file
119        +++ b/file
121 Similar to two-line header for traditional 'unified' diff
122 format, `/dev/null` is used to signal created or deleted
123 files.
125 4.   Chunk header format is modified to prevent people from
126      accidentally feeding it to `patch -p1`. Combined diff format
127      was created for review of merge commit changes, and was not
128      meant for apply. The change is similar to the change in the
129      extended 'index' header:
131        @@@ <from-file-range> <from-file-range> <to-file-range> @@@
133 There are (number of parents + 1) `@` characters in the chunk
134 header for combined diff format.
136 Unlike the traditional 'unified' diff format, which shows two
137 files A and B with a single column that has `-` (minus --
138 appears in A but removed in B), `+` (plus -- missing in A but
139 added to B), or `" "` (space -- unchanged) prefix, this format
140 compares two or more files file1, file2,... with one file X, and
141 shows how X differs from each of fileN.  One column for each of
142 fileN is prepended to the output line to note how X's line is
143 different from it.
145 A `-` character in the column N means that the line appears in
146 fileN but it does not appear in the result.  A `+` character
147 in the column N means that the line appears in the result,
148 and fileN does not have that line (in other words, the line was
149 added, from the point of view of that parent).
151 In the above example output, the function signature was changed
152 from both files (hence two `-` removals from both file1 and
153 file2, plus `++` to mean one line that was added does not appear
154 in either file1 nor file2).  Also eight other lines are the same
155 from file1 but do not appear in file2 (hence prefixed with `{plus}`).
157 When shown by `git diff-tree -c`, it compares the parents of a
158 merge commit with the merge result (i.e. file1..fileN are the
159 parents).  When shown by `git diff-files -c`, it compares the
160 two unresolved merge parents with the working tree file
161 (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
162 "their version").