Home Explore Blog CI



git

2nd chunk of `Documentation/diff-generate-patch.adoc`
bdad3f1d4f7a4f16777a48abc5ec2ff4e5accd439e58c73c00000001000008fc

5.  Hunk headers mention the name of the function to which the hunk
    applies.  See "Defining a custom hunk-header" in
    linkgit:gitattributes[5] for details of how to tailor this to
    specific languages.


Combined diff format
--------------------

Any diff-generating command can take the `-c` or `--cc` option to
produce a 'combined diff' when showing a merge. This is the default
format when showing merges with linkgit:git-diff[1] or
linkgit:git-show[1]. Note also that you can give suitable
`--diff-merges` option to any of these commands to force generation of
diffs in a specific format.

A "combined diff" format looks like this:

------------
diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
	return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
  }

- static void describe(char *arg)
 -static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
  {
 +	unsigned char sha1[20];
 +	struct commit *cmit;
	struct commit_list *list;
	static int initialized = 0;
	struct commit_name *n;

 +	if (get_sha1(arg, sha1) < 0)
 +		usage(describe_usage);
 +	cmit = lookup_commit_reference(sha1);
 +	if (!cmit)
 +		usage(describe_usage);
 +
	if (!initialized) {
		initialized = 1;
		for_each_ref(get_name);
------------

1.   It is preceded by a "git diff" header, that looks like
     this (when the `-c` option is used):

       diff --combined file
+
or like this (when the `--cc` option is used):

       diff --cc file

2.   It is followed by one or more extended header lines
     (this example shows a merge with two parents):
+
[synopsis]
index <hash>,<hash>..<hash>
mode <mode>,<mode>`..`<mode>
new file mode <mode>
deleted file mode <mode>,<mode>
+
The `mode <mode>,<mode>..<mode>` line appears only if at least one of
the <mode> is different from the rest. Extended headers with
information about detected content movement (renames and
copying detection) are designed to work with the diff of two
_<tree-ish>_ and are not used by combined diff format.

3.   It is followed by a two-line from-file/to-file header:

       --- a/file
       +++ b/file
+
Similar to the two-line header for the traditional 'unified' diff
format, `/dev/null` is used to signal created

Title: Combined Diff Format in Git
Summary
This section describes the combined diff format used by Git to show merges, including the format of the diff header, extended header lines, and the two-line from-file/to-file header, as well as how the format differs from the traditional unified diff format.