Skip to content

Commit 9659df5

Browse files
Andreas Gruenbachergitster
authored andcommitted
Clarify and extend the "git diff" format documentation
Move the similarity and dissimilarity index header description closer to where those extended headers are described. Describe and/or clarify the format used for file modes, pathnames, and the index header. Document that all "old" files refer to the state before applying the *entire* output, and all "new" files refer to the state thereafter. Signed-off-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9fbd898 commit 9659df5

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

Documentation/diff-generate-patch.txt

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ patch file. You can customize the creation of such patches via the
99
GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.
1010

1111
What the -p option produces is slightly different from the traditional
12-
diff format.
12+
diff format:
1313

14-
1. It is preceded with a "git diff" header, that looks like
15-
this:
14+
1. It is preceded with a "git diff" header that looks like this:
1615

1716
diff --git a/file1 b/file2
1817
+
1918
The `a/` and `b/` filenames are the same unless rename/copy is
2019
involved. Especially, even for a creation or a deletion,
21-
`/dev/null` is _not_ used in place of `a/` or `b/` filenames.
20+
`/dev/null` is _not_ used in place of the `a/` or `b/` filenames.
2221
+
2322
When rename/copy is involved, `file1` and `file2` show the
2423
name of the source file of the rename/copy and the name of
@@ -37,18 +36,39 @@ the file that rename/copy produces, respectively.
3736
similarity index <number>
3837
dissimilarity index <number>
3938
index <hash>..<hash> <mode>
40-
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.
45-
39+
+
40+
File modes are printed as 6-digit octal numbers including the file type
41+
and file permission bits.
42+
+
43+
Path names in extended headers do not include the `a/` and `b/` prefixes.
44+
+
4645
The similarity index is the percentage of unchanged lines, and
4746
the dissimilarity index is the percentage of changed lines. It
4847
is a rounded down integer, followed by a percent sign. The
4948
similarity index value of 100% is thus reserved for two equal
5049
files, while 100% dissimilarity means that no line from the old
5150
file made it into the new one.
51+
+
52+
The index line includes the SHA-1 checksum before and after the change.
53+
The <mode> is included if the file mode does not change; otherwise,
54+
separate lines indicate the old and the new mode.
55+
56+
3. TAB, LF, double quote and backslash characters in pathnames
57+
are represented as `\t`, `\n`, `\"` and `\\`, respectively.
58+
If there is need for such substitution then the whole
59+
pathname is put in double quotes.
60+
61+
4. All the `file1` files in the output refer to files before the
62+
commit, and all the `file2` files refer to files after the commit.
63+
It is incorrect to apply each change to each file sequentially. For
64+
example, this patch will swap a and b:
65+
66+
diff --git a/a b/b
67+
rename from a
68+
rename to b
69+
diff --git a/b b/a
70+
rename from b
71+
rename to a
5272

5373

5474
combined diff format

0 commit comments

Comments
 (0)