f78 Context Format Contents|Index|Previous|Next

Context Format

The context output format shows several lines of context around the lines that differ. It is the standard format for distributing updates to source code.

To select this output format, use the '-C lines', '--context[=lines]', or '-c' option. The argument lines that some of these options take is the number of lines of context to show. If you do not specify lines,it defaults to three. For proper operation, patch typically needs at least two lines of context.

Detailed Description of Context Format

The context output format starts with a two-line header, which looks like the following.

*** 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. Next come one or more hunks of differences; each hunk shows one area where the files differ. Context format hunks look like the following.

***************
*** from-file-line-range ****
   from-file-line
   from-file-line ...
--- to-file-line-range ----
   to-file-line
   to-file-line...

The lines of context around the lines that differ start with two space characters. The lines that differ between the two files start with one of the following indicator characters, followed by a space character:

'!'
A line that is part of a group of one or more lines that changed between the two files. There is a corresponding group of lines marked with '!' in the part of this hunk for the other file.

'+'
An "inserted" line in the second file that corresponds to nothing in the first file.

'-'
A "deleted" line in the first file that corresponds to nothing in the second file.

If all of the changes in a hunk are insertions, the lines of from-file are omitted. If all of the changes are deletions, the lines of to-file are omitted.

An Example of Context Format

The following is the output of 'diff -c lao tzu' (see Two Sample Input Files for the complete contents of the two files). Notice that up to three lines that are not different are shown around each line that is different; they are the context lines. Also notice that the first two hunks have run together, because their contents overlap.

*** lao Sat Jan 26 23:30:39 1991
--- tzu Sat Jan 26 23:30:50 1991
***************
*** 1,7 ****
- 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.
   Therefore let there always be non-being,
    so we may see their subtlety,
   And let there always be being,
--- 1,6 ----
The Nameless is the origin of Heaven and Earth;
! 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,11 ****
--- 8,13 ----
   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!

An Example of Context Format with Less Context

Here is the output of 'diff --context=1 lao tzu' (see Two Sample Input Files for the complete contents of the two files). Notice that at most one context line is reported here.

*** lao Sat Jan 26 23:30:39 1991
--- tzu Sat Jan 26 23:30:50 1991
***************
*** 1,5 ****
- 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.
  Therefore let there always be non-being,
--- 1,4 ----
  The Nameless is the origin of Heaven and Earth;
! The named is the mother of all things.
!
  Therefore let there always be non-being,
***************
*** 11 ****
--- 10,13 ----
    they have different names.
+ They both may be called deep and profound.
+ Deeper and more profound,
+ The door of all subtleties!

0