source: trunk/essentials/sys-apps/diffutils/doc/diff.info@ 3468

Last change on this file since 3468 was 2556, checked in by bird, 20 years ago

diffutils 2.8.1

File size: 197.9 KB
Line 
1This is diff.info, produced by makeinfo version 4.2 from diff.texi.
2
3This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
4documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
5showing the differences between files and the GNU `patch' command for
6using their output to update files.
7
8 Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
9Foundation, Inc.
10
11 Permission is granted to copy, distribute and/or modify this
12 document under the terms of the GNU Free Documentation License,
13 Version 1.1 or any later version published by the Free Software
14 Foundation; with no Invariant Sections, with the Front-Cover texts
15 being "A GNU Manual," and with the Back-Cover Texts as in (a)
16 below. A copy of the license is included in the section entitled
17 "GNU Free Documentation License."
18
19 (a) The FSF's Back-Cover Text is: "You have freedom to copy and
20 modify this GNU Manual, like GNU software. Copies published by
21 the Free Software Foundation raise funds for GNU development."
22
23INFO-DIR-SECTION Individual utilities
24START-INFO-DIR-ENTRY
25* cmp: (diff)Invoking cmp. Compare 2 files byte by byte.
26* diff: (diff)Invoking diff. Compare 2 files line by line.
27* diff3: (diff)Invoking diff3. Compare 3 files line by line.
28* patch: (diff)Invoking patch. Apply a patch to a file.
29* sdiff: (diff)Invoking sdiff. Merge 2 files side-by-side.
30END-INFO-DIR-ENTRY
31
32INFO-DIR-SECTION GNU packages
33START-INFO-DIR-ENTRY
34* Diff: (diff). Comparing and merging files.
35END-INFO-DIR-ENTRY
36
37
38File: diff.info, Node: Top, Next: Overview, Up: (dir)
39
40Comparing and Merging Files
41***************************
42
43This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
44documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
45showing the differences between files and the GNU `patch' command for
46using their output to update files.
47
48 Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
49Foundation, Inc.
50
51 Permission is granted to copy, distribute and/or modify this
52 document under the terms of the GNU Free Documentation License,
53 Version 1.1 or any later version published by the Free Software
54 Foundation; with no Invariant Sections, with the Front-Cover texts
55 being "A GNU Manual," and with the Back-Cover Texts as in (a)
56 below. A copy of the license is included in the section entitled
57 "GNU Free Documentation License."
58
59 (a) The FSF's Back-Cover Text is: "You have freedom to copy and
60 modify this GNU Manual, like GNU software. Copies published by
61 the Free Software Foundation raise funds for GNU development."
62
63* Menu:
64
65* Overview:: Preliminary information.
66* Comparison:: What file comparison means.
67
68* Output Formats:: Formats for two-way difference reports.
69* Incomplete Lines:: Lines that lack trailing newlines.
70* Comparing Directories:: Comparing files and directories.
71* Adjusting Output:: Making `diff' output prettier.
72* diff Performance:: Making `diff' smarter or faster.
73
74* Comparing Three Files:: Formats for three-way difference reports.
75* diff3 Merging:: Merging from a common ancestor.
76
77* Interactive Merging:: Interactive merging with `sdiff'.
78
79* Merging with patch:: Using `patch' to change old files into new ones.
80* Making Patches:: Tips for making and using patch distributions.
81
82* Invoking cmp:: Compare two files byte by byte.
83* Invoking diff:: Compare two files line by line.
84* Invoking diff3:: Compare three files line by line.
85* Invoking patch:: Apply a diff file to an original.
86* Invoking sdiff:: Side-by-side merge of file differences.
87
88* Standards conformance:: Conformance to the POSIX standard.
89* Projects:: If you've found a bug or other shortcoming.
90
91* Copying This Manual:: How to make copies of this manual.
92* Index:: Index.
93
94
95File: diff.info, Node: Overview, Next: Comparison, Prev: Top, Up: Top
96
97Overview
98********
99
100 Computer users often find occasion to ask how two files differ.
101Perhaps one file is a newer version of the other file. Or maybe the
102two files started out as identical copies but were changed by different
103people.
104
105 You can use the `diff' command to show differences between two
106files, or each corresponding file in two directories. `diff' outputs
107differences between files line by line in any of several formats,
108selectable by command line options. This set of differences is often
109called a "diff" or "patch". For files that are identical, `diff'
110normally produces no output; for binary (non-text) files, `diff'
111normally reports only that they are different.
112
113 You can use the `cmp' command to show the byte and line numbers
114where two files differ. `cmp' can also show all the bytes that differ
115between the two files, side by side. A way to compare two files
116character by character is the Emacs command `M-x compare-windows'.
117*Note Other Window: (emacs)Other Window, for more information on that
118command.
119
120 You can use the `diff3' command to show differences among three
121files. When two people have made independent changes to a common
122original, `diff3' can report the differences between the original and
123the two changed versions, and can produce a merged file that contains
124both persons' changes together with warnings about conflicts.
125
126 You can use the `sdiff' command to merge two files interactively.
127
128 You can use the set of differences produced by `diff' to distribute
129updates to text files (such as program source code) to other people.
130This method is especially useful when the differences are small compared
131to the complete files. Given `diff' output, you can use the `patch'
132program to update, or "patch", a copy of the file. If you think of
133`diff' as subtracting one file from another to produce their
134difference, you can think of `patch' as adding the difference to one
135file to reproduce the other.
136
137 This manual first concentrates on making diffs, and later shows how
138to use diffs to update files.
139
140 GNU `diff' was written by Paul Eggert, Mike Haertel, David Hayes,
141Richard Stallman, and Len Tower. Wayne Davison designed and
142implemented the unified output format. The basic algorithm is described
143in "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
144`Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A File
145Comparison Program", Webb Miller and Eugene W. Myers,
146`Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
147The algorithm was independently discovered as described in "Algorithms
148for Approximate String Matching", E. Ukkonen, `Information and Control'
149Vol. 64, 1985, pp. 100-118.
150
151 GNU `diff3' was written by Randy Smith. GNU `sdiff' was written by
152Thomas Lord. GNU `cmp' was written by Torbjorn Granlund and David
153MacKenzie.
154
155 `patch' was written mainly by Larry Wall and Paul Eggert; several
156GNU enhancements were contributed by Wayne Davison and David MacKenzie.
157Parts of this manual are adapted from a manual page written by Larry
158Wall, with his permission.
159
160
161File: diff.info, Node: Comparison, Next: Output Formats, Prev: Overview, Up: Top
162
163What Comparison Means
164*********************
165
166 There are several ways to think about the differences between two
167files. One way to think of the differences is as a series of lines
168that were deleted from, inserted in, or changed in one file to produce
169the other file. `diff' compares two files line by line, finds groups of
170lines that differ, and reports each group of differing lines. It can
171report the differing lines in several formats, which have different
172purposes.
173
174 GNU `diff' can show whether files are different without detailing
175the differences. It also provides ways to suppress certain kinds of
176differences that are not important to you. Most commonly, such
177differences are changes in the amount of white space between words or
178lines. `diff' also provides ways to suppress differences in alphabetic
179case or in lines that match a regular expression that you provide.
180These options can accumulate; for example, you can ignore changes in
181both white space and alphabetic case.
182
183 Another way to think of the differences between two files is as a
184sequence of pairs of bytes that can be either identical or different.
185`cmp' reports the differences between two files byte by byte, instead
186of line by line. As a result, it is often more useful than `diff' for
187comparing binary files. For text files, `cmp' is useful mainly when
188you want to know only whether two files are identical, or whether one
189file is a prefix of the other.
190
191 To illustrate the effect that considering changes byte by byte can
192have compared with considering them line by line, think of what happens
193if a single newline character is added to the beginning of a file. If
194that file is then compared with an otherwise identical file that lacks
195the newline at the beginning, `diff' will report that a blank line has
196been added to the file, while `cmp' will report that almost every byte
197of the two files differs.
198
199 `diff3' normally compares three input files line by line, finds
200groups of lines that differ, and reports each group of differing lines.
201Its output is designed to make it easy to inspect two different sets of
202changes to the same file.
203
204* Menu:
205
206* Hunks:: Groups of differing lines.
207* White Space:: Suppressing differences in white space.
208* Blank Lines:: Suppressing differences in blank lines.
209* Case Folding:: Suppressing differences in alphabetic case.
210* Specified Folding:: Suppressing differences that match regular expressions.
211* Brief:: Summarizing which files are different.
212* Binary:: Comparing binary files or forcing text comparisons.
213
214
215File: diff.info, Node: Hunks, Next: White Space, Up: Comparison
216
217Hunks
218=====
219
220 When comparing two files, `diff' finds sequences of lines common to
221both files, interspersed with groups of differing lines called "hunks".
222Comparing two identical files yields one sequence of common lines and
223no hunks, because no lines differ. Comparing two entirely different
224files yields no common lines and one large hunk that contains all lines
225of both files. In general, there are many ways to match up lines
226between two given files. `diff' tries to minimize the total hunk size
227by finding large sequences of common lines interspersed with small
228hunks of differing lines.
229
230 For example, suppose the file `F' contains the three lines `a', `b',
231`c', and the file `G' contains the same three lines in reverse order
232`c', `b', `a'. If `diff' finds the line `c' as common, then the command
233`diff F G' produces this output:
234
235 1,2d0
236 < a
237 < b
238 3a2,3
239 > b
240 > a
241
242But if `diff' notices the common line `b' instead, it produces this
243output:
244
245 1c1
246 < a
247 ---
248 > c
249 3c3
250 < c
251 ---
252 > a
253
254It is also possible to find `a' as the common line. `diff' does not
255always find an optimal matching between the files; it takes shortcuts
256to run faster. But its output is usually close to the shortest
257possible. You can adjust this tradeoff with the `--minimal' option
258(*note diff Performance::).
259
260
261File: diff.info, Node: White Space, Next: Blank Lines, Prev: Hunks, Up: Comparison
262
263Suppressing Differences in Blank and Tab Spacing
264================================================
265
266 The `-E' and `--ignore-tab-expansion' options ignore the distinction
267between tabs and spaces on input. A tab is considered to be equivalent
268to the number of spaces to the next tab stop. `diff' assumes that tab
269stops are set every 8 print columns.
270
271 The `-b' and `--ignore-space-change' options are stronger. They
272ignore white space at line end, and consider all other sequences of one
273or more white space characters to be equivalent. With these options,
274`diff' considers the following two lines to be equivalent, where `$'
275denotes the line end:
276
277 Here lyeth muche rychnesse in lytell space. -- John Heywood$
278 Here lyeth muche rychnesse in lytell space. -- John Heywood $
279
280 The `-w' and `--ignore-all-space' options are stronger still. They
281ignore difference even if one line has white space where the other line
282has none. "White space" characters include tab, newline, vertical tab,
283form feed, carriage return, and space; some locales may define
284additional characters to be white space. With these options, `diff'
285considers the following two lines to be equivalent, where `$' denotes
286the line end and `^M' denotes a carriage return:
287
288 Here lyeth muche rychnesse in lytell space.-- John Heywood$
289 He relyeth much erychnes seinly tells pace. --John Heywood ^M$
290
291
292File: diff.info, Node: Blank Lines, Next: Case Folding, Prev: White Space, Up: Comparison
293
294Suppressing Differences in Blank Lines
295======================================
296
297 The `-B' and `--ignore-blank-lines' options ignore insertions or
298deletions of blank lines. These options affect only lines that are
299completely empty; they do not affect lines that look empty but contain
300space or tab characters. With these options, for example, a file
301containing
302 1. A point is that which has no part.
303
304 2. A line is breadthless length.
305 -- Euclid, The Elements, I
306
307is considered identical to a file containing
308 1. A point is that which has no part.
309 2. A line is breadthless length.
310
311
312 -- Euclid, The Elements, I
313
314
315File: diff.info, Node: Case Folding, Next: Specified Folding, Prev: Blank Lines, Up: Comparison
316
317Suppressing Case Differences
318============================
319
320 GNU `diff' can treat lower case letters as equivalent to their upper
321case counterparts, so that, for example, it considers `Funky Stuff',
322`funky STUFF', and `fUNKy stuFf' to all be the same. To request this,
323use the `-i' or `--ignore-case' option.
324
325
326File: diff.info, Node: Specified Folding, Next: Brief, Prev: Case Folding, Up: Comparison
327
328Suppressing Lines Matching a Regular Expression
329===============================================
330
331 To ignore insertions and deletions of lines that match a
332`grep'-style regular expression, use the `-I REGEXP' or
333`--ignore-matching-lines=REGEXP' option. You should escape regular
334expressions that contain shell metacharacters to prevent the shell from
335expanding them. For example, `diff -I '^[[:digit:]]'' ignores all
336changes to lines beginning with a digit.
337
338 However, `-I' only ignores the insertion or deletion of lines that
339contain the regular expression if every changed line in the hunk--every
340insertion and every deletion--matches the regular expression. In other
341words, for each nonignorable change, `diff' prints the complete set of
342changes in its vicinity, including the ignorable ones.
343
344 You can specify more than one regular expression for lines to ignore
345by using more than one `-I' option. `diff' tries to match each line
346against each regular expression.
347
348
349File: diff.info, Node: Brief, Next: Binary, Prev: Specified Folding, Up: Comparison
350
351Summarizing Which Files Differ
352==============================
353
354 When you only want to find out whether files are different, and you
355don't care what the differences are, you can use the summary output
356format. In this format, instead of showing the differences between the
357files, `diff' simply reports whether files differ. The `-q' and
358`--brief' options select this output format.
359
360 This format is especially useful when comparing the contents of two
361directories. It is also much faster than doing the normal line by line
362comparisons, because `diff' can stop analyzing the files as soon as it
363knows that there are any differences.
364
365 You can also get a brief indication of whether two files differ by
366using `cmp'. For files that are identical, `cmp' produces no output.
367When the files differ, by default, `cmp' outputs the byte and line
368number where the first difference occurs. You can use the `-s' option
369to suppress that information, so that `cmp' produces no output and
370reports whether the files differ using only its exit status (*note
371Invoking cmp::).
372
373 Unlike `diff', `cmp' cannot compare directories; it can only compare
374two files.
375
376
377File: diff.info, Node: Binary, Prev: Brief, Up: Comparison
378
379Binary Files and Forcing Text Comparisons
380=========================================
381
382 If `diff' thinks that either of the two files it is comparing is
383binary (a non-text file), it normally treats that pair of files much as
384if the summary output format had been selected (*note Brief::), and
385reports only that the binary files are different. This is because line
386by line comparisons are usually not meaningful for binary files.
387
388 `diff' determines whether a file is text or binary by checking the
389first few bytes in the file; the exact number of bytes is system
390dependent, but it is typically several thousand. If every byte in that
391part of the file is non-null, `diff' considers the file to be text;
392otherwise it considers the file to be binary.
393
394 Sometimes you might want to force `diff' to consider files to be
395text. For example, you might be comparing text files that contain null
396characters; `diff' would erroneously decide that those are non-text
397files. Or you might be comparing documents that are in a format used
398by a word processing system that uses null characters to indicate
399special formatting. You can force `diff' to consider all files to be
400text files, and compare them line by line, by using the `-a' or
401`--text' option. If the files you compare using this option do not in
402fact contain text, they will probably contain few newline characters,
403and the `diff' output will consist of hunks showing differences between
404long lines of whatever characters the files contain.
405
406 You can also force `diff' to consider all files to be binary files,
407and report only whether they differ (but not how). Use the `-q' or
408`--brief' option for this.
409
410 Differing binary files are considered to cause trouble because the
411resulting `diff' output does not capture all the differences. This
412trouble causes `diff' to exit with status 2. However, this trouble
413cannot occur with the `--a' or `--text' option, or with the `-q' or
414`--brief' option, as these options both cause `diff' to treat binary
415files like text files.
416
417 In operating systems that distinguish between text and binary files,
418`diff' normally reads and writes all data as text. Use the `--binary'
419option to force `diff' to read and write binary data instead. This
420option has no effect on a POSIX-compliant system like GNU or
421traditional Unix. However, many personal computer operating systems
422represent the end of a line with a carriage return followed by a
423newline. On such systems, `diff' normally ignores these carriage
424returns on input and generates them at the end of each output line, but
425with the `--binary' option `diff' treats each carriage return as just
426another input character, and does not generate a carriage return at the
427end of each output line. This can be useful when dealing with non-text
428files that are meant to be interchanged with POSIX-compliant systems.
429
430 The `--strip-trailing-cr' causes `diff' to treat input lines that
431end in carriage return followed by newline as if they end in plain
432newline. This can be useful when comparing text that is imperfectly
433imported from many personal computer operating systems. This option
434affects how lines are read, which in turn affects how they are compared
435and output.
436
437 If you want to compare two files byte by byte, you can use the `cmp'
438program with the `-l' option to show the values of each differing byte
439in the two files. With GNU `cmp', you can also use the `-b' option to
440show the ASCII representation of those bytes. *Note Invoking cmp::,
441for more information.
442
443 If `diff3' thinks that any of the files it is comparing is binary (a
444non-text file), it normally reports an error, because such comparisons
445are usually not useful. `diff3' uses the same test as `diff' to decide
446whether a file is binary. As with `diff', if the input files contain a
447few non-text bytes but otherwise are like text files, you can force
448`diff3' to consider all files to be text files and compare them line by
449line by using the `-a' or `--text' options.
450
451
452File: diff.info, Node: Output Formats, Next: Incomplete Lines, Prev: Comparison, Up: Top
453
454`diff' Output Formats
455*********************
456
457 `diff' has several mutually exclusive options for output format.
458The following sections describe each format, illustrating how `diff'
459reports the differences between two sample input files.
460
461* Menu:
462
463* Sample diff Input:: Sample `diff' input files for examples.
464* Normal:: Showing differences without surrounding text.
465* Context:: Showing differences with the surrounding text.
466* Side by Side:: Showing differences in two columns.
467* Scripts:: Generating scripts for other programs.
468* If-then-else:: Merging files with if-then-else.
469
470
471File: diff.info, Node: Sample diff Input, Next: Normal, Up: Output Formats
472
473Two Sample Input Files
474======================
475
476 Here are two sample files that we will use in numerous examples to
477illustrate the output of `diff' and how various options can change it.
478
479 This is the file `lao':
480
481 The Way that can be told of is not the eternal Way;
482 The name that can be named is not the eternal name.
483 The Nameless is the origin of Heaven and Earth;
484 The Named is the mother of all things.
485 Therefore let there always be non-being,
486 so we may see their subtlety,
487 And let there always be being,
488 so we may see their outcome.
489 The two are the same,
490 But after they are produced,
491 they have different names.
492
493 This is the file `tzu':
494
495 The Nameless is the origin of Heaven and Earth;
496 The named is the mother of all things.
497
498 Therefore let there always be non-being,
499 so we may see their subtlety,
500 And let there always be being,
501 so we may see their outcome.
502 The two are the same,
503 But after they are produced,
504 they have different names.
505 They both may be called deep and profound.
506 Deeper and more profound,
507 The door of all subtleties!
508
509 In this example, the first hunk contains just the first two lines of
510`lao', the second hunk contains the fourth line of `lao' opposing the
511second and third lines of `tzu', and the last hunk contains just the
512last three lines of `tzu'.
513
514
515File: diff.info, Node: Normal, Next: Context, Prev: Sample diff Input, Up: Output Formats
516
517Showing Differences Without Context
518===================================
519
520 The "normal" `diff' output format shows each hunk of differences
521without any surrounding context. Sometimes such output is the clearest
522way to see how lines have changed, without the clutter of nearby
523unchanged lines (although you can get similar results with the context
524or unified formats by using 0 lines of context). However, this format
525is no longer widely used for sending out patches; for that purpose, the
526context format (*note Context Format::) and the unified format (*note
527Unified Format::) are superior. Normal format is the default for
528compatibility with older versions of `diff' and the POSIX standard.
529Use the `--normal' option to select this output format explicitly.
530
531* Menu:
532
533* Detailed Normal:: A detailed description of normal output format.
534* Example Normal:: Sample output in the normal format.
535
536
537File: diff.info, Node: Detailed Normal, Next: Example Normal, Up: Normal
538
539Detailed Description of Normal Format
540-------------------------------------
541
542 The normal output format consists of one or more hunks of
543differences; each hunk shows one area where the files differ. Normal
544format hunks look like this:
545
546 CHANGE-COMMAND
547 < FROM-FILE-LINE
548 < FROM-FILE-LINE...
549 ---
550 > TO-FILE-LINE
551 > TO-FILE-LINE...
552
553 There are three types of change commands. Each consists of a line
554number or comma-separated range of lines in the first file, a single
555character indicating the kind of change to make, and a line number or
556comma-separated range of lines in the second file. All line numbers are
557the original line numbers in each file. The types of change commands
558are:
559
560`LaR'
561 Add the lines in range R of the second file after line L of the
562 first file. For example, `8a12,15' means append lines 12-15 of
563 file 2 after line 8 of file 1; or, if changing file 2 into file 1,
564 delete lines 12-15 of file 2.
565
566`FcT'
567 Replace the lines in range F of the first file with lines in range
568 T of the second file. This is like a combined add and delete, but
569 more compact. For example, `5,7c8,10' means change lines 5-7 of
570 file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
571 file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.
572
573`RdL'
574 Delete the lines in range R from the first file; line L is where
575 they would have appeared in the second file had they not been
576 deleted. For example, `5,7d3' means delete lines 5-7 of file 1;
577 or, if changing file 2 into file 1, append lines 5-7 of file 1
578 after line 3 of file 2.
579
580
581File: diff.info, Node: Example Normal, Prev: Detailed Normal, Up: Normal
582
583An Example of Normal Format
584---------------------------
585
586 Here is the output of the command `diff lao tzu' (*note Sample diff
587Input::, for the complete contents of the two files). Notice that it
588shows only the lines that are different between the two files.
589
590 1,2d0
591 < The Way that can be told of is not the eternal Way;
592 < The name that can be named is not the eternal name.
593 4c2,3
594 < The Named is the mother of all things.
595 ---
596 > The named is the mother of all things.
597 >
598 11a11,13
599 > They both may be called deep and profound.
600 > Deeper and more profound,
601 > The door of all subtleties!
602
603
604File: diff.info, Node: Context, Next: Side by Side, Prev: Normal, Up: Output Formats
605
606Showing Differences in Their Context
607====================================
608
609 Usually, when you are looking at the differences between files, you
610will also want to see the parts of the files near the lines that
611differ, to help you understand exactly what has changed. These nearby
612parts of the files are called the "context".
613
614 GNU `diff' provides two output formats that show context around the
615differing lines: "context format" and "unified format". It can
616optionally show in which function or section of the file the differing
617lines are found.
618
619 If you are distributing new versions of files to other people in the
620form of `diff' output, you should use one of the output formats that
621show context so that they can apply the diffs even if they have made
622small changes of their own to the files. `patch' can apply the diffs
623in this case by searching in the files for the lines of context around
624the differing lines; if those lines are actually a few lines away from
625where the diff says they are, `patch' can adjust the line numbers
626accordingly and still apply the diff correctly. *Note Imperfect::, for
627more information on using `patch' to apply imperfect diffs.
628
629* Menu:
630
631* Context Format:: An output format that shows surrounding lines.
632* Unified Format:: A more compact output format that shows context.
633* Sections:: Showing which sections of the files differences are in.
634* Alternate Names:: Showing alternate file names in context headers.
635
636
637File: diff.info, Node: Context Format, Next: Unified Format, Up: Context
638
639Context Format
640--------------
641
642 The context output format shows several lines of context around the
643lines that differ. It is the standard format for distributing updates
644to source code.
645
646 To select this output format, use the `-C LINES',
647`--context[=LINES]', or `-c' option. The argument LINES that some of
648these options take is the number of lines of context to show. If you
649do not specify LINES, it defaults to three. For proper operation,
650`patch' typically needs at least two lines of context.
651
652* Menu:
653
654* Detailed Context:: A detailed description of the context output format.
655* Example Context:: Sample output in context format.
656* Less Context:: Another sample with less context.
657
658
659File: diff.info, Node: Detailed Context, Next: Example Context, Up: Context Format
660
661Detailed Description of Context Format
662......................................
663
664 The context output format starts with a two-line header, which looks
665like this:
666
667 *** FROM-FILE FROM-FILE-MODIFICATION-TIME
668 --- TO-FILE TO-FILE-MODIFICATION TIME
669
670The time stamp normally looks like `2002-02-21 23:30:39.942229878
671-0800' to indicate the date, time with fractional seconds, and time
672zone in Internet RFC 2822 format
673(ftp://ftp.isi.edu/in-notes/rfc2822.txt). However, a traditional time
674stamp like `Thu Feb 21 23:30:39 2002' is used if the `LC_TIME' locale
675category is either `C' or `POSIX'.
676
677 You can change the header's content with the `--label=LABEL' option;
678see *Note Alternate Names::.
679
680 Next come one or more hunks of differences; each hunk shows one area
681where the files differ. Context format hunks look like this:
682
683 ***************
684 *** FROM-FILE-LINE-RANGE ****
685 FROM-FILE-LINE
686 FROM-FILE-LINE...
687 --- TO-FILE-LINE-RANGE ----
688 TO-FILE-LINE
689 TO-FILE-LINE...
690
691 The lines of context around the lines that differ start with two
692space characters. The lines that differ between the two files start
693with one of the following indicator characters, followed by a space
694character:
695
696`!'
697 A line that is part of a group of one or more lines that changed
698 between the two files. There is a corresponding group of lines
699 marked with `!' in the part of this hunk for the other file.
700
701`+'
702 An "inserted" line in the second file that corresponds to nothing
703 in the first file.
704
705`-'
706 A "deleted" line in the first file that corresponds to nothing in
707 the second file.
708
709 If all of the changes in a hunk are insertions, the lines of
710FROM-FILE are omitted. If all of the changes are deletions, the lines
711of TO-FILE are omitted.
712
713
714File: diff.info, Node: Example Context, Next: Less Context, Prev: Detailed Context, Up: Context Format
715
716An Example of Context Format
717............................
718
719 Here is the output of `diff -c lao tzu' (*note Sample diff Input::,
720for the complete contents of the two files). Notice that up to three
721lines that are not different are shown around each line that is
722different; they are the context lines. Also notice that the first two
723hunks have run together, because their contents overlap.
724
725 *** lao 2002-02-21 23:30:39.942229878 -0800
726 --- tzu 2002-02-21 23:30:50.442260588 -0800
727 ***************
728 *** 1,7 ****
729 - The Way that can be told of is not the eternal Way;
730 - The name that can be named is not the eternal name.
731 The Nameless is the origin of Heaven and Earth;
732 ! The Named is the mother of all things.
733 Therefore let there always be non-being,
734 so we may see their subtlety,
735 And let there always be being,
736 --- 1,6 ----
737 The Nameless is the origin of Heaven and Earth;
738 ! The named is the mother of all things.
739 !
740 Therefore let there always be non-being,
741 so we may see their subtlety,
742 And let there always be being,
743 ***************
744 *** 9,11 ****
745 --- 8,13 ----
746 The two are the same,
747 But after they are produced,
748 they have different names.
749 + They both may be called deep and profound.
750 + Deeper and more profound,
751 + The door of all subtleties!
752
753
754File: diff.info, Node: Less Context, Prev: Example Context, Up: Context Format
755
756An Example of Context Format with Less Context
757..............................................
758
759 Here is the output of `diff -C 1 lao tzu' (*note Sample diff
760Input::, for the complete contents of the two files). Notice that at