Contents|Index|Previous|Next

Unified Format

The unified output format is a variation on the context format that is more compact because it omits redundant context lines. To select this output format, use the '-U lines', '--unified[=lines]', or '-u' option. The argument linesis the number of lines of context to show. When it is not given, it defaults to three. At present, only GNU diff can produce this format and only GNU patch can automatically apply diffs in this format. For proper operation, patch typically needs at least two lines of context.

Detailed Description of Unified Format

The unified output format starts with a two-line header, which looks like this:

--- from-file from-file-modification-time
+++ to-file to-file-modification-time

You can change the header's content with the '-L label' or '--label=label' option; see Showing Alternate File Names and Showing Which Sections Differences Are in. Next come one or more hunks of differences; each hunk shows one area where the files differ. Unified format hunks look like the following

@@ from-file-range to-file-range @@
line-from-either-file
line-from-either-file...

The lines common to both files begin with a space character. The lines that actually differ between the two files have one of the following indicator characters in the left column:

'+' A line was added here to the first file.

'-' A line was removed here from the first file.

An Example of Unified Format

Here is the output of the command, 'diff -u lao tzu' (see Two Sample Input Files for the complete contents of the two files):

--- lao Sat Jan 26 23:30:39 1991
+++ tzu Sat Jan 26 23:30:50 1991
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
@@ -9,3 +8,6 @@
The two are the same,
But after they are produced,
they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!