1 This is diffutils.info, produced by makeinfo version 4.13 from
4 This manual is for GNU Diffutils (version 3.2, 15 August 2011), and
5 documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
6 showing the differences between files and the GNU `patch' command for
7 using their output to update files.
9 Copyright (C) 1992-1994, 1998, 2001-2002, 2004, 2006, 2009-2011 Free
10 Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this
13 document under the terms of the GNU Free Documentation License,
14 Version 1.3 or any later version published by the Free Software
15 Foundation; with no Invariant Sections, no Front-Cover Texts, and
16 no Back-Cover Texts. A copy of the license is included in the
17 section entitled "GNU Free Documentation License."
19 INFO-DIR-SECTION Individual utilities
21 * cmp: (diffutils)Invoking cmp. Compare 2 files byte by byte.
22 * diff: (diffutils)Invoking diff. Compare 2 files line by line.
23 * diff3: (diffutils)Invoking diff3. Compare 3 files line by line.
24 * patch: (diffutils)Invoking patch. Apply a patch to a file.
25 * sdiff: (diffutils)Invoking sdiff. Merge 2 files side-by-side.
28 INFO-DIR-SECTION Text creation and manipulation
30 * Diffutils: (diffutils). Comparing and merging files.
34 File: diffutils.info, Node: Top, Next: Overview, Up: (dir)
36 Comparing and Merging Files
37 ***************************
39 This manual is for GNU Diffutils (version 3.2, 15 August 2011), and
40 documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
41 showing the differences between files and the GNU `patch' command for
42 using their output to update files.
44 Copyright (C) 1992-1994, 1998, 2001-2002, 2004, 2006, 2009-2011 Free
45 Software Foundation, Inc.
47 Permission is granted to copy, distribute and/or modify this
48 document under the terms of the GNU Free Documentation License,
49 Version 1.3 or any later version published by the Free Software
50 Foundation; with no Invariant Sections, no Front-Cover Texts, and
51 no Back-Cover Texts. A copy of the license is included in the
52 section entitled "GNU Free Documentation License."
56 * Overview:: Preliminary information.
57 * Comparison:: What file comparison means.
59 * Output Formats:: Formats for two-way difference reports.
60 * Incomplete Lines:: Lines that lack trailing newlines.
61 * Comparing Directories:: Comparing files and directories.
62 * Adjusting Output:: Making `diff' output prettier.
63 * diff Performance:: Making `diff' smarter or faster.
65 * Comparing Three Files:: Formats for three-way difference reports.
66 * diff3 Merging:: Merging from a common ancestor.
68 * Interactive Merging:: Interactive merging with `sdiff'.
70 * Merging with patch:: Using `patch' to change old files into new ones.
71 * Making Patches:: Tips for making and using patch distributions.
73 * Invoking cmp:: Compare two files byte by byte.
74 * Invoking diff:: Compare two files line by line.
75 * Invoking diff3:: Compare three files line by line.
76 * Invoking patch:: Apply a diff file to an original.
77 * Invoking sdiff:: Side-by-side merge of file differences.
79 * Standards conformance:: Conformance to the POSIX standard.
80 * Projects:: If you've found a bug or other shortcoming.
82 * Copying This Manual:: How to make copies of this manual.
83 * Translations:: Available translations of this manual.
87 File: diffutils.info, Node: Overview, Next: Comparison, Prev: Top, Up: Top
92 Computer users often find occasion to ask how two files differ. Perhaps
93 one file is a newer version of the other file. Or maybe the two files
94 started out as identical copies but were changed by different people.
96 You can use the `diff' command to show differences between two
97 files, or each corresponding file in two directories. `diff' outputs
98 differences between files line by line in any of several formats,
99 selectable by command line options. This set of differences is often
100 called a "diff" or "patch". For files that are identical, `diff'
101 normally produces no output; for binary (non-text) files, `diff'
102 normally reports only that they are different.
104 You can use the `cmp' command to show the byte and line numbers
105 where two files differ. `cmp' can also show all the bytes that differ
106 between the two files, side by side. A way to compare two files
107 character by character is the Emacs command `M-x compare-windows'.
108 *Note Other Window: (emacs)Other Window, for more information on that
111 You can use the `diff3' command to show differences among three
112 files. When two people have made independent changes to a common
113 original, `diff3' can report the differences between the original and
114 the two changed versions, and can produce a merged file that contains
115 both persons' changes together with warnings about conflicts.
117 You can use the `sdiff' command to merge two files interactively.
119 You can use the set of differences produced by `diff' to distribute
120 updates to text files (such as program source code) to other people.
121 This method is especially useful when the differences are small compared
122 to the complete files. Given `diff' output, you can use the `patch'
123 program to update, or "patch", a copy of the file. If you think of
124 `diff' as subtracting one file from another to produce their
125 difference, you can think of `patch' as adding the difference to one
126 file to reproduce the other.
128 This manual first concentrates on making diffs, and later shows how
129 to use diffs to update files.
131 GNU `diff' was written by Paul Eggert, Mike Haertel, David Hayes,
132 Richard Stallman, and Len Tower. Wayne Davison designed and
133 implemented the unified output format. The basic algorithm is described
134 by Eugene W. Myers in "An O(ND) Difference Algorithm and its
135 Variations", `Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A
136 File Comparison Program", Webb Miller and Eugene W. Myers,
137 `Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
138 The algorithm was independently discovered as described by E. Ukkonen in
139 "Algorithms for Approximate String Matching", `Information and Control'
140 Vol. 64, 1985, pp. 100-118. Unless the `--minimal' option is used,
141 `diff' uses a heuristic by Paul Eggert that limits the cost to O(N^1.5
142 log N) at the price of producing suboptimal output for large inputs
143 with many differences. Related algorithms are surveyed by Alfred V.
144 Aho in section 6.3 of "Algorithms for Finding Patterns in Strings",
145 `Handbook of Theoretical Computer Science' (Jan Van Leeuwen, ed.), Vol.
146 A, `Algorithms and Complexity', Elsevier/MIT Press, 1990, pp. 255-300.
148 GNU `diff3' was written by Randy Smith. GNU `sdiff' was written by
149 Thomas Lord. GNU `cmp' was written by Torbjo"rn Granlund and David
152 GNU `patch' was written mainly by Larry Wall and Paul Eggert;
153 several GNU enhancements were contributed by Wayne Davison and David
154 MacKenzie. Parts of this manual are adapted from a manual page written
155 by Larry Wall, with his permission.
158 File: diffutils.info, Node: Comparison, Next: Output Formats, Prev: Overview, Up: Top
160 1 What Comparison Means
161 ***********************
163 There are several ways to think about the differences between two files.
164 One way to think of the differences is as a series of lines that were
165 deleted from, inserted in, or changed in one file to produce the other
166 file. `diff' compares two files line by line, finds groups of lines
167 that differ, and reports each group of differing lines. It can report
168 the differing lines in several formats, which have different purposes.
170 GNU `diff' can show whether files are different without detailing
171 the differences. It also provides ways to suppress certain kinds of
172 differences that are not important to you. Most commonly, such
173 differences are changes in the amount of white space between words or
174 lines. `diff' also provides ways to suppress differences in alphabetic
175 case or in lines that match a regular expression that you provide.
176 These options can accumulate; for example, you can ignore changes in
177 both white space and alphabetic case.
179 Another way to think of the differences between two files is as a
180 sequence of pairs of bytes that can be either identical or different.
181 `cmp' reports the differences between two files byte by byte, instead
182 of line by line. As a result, it is often more useful than `diff' for
183 comparing binary files. For text files, `cmp' is useful mainly when
184 you want to know only whether two files are identical, or whether one
185 file is a prefix of the other.
187 To illustrate the effect that considering changes byte by byte can
188 have compared with considering them line by line, think of what happens
189 if a single newline character is added to the beginning of a file. If
190 that file is then compared with an otherwise identical file that lacks
191 the newline at the beginning, `diff' will report that a blank line has
192 been added to the file, while `cmp' will report that almost every byte
193 of the two files differs.
195 `diff3' normally compares three input files line by line, finds
196 groups of lines that differ, and reports each group of differing lines.
197 Its output is designed to make it easy to inspect two different sets of
198 changes to the same file.
202 * Hunks:: Groups of differing lines.
203 * White Space:: Suppressing differences in white space.
204 * Blank Lines:: Suppressing differences whose lines are all blank.
205 * Specified Lines:: Suppressing differences whose lines all match a pattern.
206 * Case Folding:: Suppressing differences in alphabetic case.
207 * Brief:: Summarizing which files are different.
208 * Binary:: Comparing binary files or forcing text comparisons.
211 File: diffutils.info, Node: Hunks, Next: White Space, Up: Comparison
216 When comparing two files, `diff' finds sequences of lines common to
217 both files, interspersed with groups of differing lines called "hunks".
218 Comparing two identical files yields one sequence of common lines and
219 no hunks, because no lines differ. Comparing two entirely different
220 files yields no common lines and one large hunk that contains all lines
221 of both files. In general, there are many ways to match up lines
222 between two given files. `diff' tries to minimize the total hunk size
223 by finding large sequences of common lines interspersed with small
224 hunks of differing lines.
226 For example, suppose the file `F' contains the three lines `a', `b',
227 `c', and the file `G' contains the same three lines in reverse order
228 `c', `b', `a'. If `diff' finds the line `c' as common, then the command
229 `diff F G' produces this output:
238 But if `diff' notices the common line `b' instead, it produces this
250 It is also possible to find `a' as the common line. `diff' does not
251 always find an optimal matching between the files; it takes shortcuts
252 to run faster. But its output is usually close to the shortest
253 possible. You can adjust this tradeoff with the `--minimal' (`-d')
254 option (*note diff Performance::).
257 File: diffutils.info, Node: White Space, Next: Blank Lines, Prev: Hunks, Up: Comparison
259 1.2 Suppressing Differences in Blank and Tab Spacing
260 ====================================================
262 The `--ignore-tab-expansion' (`-E') option ignores the distinction
263 between tabs and spaces on input. A tab is considered to be equivalent
264 to the number of spaces to the next tab stop (*note Tabs::).
266 The `--ignore-trailing-space' (`-Z') option ignores white space at
269 The `--ignore-space-change' (`-b') option is stronger than `-E' and
270 `-Z' combined. It ignores white space at line end, and considers all
271 other sequences of one or more white space characters within a line to
272 be equivalent. With this option, `diff' considers the following two
273 lines to be equivalent, where `$' denotes the line end:
275 Here lyeth muche rychnesse in lytell space. -- John Heywood$
276 Here lyeth muche rychnesse in lytell space. -- John Heywood $
278 The `--ignore-all-space' (`-w') option is stronger still. It
279 ignores differences even if one line has white space where the other
280 line has none. "White space" characters include tab, vertical tab,
281 form feed, carriage return, and space; some locales may define
282 additional characters to be white space. With this option, `diff'
283 considers the following two lines to be equivalent, where `$' denotes
284 the line end and `^M' denotes a carriage return:
286 Here lyeth muche rychnesse in lytell space.-- John Heywood$
287 He relyeth much erychnes seinly tells pace. --John Heywood ^M$
289 For many other programs newline is also a white space character, but
290 `diff' is a line-oriented program and a newline character always ends a
291 line. Hence the `-w' or `--ignore-all-space' option does not ignore
292 newline-related changes; it ignores only other white space changes.
295 File: diffutils.info, Node: Blank Lines, Next: Specified Lines, Prev: White Space, Up: Comparison
297 1.3 Suppressing Differences Whose Lines Are All Blank
298 =====================================================
300 The `--ignore-blank-lines' (`-B') option ignores changes that consist
301 entirely of blank lines. With this option, for example, a file
303 1. A point is that which has no part.
305 2. A line is breadthless length.
306 -- Euclid, The Elements, I
307 is considered identical to a file containing
308 1. A point is that which has no part.
309 2. A line is breadthless length.
312 -- Euclid, The Elements, I
314 Normally this option affects only lines that are completely empty,
315 but if you also specify an option that ignores trailing spaces, lines
316 are also affected if they look empty but contain white space. In other
317 words, `-B' is equivalent to `-I '^$'' by default, but it is equivalent
318 to `-I '^[[:space:]]*$'' if `-b', `-w' or `-Z' is also specified.
321 File: diffutils.info, Node: Specified Lines, Next: Case Folding, Prev: Blank Lines, Up: Comparison
323 1.4 Suppressing Differences Whose Lines All Match a Regular Expression
324 ======================================================================
326 To ignore insertions and deletions of lines that match a `grep'-style
327 regular expression, use the `--ignore-matching-lines=REGEXP' (`-I
328 REGEXP') option. You should escape regular expressions that contain
329 shell metacharacters to prevent the shell from expanding them. For
330 example, `diff -I '^[[:digit:]]'' ignores all changes to lines
331 beginning with a digit.
333 However, `-I' only ignores the insertion or deletion of lines that
334 contain the regular expression if every changed line in the hunk--every
335 insertion and every deletion--matches the regular expression. In other
336 words, for each nonignorable change, `diff' prints the complete set of
337 changes in its vicinity, including the ignorable ones.
339 You can specify more than one regular expression for lines to ignore
340 by using more than one `-I' option. `diff' tries to match each line
341 against each regular expression.
344 File: diffutils.info, Node: Case Folding, Next: Brief, Prev: Specified Lines, Up: Comparison
346 1.5 Suppressing Case Differences
347 ================================
349 GNU `diff' can treat lower case letters as equivalent to their upper
350 case counterparts, so that, for example, it considers `Funky Stuff',
351 `funky STUFF', and `fUNKy stuFf' to all be the same. To request this,
352 use the `-i' or `--ignore-case' option.
355 File: diffutils.info, Node: Brief, Next: Binary, Prev: Case Folding, Up: Comparison
357 1.6 Summarizing Which Files Differ
358 ==================================
360 When you only want to find out whether files are different, and you
361 don't care what the differences are, you can use the summary output
362 format. In this format, instead of showing the differences between the
363 files, `diff' simply reports whether files differ. The `--brief'
364 (`-q') option selects this output format.
366 This format is especially useful when comparing the contents of two
367 directories. It is also much faster than doing the normal line by line
368 comparisons, because `diff' can stop analyzing the files as soon as it
369 knows that there are any differences.
371 You can also get a brief indication of whether two files differ by
372 using `cmp'. For files that are identical, `cmp' produces no output.
373 When the files differ, by default, `cmp' outputs the byte and line
374 number where the first difference occurs, or reports that one file is a
375 prefix of the other. You can use the `-s', `--quiet', or `--silent'
376 option to suppress that information, so that `cmp' produces no output
377 and reports whether the files differ using only its exit status (*note
380 Unlike `diff', `cmp' cannot compare directories; it can only compare
384 File: diffutils.info, Node: Binary, Prev: Brief, Up: Comparison
386 1.7 Binary Files and Forcing Text Comparisons
387 =============================================
389 If `diff' thinks that either of the two files it is comparing is binary
390 (a non-text file), it normally treats that pair of files much as if the
391 summary output format had been selected (*note Brief::), and reports
392 only that the binary files are different. This is because line by line
393 comparisons are usually not meaningful for binary files.
395 `diff' determines whether a file is text or binary by checking the
396 first few bytes in the file; the exact number of bytes is system
397 dependent, but it is typically several thousand. If every byte in that
398 part of the file is non-null, `diff' considers the file to be text;
399 otherwise it considers the file to be binary.
401 Sometimes you might want to force `diff' to consider files to be
402 text. For example, you might be comparing text files that contain null
403 characters; `diff' would erroneously decide that those are non-text
404 files. Or you might be comparing documents that are in a format used
405 by a word processing system that uses null characters to indicate
406 special formatting. You can force `diff' to consider all files to be
407 text files, and compare them line by line, by using the `--text' (`-a')
408 option. If the files you compare using this option do not in fact
409 contain text, they will probably contain few newline characters, and
410 the `diff' output will consist of hunks showing differences between
411 long lines of whatever characters the files contain.
413 You can also force `diff' to report only whether files differ (but
414 not how). Use the `--brief' (`-q') option for this.
416 Normally, differing binary files count as trouble because the
417 resulting `diff' output does not capture all the differences. This
418 trouble causes `diff' to exit with status 2. However, this trouble
419 cannot occur with the `--text' (`-a') option, or with the `--brief'
420 (`-q') option, as these options both cause `diff' to generate a form of
421 output that represents differences as requested.
423 In operating systems that distinguish between text and binary files,
424 `diff' normally reads and writes all data as text. Use the `--binary'
425 option to force `diff' to read and write binary data instead. This
426 option has no effect on a POSIX-compliant system like GNU or
427 traditional Unix. However, many personal computer operating systems
428 represent the end of a line with a carriage return followed by a
429 newline. On such systems, `diff' normally ignores these carriage
430 returns on input and generates them at the end of each output line, but
431 with the `--binary' option `diff' treats each carriage return as just
432 another input character, and does not generate a carriage return at the
433 end of each output line. This can be useful when dealing with non-text
434 files that are meant to be interchanged with POSIX-compliant systems.
436 The `--strip-trailing-cr' causes `diff' to treat input lines that
437 end in carriage return followed by newline as if they end in plain
438 newline. This can be useful when comparing text that is imperfectly
439 imported from many personal computer operating systems. This option
440 affects how lines are read, which in turn affects how they are compared
443 If you want to compare two files byte by byte, you can use the `cmp'
444 program with the `--verbose' (`-l') option to show the values of each
445 differing byte in the two files. With GNU `cmp', you can also use the
446 `-b' or `--print-bytes' option to show the ASCII representation of
447 those bytes. *Note Invoking cmp::, for more information.
449 If `diff3' thinks that any of the files it is comparing is binary (a
450 non-text file), it normally reports an error, because such comparisons
451 are usually not useful. `diff3' uses the same test as `diff' to decide
452 whether a file is binary. As with `diff', if the input files contain a
453 few non-text bytes but otherwise are like text files, you can force
454 `diff3' to consider all files to be text files and compare them line by
455 line by using the `-a' or `--text' option.
458 File: diffutils.info, Node: Output Formats, Next: Incomplete Lines, Prev: Comparison, Up: Top
460 2 `diff' Output Formats
461 ***********************
463 `diff' has several mutually exclusive options for output format. The
464 following sections describe each format, illustrating how `diff'
465 reports the differences between two sample input files.
469 * Sample diff Input:: Sample `diff' input files for examples.
470 * Context:: Showing differences with the surrounding text.
471 * Side by Side:: Showing differences in two columns.
472 * Normal:: Showing differences without surrounding text.
473 * Scripts:: Generating scripts for other programs.
474 * If-then-else:: Merging files with if-then-else.
477 File: diffutils.info, Node: Sample diff Input, Next: Context, Up: Output Formats
479 2.1 Two Sample Input Files
480 ==========================
482 Here are two sample files that we will use in numerous examples to
483 illustrate the output of `diff' and how various options can change it.
485 This is the file `lao':
487 The Way that can be told of is not the eternal Way;
488 The name that can be named is not the eternal name.
489 The Nameless is the origin of Heaven and Earth;
490 The Named is the mother of all things.
491 Therefore let there always be non-being,
492 so we may see their subtlety,
493 And let there always be being,
494 so we may see their outcome.
495 The two are the same,
496 But after they are produced,
497 they have different names.
499 This is the file `tzu':
501 The Nameless is the origin of Heaven and Earth;
502 The named is the mother of all things.
504 Therefore let there always be non-being,
505 so we may see their subtlety,
506 And let there always be being,
507 so we may see their outcome.
508 The two are the same,
509 But after they are produced,
510 they have different names.
511 They both may be called deep and profound.
512 Deeper and more profound,
513 The door of all subtleties!
515 In this example, the first hunk contains just the first two lines of
516 `lao', the second hunk contains the fourth line of `lao' opposing the
517 second and third lines of `tzu', and the last hunk contains just the
518 last three lines of `tzu'.
521 File: diffutils.info, Node: Context, Next: Side by Side, Prev: Sample diff Input, Up: Output Formats
523 2.2 Showing Differences in Their Context
524 ========================================
526 Usually, when you are looking at the differences between files, you will
527 also want to see the parts of the files near the lines that differ, to
528 help you understand exactly what has changed. These nearby parts of the
529 files are called the "context".
531 GNU `diff' provides two output formats that show context around the
532 differing lines: "context format" and "unified format". It can
533 optionally show in which function or section of the file the differing
536 If you are distributing new versions of files to other people in the
537 form of `diff' output, you should use one of the output formats that
538 show context so that they can apply the diffs even if they have made
539 small changes of their own to the files. `patch' can apply the diffs
540 in this case by searching in the files for the lines of context around
541 the differing lines; if those lines are actually a few lines away from
542 where the diff says they are, `patch' can adjust the line numbers
543 accordingly and still apply the diff correctly. *Note Imperfect::, for
544 more information on using `patch' to apply imperfect diffs.
548 * Context Format:: An output format that shows surrounding lines.
549 * Unified Format:: A more compact output format that shows context.
550 * Sections:: Showing which sections of the files differences are in.
551 * Alternate Names:: Showing alternate file names in context headers.
554 File: diffutils.info, Node: Context Format, Next: Unified Format, Up: Context
559 The context output format shows several lines of context around the
560 lines that differ. It is the standard format for distributing updates
563 To select this output format, use the `--context[=LINES]' (`-C
564 LINES') or `-c' option. The argument LINES that some of these options
565 take is the number of lines of context to show. If you do not specify
566 LINES, it defaults to three. For proper operation, `patch' typically
567 needs at least two lines of context.
571 * Example Context:: Sample output in context format.
572 * Less Context:: Another sample with less context.
573 * Detailed Context:: A detailed description of the context output format.
576 File: diffutils.info, Node: Example Context, Next: Less Context, Up: Context Format
578 2.2.1.1 An Example of Context Format
579 ....................................
581 Here is the output of `diff -c lao tzu' (*note Sample diff Input::, for
582 the complete contents of the two files). Notice that up to three lines
583 that are not different are shown around each line that is different;
584 they are the context lines. Also notice that the first two hunks have
585 run together, because their contents overlap.
587 *** lao 2002-02-21 23:30:39.942229878 -0800
588 --- tzu 2002-02-21 23:30:50.442260588 -0800
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 The Nameless is the origin of Heaven and Earth;
594 ! The Named is the mother of all things.
595 Therefore let there always be non-being,
596 so we may see their subtlety,
597 And let there always be being,
599 The Nameless is the origin of Heaven and Earth;
600 ! The named is the mother of all things.
602 Therefore let there always be non-being,
603 so we may see their subtlety,
604 And let there always be being,
608 The two are the same,
609 But after they are produced,
610 they have different names.
611 + They both may be called deep and profound.
612 + Deeper and more profound,
613 + The door of all subtleties!
616 File: diffutils.info, Node: Less Context, Next: Detailed Context, Prev: Example Context, Up: Context Format
618 2.2.1.2 An Example of Context Format with Less Context
619 ......................................................
621 Here is the output of `diff -C 1 lao tzu' (*note Sample diff Input::,
622 for the complete contents of the two files). Notice that at most one
623 context line is reported here.
625 *** lao 2002-02-21 23:30:39.942229878 -0800
626 --- tzu 2002-02-21 23:30:50.442260588 -0800
629 - The Way that can be told of is not the eternal Way;
630 - The name that can be named is not the eternal name.
631 The Nameless is the origin of Heaven and Earth;
632 ! The Named is the mother of all things.
633 Therefore let there always be non-being,
635 The Nameless is the origin of Heaven and Earth;
636 ! The named is the mother of all things.
638 Therefore let there always be non-being,
642 they have different names.
643 + They both may be called deep and profound.
644 + Deeper and more profound,
645 + The door of all subtleties!
648 File: diffutils.info, Node: Detailed Context, Prev: Less Context, Up: Context Format
650 2.2.1.3 Detailed Description of Context Format
651 ..............................................
653 The context output format starts with a two-line header, which looks
656 *** FROM-FILE FROM-FILE-MODIFICATION-TIME
657 --- TO-FILE TO-FILE-MODIFICATION TIME
659 The time stamp normally looks like `2002-02-21 23:30:39.942229878
660 -0800' to indicate the date, time with fractional seconds, and time
661 zone in Internet RFC 2822 format
662 (ftp://ftp.isi.edu/in-notes/rfc2822.txt). (The fractional seconds are
663 omitted on hosts that do not support fractional time stamps.) However,
664 a traditional time stamp like `Thu Feb 21 23:30:39 2002' is used if the
665 `LC_TIME' locale category is either `C' or `POSIX'.
667 You can change the header's content with the `--label=LABEL' option;
668 see *note Alternate Names::.
670 Next come one or more hunks of differences; each hunk shows one area
671 where the files differ. Context format hunks look like this:
674 *** FROM-FILE-LINE-NUMBERS ****
677 --- TO-FILE-LINE-NUMBERS ----
681 If a hunk contains two or more lines, its line numbers look like
682 `START,END'. Otherwise only its end line number appears. An empty
683 hunk is considered to end at the line that precedes the hunk.
685 The lines of context around the lines that differ start with two
686 space characters. The lines that differ between the two files start
687 with one of the following indicator characters, followed by a space
691 A line that is part of a group of one or more lines that changed
692 between the two files. There is a corresponding group of lines
693 marked with `!' in the part of this hunk for the other file.
696 An "inserted" line in the second file that corresponds to nothing
700 A "deleted" line in the first file that corresponds to nothing in
703 If all of the changes in a hunk are insertions, the lines of
704 FROM-FILE are omitted. If all of the changes are deletions, the lines
705 of TO-FILE are omitted.
708 File: diffutils.info, Node: Unified Format, Next: Sections, Prev: Context Format, Up: Context
713 The unified output format is a variation on the context format that is
714 more compact because it omits redundant context lines. To select this
715 output format, use the `--unified[=LINES]' (`-U LINES'), or `-u' option.
716 The argument LINES is the number of lines of context to show. When it
717 is not given, it defaults to three.
719 At present, only GNU `diff' can produce this format and only GNU
720 `patch' can automatically apply diffs in this format. For proper
721 operation, `patch' typically needs at least three lines of context.
725 * Example Unified:: Sample output in unified format.
726 * Detailed Unified:: A detailed description of unified format.
729 File: diffutils.info, Node: Example Unified, Next: Detailed Unified, Up: Unified Format
731 2.2.2.1 An Example of Unified Format
732 ....................................
734 Here is the output of the command `diff -u lao tzu' (*note Sample diff
735 Input::, for the complete contents of the two files):
737 --- lao 2002-02-21 23:30:39.942229878 -0800
738 +++ tzu 2002-02-21 23:30:50.442260588 -0800
740 -The Way that can be told of is not the eternal Way;
741 -The name that can be named is not the eternal name.
742 The Nameless is the origin of Heaven and Earth;
743 -The Named is the mother of all things.
744 +The named is the mother of all things.
746 Therefore let there always be non-being,
747 so we may see their subtlety,
748 And let there always be being,
750 The two are the same,
751 But after they are produced,
752 they have different names.
753 +They both may be called deep and profound.
754 +Deeper and more profound,
755 +The door of all subtleties!
758 File: diffutils.info, Node: Detailed Unified, Prev: Example Unified, Up: Unified Format
760 2.2.2.2 Detailed Description of Unified Format
761 ..............................................
763 The unified output format starts with a two-line header, which looks
766 --- FROM-FILE FROM-FILE-MODIFICATION-TIME
767 +++ TO-FILE TO-FILE-MODIFICATION-TIME
769 The time stamp looks like `2002-02-21 23:30:39.942229878 -0800' to
770 indicate the date, time with fractional seconds, and time zone. The
771 fractional seconds are omitted on hosts that do not support fractional
774 You can change the header's content with the `--label=LABEL' option;
775 see *Note Alternate Names::.
777 Next come one or more hunks of differences; each hunk shows one area
778 where the files differ. Unified format hunks look like this:
780 @@ FROM-FILE-LINE-NUMBERS TO-FILE-LINE-NUMBERS @@
781 LINE-FROM-EITHER-FILE
782 LINE-FROM-EITHER-FILE...
784 If a hunk contains just one line, only its start line number appears.
785 Otherwise its line numbers look like `START,COUNT'. An empty hunk is
786 considered to start at the line that follows the hunk.
788 If a hunk and its context contain two or more lines, its line
789 numbers look like `START,COUNT'. Otherwise only its end line number
790 appears. An empty hunk is considered to end at the line that precedes
793 The lines common to both files begin with a space character. The
794 lines that actually differ between the two files have one of the
795 following indicator characters in the left print column:
798 A line was added here to the first file.
801 A line was removed here from the first file.
804 File: diffutils.info, Node: Sections, Next: Alternate Names, Prev: Unified Format, Up: Context
806 2.2.3 Showing Which Sections Differences Are in
807 -----------------------------------------------
809 Sometimes you might want to know which part of the files each change
810 falls in. If the files are source code, this could mean which function
811 was changed. If the files are documents, it could mean which chapter
812 or appendix was changed. GNU `diff' can show this by displaying the
813 nearest section heading line that precedes the differing lines. Which
814 lines are "section headings" is determined by a regular expression.
818 * Specified Headings:: Showing headings that match regular expressions.
819 * C Function Headings:: Showing headings of C functions.
822 File: diffutils.info, Node: Specified Headings, Next: C Function Headings, Up: Sections
824 2.2.3.1 Showing Lines That Match Regular Expressions
825 ....................................................
827 To show in which sections differences occur for files that are not
828 source code for C or similar languages, use the
829 `--show-function-line=REGEXP' (`-F REGEXP') option. `diff' considers
830 lines that match the `grep'-style regular expression REGEXP to be the
831 beginning of a section of the file. Here are suggested regular
832 expressions for some common languages:
843 This option does not automatically select an output format; in order
844 to use it, you must select the context format (*note Context Format::)
845 or unified format (*note Unified Format::). In other output formats it
848 The `--show-function-line' (`-F') option finds the nearest unchanged
849 line that precedes each hunk of differences and matches the given
850 regular expression. Then it adds that line to the end of the line of
851 asterisks in the context format, or to the `@@' line in unified format.
852 If no matching line exists, this option leaves the output for that hunk
853 unchanged. If that line is more than 40 characters long, it outputs
854 only the first 40 characters. You can specify more than one regular
855 expression for such lines; `diff' tries to match each line against each
856 regular expression, starting with the last one given. This means that
857 you can use `-p' and `-F' together, if you wish.
860 File: diffutils.info, Node: C Function Headings, Prev: Specified Headings, Up: Sections
862 2.2.3.2 Showing C Function Headings
863 ...................................
865 To show in which functions differences occur for C and similar
866 languages, you can use the `--show-c-function' (`-p') option. This
867 option automatically defaults to the context output format (*note
868 Context Format::), with the default number of lines of context. You
869 can override that number with `-C LINES' elsewhere in the command line.
870 You can override both the format and the number with `-U LINES'
871 elsewhere in the command line.
873 The `--show-c-function' (`-p') option is equivalent to `-F
874 '^[[:alpha:]$_]'' if the unified format is specified, otherwise `-c -F
875 '^[[:alpha:]$_]'' (*note Specified Headings::). GNU `diff' provides
876 this option for the sake of convenience.
879 File: diffutils.info, Node: Alternate Names, Prev: Sections, Up: Context
881 2.2.4 Showing Alternate File Names
882 ----------------------------------
884 If you are comparing two files that have meaningless or uninformative
885 names, you might want `diff' to show alternate names in the header of
886 the context and unified output formats. To do this, use the
887 `--label=LABEL' option. The first time you give this option, its
888 argument replaces the name and date of the first file in the header;
889 the second time, its argument replaces the name and date of the second
890 file. If you give this option more than twice, `diff' reports an
891 error. The `--label' option does not affect the file names in the `pr'
892 header when the `-l' or `--paginate' option is used (*note
895 Here are the first two lines of the output from `diff -C 2
896 --label=original --label=modified lao tzu':
902 File: diffutils.info, Node: Side by Side, Next: Normal, Prev: Context, Up: Output Formats
904 2.3 Showing Differences Side by Side
905 ====================================
907 `diff' can produce a side by side difference listing of two files. The
908 files are listed in two columns with a gutter between them. The gutter
909 contains one of the following markers:
912 The corresponding lines are in common. That is, either the lines
913 are identical, or the difference is ignored because of one of the
914 `--ignore' options (*note White Space::).
917 The corresponding lines differ, and they are either both complete
921 The files differ and only the first file contains the line.
924 The files differ and only the second file contains the line.
927 Only the first file contains the line, but the difference is
931 Only the second file contains the line, but the difference is
935 The corresponding lines differ, and only the first line is
939 The corresponding lines differ, and only the second line is
942 Normally, an output line is incomplete if and only if the lines that
943 it contains are incomplete; *Note Incomplete Lines::. However, when an
944 output line represents two differing lines, one might be incomplete
945 while the other is not. In this case, the output line is complete, but
946 its the gutter is marked `\' if the first line is incomplete, `/' if
949 Side by side format is sometimes easiest to read, but it has
950 limitations. It generates much wider output than usual, and truncates
951 lines that are too long to fit. Also, it relies on lining up output
952 more heavily than usual, so its output looks particularly bad if you
953 use varying width fonts, nonstandard tab stops, or nonprinting
956 You can use the `sdiff' command to interactively merge side by side
957 differences. *Note Interactive Merging::, for more information on
962 * Side by Side Format:: Controlling side by side output format.
963 * Example Side by Side:: Sample side by side output.
966 File: diffutils.info, Node: Side by Side Format, Next: Example Side by Side, Up: Side by Side
968 2.3.1 Controlling Side by Side Format
969 -------------------------------------
971 The `--side-by-side' (`-y') option selects side by side format.
972 Because side by side output lines contain two input lines, the output
973 is wider than usual: normally 130 print columns, which can fit onto a
974 traditional printer line. You can set the width of the output with the
975 `--width=COLUMNS' (`-W COLUMNS') option. The output is split into two
976 halves of equal width, separated by a small gutter to mark differences;
977 the right half is aligned to a tab stop so that tabs line up. Input
978 lines that are too long to fit in half of an output line are truncated
981 The `--left-column' option prints only the left column of two common
982 lines. The `--suppress-common-lines' option suppresses common lines
986 File: diffutils.info, Node: Example Side by Side, Prev: Side by Side Format, Up: Side by Side
988 2.3.2 An Example of Side by Side Format
989 ---------------------------------------
991 Here is the output of the command `diff -y -W 72 lao tzu' (*note Sample
992 diff Input::, for the complete contents of the two files).
994 The Way that can be told of is n <
995 The name that can be named is no <
996 The Nameless is the origin of He The Nameless is the origin of He
997 The Named is the mother of all t | The named is the mother of all t
999 Therefore let there always be no Therefore let there always be no
1000 so we may see their subtlety, so we may see their subtlety,
1001 And let there always be being, And let there always be being,
1002 so we may see their outcome. so we may see their outcome.
1003 The two are the same, The two are the same,
1004 But after they are produced, But after they are produced,
1005 they have different names. they have different names.
1006 > They both may be called deep and
1007 > Deeper and more profound,
1008 > The door of all subtleties!
1011 File: diffutils.info, Node: Normal, Next: Scripts, Prev: Side by Side, Up: Output Formats
1013 2.4 Showing Differences Without Context
1014 =======================================
1016 The "normal" `diff' output format shows each hunk of differences
1017 without any surrounding context. Sometimes such output is the clearest
1018 way to see how lines have changed, without the clutter of nearby
1019 unchanged lines (although you can get similar results with the context
1020 or unified formats by using 0 lines of context). However, this format
1021 is no longer widely used for sending out patches; for that purpose, the
1022 context format (*note Context Format::) and the unified format (*note
1023 Unified Format::) are superior. Normal format is the default for
1024 compatibility with older versions of `diff' and the POSIX standard.
1025 Use the `--normal' option to select this output format explicitly.
1029 * Example Normal:: Sample output in the normal format.
1030 * Detailed Normal:: A detailed description of normal output format.
1033 File: diffutils.info, Node: Example Normal, Next: Detailed Normal, Up: Normal
1035 2.4.1 An Example of Normal Format
1036 ---------------------------------
1038 Here is the output of the command `diff lao tzu' (*note Sample diff
1039 Input::, for the complete contents of the two files). Notice that it
1040 shows only the lines that are different between the two files.
1043 < The Way that can be told of is not the eternal Way;
1044 < The name that can be named is not the eternal name.
1046 < The Named is the mother of all things.
1048 > The named is the mother of all things.
1051 > They both may be called deep and profound.
1052 > Deeper and more profound,
1053 > The door of all subtleties!
1056 File: diffutils.info, Node: Detailed Normal, Prev: Example Normal, Up: Normal
1058 2.4.2 Detailed Description of Normal Format
1059 -------------------------------------------
1061 The normal output format consists of one or more hunks of differences;
1062 each hunk shows one area where the files differ. Normal format hunks
1072 There are three types of change commands. Each consists of a line
1073 number or comma-separated range of lines in the first file, a single
1074 character indicating the kind of change to make, and a line number or
1075 comma-separated range of lines in the second file. All line numbers are
1076 the original line numbers in each file. The types of change commands
1080 Add the lines in range R of the second file after line L of the
1081 first file. For example, `8a12,15' means append lines 12-15 of
1082 file 2 after line 8 of file 1; or, if changing file 2 into file 1,
1083 delete lines 12-15 of file 2.
1086 Replace the lines in range F of the first file with lines in range
1087 T of the second file. This is like a combined add and delete, but
1088 more compact. For example, `5,7c8,10' means change lines 5-7 of
1089 file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
1090 file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.
1093 Delete the lines in range R from the first file; line L is where
1094 they would have appeared in the second file had they not been
1095 deleted. For example, `5,7d3' means delete lines 5-7 of file 1;
1096 or, if changing file 2 into file 1, append lines 5-7 of file 1
1097 after line 3 of file 2.
1100 File: diffutils.info, Node: Scripts, Next: If-then-else, Prev: Normal, Up: Output Formats
1102 2.5 Making Edit Scripts
1103 =======================
1105 Several output modes produce command scripts for editing FROM-FILE to
1110 * ed Scripts:: Using `diff' to produce commands for `ed'.
1111 * Forward ed:: Making forward `ed' scripts.
1112 * RCS:: A special `diff' output format used by RCS.
1115 File: diffutils.info, Node: ed Scripts, Next: Forward ed, Up: Scripts
1120 `diff' can produce commands that direct the `ed' text editor to change
1121 the first file into the second file. Long ago, this was the only
1122 output mode that was suitable for editing one file into another
1123 automatically; today, with `patch', it is almost obsolete. Use the
1124 `--ed' (`-e') option to select this output format.
1126 Like the normal format (*note Normal::), this output format does not
1127 show any context; unlike the normal format, it does not include the
1128 information necessary to apply the diff in reverse (to produce the first
1129 file if all you have is the second file and the diff).
1131 If the file `d' contains the output of `diff -e old new', then the
1132 command `(cat d && echo w) | ed - old' edits `old' to make it a copy of
1133 `new'. More generally, if `d1', `d2', ..., `dN' contain the outputs of
1134 `diff -e old new1', `diff -e new1 new2', ..., `diff -e newN-1 newN',
1135 respectively, then the command `(cat d1 d2 ... dN && echo w) | ed -
1136 old' edits `old' to make it a copy of `newN'.
1140 * Example ed:: A sample `ed' script.
1141 * Detailed ed:: A detailed description of `ed' format.
1144 File: diffutils.info, Node: Example ed, Next: Detailed ed, Up: ed Scripts
1146 2.5.1.1 Example `ed' Script
1147 ...........................
1149 Here is the output of `diff -e lao tzu' (*note Sample diff Input::, for
1150 the complete contents of the two files):
1153 They both may be called deep and profound.
1154 Deeper and more profound,
1155 The door of all subtleties!
1158 The named is the mother of all things.
1164 File: diffutils.info, Node: Detailed ed, Prev: Example ed, Up: ed Scripts
1166 2.5.1.2 Detailed Description of `ed' Format
1167 ...........................................
1169 The `ed' output format consists of one or more hunks of differences.
1170 The changes closest to the ends of the files come first so that
1171 commands that change the number of lines do not affect how `ed'
1172 interprets line numbers in succeeding commands. `ed' format hunks look
1180 Because `ed' uses a single period on a line to indicate the end of
1181 input, GNU `diff' protects lines of changes that contain a single
1182 period on a line by writing two periods instead, then writing a
1183 subsequent `ed' command to change the two periods into one. The `ed'
1184 format cannot represent an incomplete line, so if the second file ends
1185 in a changed incomplete line, `diff' reports an error and then pretends
1186 that a newline was appended.
1188 There are three types of change commands. Each consists of a line
1189 number or comma-separated range of lines in the first file and a single
1190 character indicating the kind of change to make. All line numbers are
1191 the original line numbers in the file. The types of change commands
1195 Add text from the second file after line L in the first file. For
1196 example, `8a' means to add the following lines after line 8 of file
1200 Replace the lines in range R in the first file with the following
1201 lines. Like a combined add and delete, but more compact. For
1202 example, `5,7c' means change lines 5-7 of file 1 to read as the
1206 Delete the lines in range R from the first file. For example,
1207 `5,7d' means delete lines 5-7 of file 1.
1210 File: diffutils.info, Node: Forward ed, Next: RCS, Prev: ed Scripts, Up: Scripts
1212 2.5.2 Forward `ed' Scripts
1213 --------------------------
1215 `diff' can produce output that is like an `ed' script, but with hunks
1216 in forward (front to back) order. The format of the commands is also
1217 changed slightly: command characters precede the lines they modify,
1218 spaces separate line numbers in ranges, and no attempt is made to
1219 disambiguate hunk lines consisting of a single period. Like `ed'
1220 format, forward `ed' format cannot represent incomplete lines.
1222 Forward `ed' format is not very useful, because neither `ed' nor
1223 `patch' can apply diffs in this format. It exists mainly for
1224 compatibility with older versions of `diff'. Use the `-f' or
1225 `--forward-ed' option to select it.
1228 File: diffutils.info, Node: RCS, Prev: Forward ed, Up: Scripts
1233 The RCS output format is designed specifically for use by the Revision
1234 Control System, which is a set of free programs used for organizing
1235 different versions and systems of files. Use the `--rcs' (`-n') option
1236 to select this output format. It is like the forward `ed' format
1237 (*note Forward ed::), but it can represent arbitrary changes to the
1238 contents of a file because it avoids the forward `ed' format's problems
1239 with lines consisting of a single period and with incomplete lines.
1240 Instead of ending text sections with a line consisting of a single
1241 period, each command specifies the number of lines it affects; a
1242 combination of the `a' and `d' commands are used instead of `c'. Also,
1243 if the second file ends in a changed incomplete line, then the output
1244 also ends in an incomplete line.
1246 Here is the output of `diff -n lao tzu' (*note Sample diff Input::,
1247 for the complete contents of the two files):
1252 The named is the mother of all things.
1255 They both may be called deep and profound.
1256 Deeper and more profound,
1257 The door of all subtleties!
1260 File: diffutils.info, Node: If-then-else, Prev: Scripts, Up: Output Formats
1262 2.6 Merging Files with If-then-else
1263 ===================================
1265 You can use `diff' to merge two files of C source code. The output of
1266 `diff' in this format contains all the lines of both files. Lines
1267 common to both files are output just once; the differing parts are
1268 separated by the C preprocessor directives `#ifdef NAME' or `#ifndef
1269 NAME', `#else', and `#endif'. When compiling the output, you select
1270 which version to use by either defining or leaving undefined the macro
1273 To merge two files, use `diff' with the `-D NAME' or `--ifdef=NAME'
1274 option. The argument NAME is the C preprocessor identifier to use in
1275 the `#ifdef' and `#ifndef' directives.
1277 For example, if you change an instance of `wait (&s)' to `waitpid
1278 (-1, &s, 0)' and then merge the old and new files with the
1279 `--ifdef=HAVE_WAITPID' option, then the affected part of your code
1280 might look like this:
1283 #ifndef HAVE_WAITPID
1284 if ((w = wait (&s)) < 0 && errno != EINTR)
1285 #else /* HAVE_WAITPID */
1286 if ((w = waitpid (-1, &s, 0)) < 0 && errno != EINTR)
1287 #endif /* HAVE_WAITPID */
1289 } while (w != child);
1291 You can specify formats for languages other than C by using line
1292 group formats and line formats, as described in the next sections.
1296 * Line Group Formats:: Formats for general if-then-else line groups.
1297 * Line Formats:: Formats for each line in a line group.
1298 * Example If-then-else:: Sample if-then-else format output.
1299 * Detailed If-then-else:: A detailed description of if-then-else format.
1302 File: diffutils.info, Node: Line Group Formats, Next: Line Formats, Up: If-then-else
1304 2.6.1 Line Group Formats
1305 ------------------------
1307 Line group formats let you specify formats suitable for many
1308 applications that allow if-then-else input, including programming
1309 languages and text formatting languages. A line group format specifies
1310 the output format for a contiguous group of similar lines.
1312 For example, the following command compares the TeX files `old' and
1313 `new', and outputs a merged file in which old regions are surrounded by
1314 `\begin{em}'-`\end{em}' lines, and new regions are surrounded by
1315 `\begin{bf}'-`\end{bf}' lines.
1318 --old-group-format='\begin{em}
1321 --new-group-format='\begin{bf}
1326 The following command is equivalent to the above example, but it is a
1327 little more verbose, because it spells out the default line group
1331 --old-group-format='\begin{em}
1334 --new-group-format='\begin{bf}
1337 --unchanged-group-format='%=' \
1338 --changed-group-format='\begin{em}
1345 Here is a more advanced example, which outputs a diff listing with
1346 headers containing line numbers in a "plain English" style.
1349 --unchanged-group-format='' \
1350 --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
1352 --new-group-format='-------- %dN line%(N=1?:s) added after %de:
1354 --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
1359 To specify a line group format, use `diff' with one of the options
1360 listed below. You can specify up to four line group formats, one for
1361 each kind of line group. You should quote FORMAT, because it typically
1362 contains shell metacharacters.
1364 `--old-group-format=FORMAT'
1365 These line groups are hunks containing only lines from the first
1366 file. The default old group format is the same as the changed
1367 group format if it is specified; otherwise it is a format that
1368 outputs the line group as-is.
1370 `--new-group-format=FORMAT'
1371 These line groups are hunks containing only lines from the second
1372 file. The default new group format is same as the changed group
1373 format if it is specified; otherwise it is a format that outputs
1374 the line group as-is.
1376 `--changed-group-format=FORMAT'
1377 These line groups are hunks containing lines from both files. The
1378 default changed group format is the concatenation of the old and
1381 `--unchanged-group-format=FORMAT'
1382 These line groups contain lines common to both files. The default
1383 unchanged group format is a format that outputs the line group
1386 In a line group format, ordinary characters represent themselves;
1387 conversion specifications start with `%' and have one of the following
1391 stands for the lines from the first file, including the trailing
1392 newline. Each line is formatted according to the old line format
1393 (*note Line Formats::).
1396 stands for the lines from the second file, including the trailing
1397 newline. Each line is formatted according to the new line format.
1400 stands for the lines common to both files, including the trailing
1401 newline. Each line is formatted according to the unchanged line
1408 where C is a single character, stands for C. C may not be a
1409 backslash or an apostrophe. For example, `%c':'' stands for a
1410 colon, even inside the then-part of an if-then-else format, which
1411 a colon would normally terminate.
1414 where O is a string of 1, 2, or 3 octal digits, stands for the
1415 character with octal code O. For example, `%c'\0'' stands for a
1419 where F is a `printf' conversion specification and N is one of the
1420 following letters, stands for N's value formatted with F.
1423 The line number of the line just before the group in the old
1427 The line number of the first line in the group in the old
1431 The line number of the last line in the group in the old file.
1434 The line number of the line just after the group in the old
1438 The number of lines in the group in the old file; equals L -
1442 Likewise, for lines in the new file.
1445 The `printf' conversion specification can be `%d', `%o', `%x', or
1446 `%X', specifying decimal, octal, lower case hexadecimal, or upper
1447 case hexadecimal output respectively. After the `%' the following
1448 options can appear in sequence: a series of zero or more flags; an
1449 integer specifying the minimum field width; and a period followed
1450 by an optional integer specifying the minimum number of digits.
1451 The flags are `-' for left-justification, `'' for separating the
1452 digit into groups as specified by the `LC_NUMERIC' locale category,
1453 and `0' for padding with zeros instead of spaces. For example,
1454 `%5dN' prints the number of new lines in the group in a field of
1455 width 5 characters, using the `printf' format `"%5d"'.
1458 If A equals B then T else E. A and B are each either a decimal
1459 constant or a single letter interpreted as above. This format
1460 spec is equivalent to T if A's value equals B's; otherwise it is
1463 For example, `%(N=0?no:%dN) line%(N=1?:s)' is equivalent to `no
1464 lines' if N (the number of lines in the group in the new file) is
1465 0, to `1 line' if N is 1, and to `%dN lines' otherwise.
1468 File: diffutils.info, Node: Line Formats, Next: Example If-then-else, Prev: Line Group Formats, Up: If-then-else
1473 Line formats control how each line taken from an input file is output
1474 as part of a line group in if-then-else format.
1476 For example, the following command outputs text with a one-character
1477 change indicator to the left of the text. The first character of output
1478 is `-' for deleted lines, `|' for added lines, and a space for
1479 unchanged lines. The formats contain newline characters where newlines
1480 are desired on output.
1483 --old-line-format='-%l
1485 --new-line-format='|%l
1487 --unchanged-line-format=' %l
1491 To specify a line format, use one of the following options. You
1492 should quote FORMAT, since it often contains shell metacharacters.
1494 `--old-line-format=FORMAT'
1495 formats lines just from the first file.
1497 `--new-line-format=FORMAT'
1498 formats lines just from the second file.
1500 `--unchanged-line-format=FORMAT'
1501 formats lines common to both files.
1503 `--line-format=FORMAT'
1504 formats all lines; in effect, it sets all three above options
1507 In a line format, ordinary characters represent themselves;
1508 conversion specifications start with `%' and have one of the following
1512 stands for the contents of the line, not counting its trailing
1513 newline (if any). This format ignores whether the line is
1514 incomplete; *Note Incomplete Lines::.
1517 stands for the contents of the line, including its trailing newline
1518 (if any). If a line is incomplete, this format preserves its
1525 where C is a single character, stands for C. C may not be a
1526 backslash or an apostrophe. For example, `%c':'' stands for a
1530 where O is a string of 1, 2, or 3 octal digits, stands for the
1531 character with octal code O. For example, `%c'\0'' stands for a
1535 where F is a `printf' conversion specification, stands for the
1536 line number formatted with F. For example, `%.5dn' prints the
1537 line number using the `printf' format `"%.5d"'. *Note Line Group
1538 Formats::, for more about printf conversion specifications.
1541 The default line format is `%l' followed by a newline character.
1543 If the input contains tab characters and it is important that they
1544 line up on output, you should ensure that `%l' or `%L' in a line format
1545 is just after a tab stop (e.g. by preceding `%l' or `%L' with a tab
1546 character), or you should use the `-t' or `--expand-tabs' option.
1548 Taken together, the line and line group formats let you specify many
1549 different formats. For example, the following command uses a format
1550 similar to normal `diff' format. You can tailor this command to get
1551 fine control over `diff' output.
1554 --old-line-format='< %l
1556 --new-line-format='> %l
1558 --old-group-format='%df%(f=l?:,%dl)d%dE
1560 --new-group-format='%dea%dF%(F=L?:,%dL)
1562 --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
1565 --unchanged-group-format='' \
1569 File: diffutils.info, Node: Example If-then-else, Next: Detailed If-then-else, Prev: Line Formats, Up: If-then-else
1571 2.6.3 An Example of If-then-else Format
1572 ---------------------------------------
1574 Here is the output of `diff -DTWO lao tzu' (*note Sample diff Input::,
1575 for the complete contents of the two files):
1578 The Way that can be told of is not the eternal Way;
1579 The name that can be named is not the eternal name.
1581 The Nameless is the origin of Heaven and Earth;
1583 The Named is the mother of all things.
1585 The named is the mother of all things.
1588 Therefore let there always be non-being,
1589 so we may see their subtlety,
1590 And let there always be being,
1591 so we may see their outcome.
1592 The two are the same,
1593 But after they are produced,
1594 they have different names.
1596 They both may be called deep and profound.
1597 Deeper and more profound,
1598 The door of all subtleties!
1602 File: diffutils.info, Node: Detailed If-then-else, Prev: Example If-then-else, Up: If-then-else
1604 2.6.4 Detailed Description of If-then-else Format
1605 -------------------------------------------------
1607 For lines common to both files, `diff' uses the unchanged line group
1608 format. For each hunk of differences in the merged output format, if
1609 the hunk contains only lines from the first file, `diff' uses the old
1610 line group format; if the hunk contains only lines from the second
1611 file, `diff' uses the new group format; otherwise, `diff' uses the
1612 changed group format.
1614 The old, new, and unchanged line formats specify the output format of
1615 lines from the first file, lines from the second file, and lines common
1616 to both files, respectively.
1618 The option `--ifdef=NAME' is equivalent to the following sequence of
1619 options using shell syntax:
1621 --old-group-format='#ifndef NAME
1622 %<#endif /* ! NAME */
1624 --new-group-format='#ifdef NAME
1627 --unchanged-group-format='%=' \
1628 --changed-group-format='#ifndef NAME
1633 You should carefully check the `diff' output for proper nesting.
1634 For example, when using the `-D NAME' or `--ifdef=NAME' option, you
1635 should check that if the differing lines contain any of the C
1636 preprocessor directives `#ifdef', `#ifndef', `#else', `#elif', or
1637 `#endif', they are nested properly and match. If they don't, you must
1638 make corrections manually. It is a good idea to carefully check the
1639 resulting code anyway to make sure that it really does what you want it
1640 to; depending on how the input files were produced, the output might
1641 contain duplicate or otherwise incorrect code.
1643 The `patch' `-D NAME' option behaves like the `diff' `-D NAME'
1644 option, except it operates on a file and a diff to produce a merged
1645 file; *Note patch Options::.
1648 File: diffutils.info, Node: Incomplete Lines, Next: Comparing Directories, Prev: Output Formats, Up: Top
1653 When an input file ends in a non-newline character, its last line is
1654 called an "incomplete line" because its last character is not a
1655 newline. All other lines are called "full lines" and end in a newline
1656 character. Incomplete lines do not match full lines unless differences
1657 in white space are ignored (*note White Space::).
1659 An incomplete line is normally distinguished on output from a full
1660 line by a following line that starts with `\'. However, the RCS format
1661 (*note RCS::) outputs the incomplete line as-is, without any trailing
1662 newline or following line. The side by side format normally represents
1663 incomplete lines as-is, but in some cases uses a `\' or `/' gutter
1664 marker; *Note Side by Side::. The if-then-else line format preserves a
1665 line's incompleteness with `%L', and discards the newline with `%l';
1666 *Note Line Formats::. Finally, with the `ed' and forward `ed' output
1667 formats (*note Output Formats::) `diff' cannot represent an incomplete
1668 line, so it pretends there was a newline and reports an error.
1670 For example, suppose `F' and `G' are one-byte files that contain
1671 just `f' and `g', respectively. Then `diff F G' outputs
1675 \ No newline at end of file
1678 \ No newline at end of file
1680 (The exact message may differ in non-English locales.) `diff -n F G'
1681 outputs the following without a trailing newline:
1687 `diff -e F G' reports two errors and outputs the following:
1694 File: diffutils.info, Node: Comparing Directories, Next: Adjusting Output, Prev: Incomplete Lines, Up: Top
1696 4 Comparing Directories
1697 ***********************
1699 You can use `diff' to compare some or all of the files in two directory
1700 trees. When both file name arguments to `diff' are directories, it
1701 compares each file that is contained in both directories, examining
1702 file names in alphabetical order as specified by the `LC_COLLATE'
1703 locale category. Normally `diff' is silent about pairs of files that
1704 contain no differences, but if you use the `--report-identical-files'
1705 (`-s') option, it reports pairs of identical files. Normally `diff'
1706 reports subdirectories common to both directories without comparing
1707 subdirectories' files, but if you use the `-r' or `--recursive' option,
1708 it compares every corresponding pair of files in the directory trees,
1709 as many levels deep as they go.
1711 For file names that are in only one of the directories, `diff'
1712 normally does not show the contents of the file that exists; it reports
1713 only that the file exists in that directory and not in the other. You
1714 can make `diff' act as though the file existed but was empty in the
1715 other directory, so that it outputs the entire contents of the file that
1716 actually exists. (It is output as either an insertion or a deletion,
1717 depending on whether it is in the first or the second directory given.)
1718 To do this, use the `--new-file' (`-N') option.
1720 If the older directory contains one or more large files that are not
1721 in the newer directory, you can make the patch smaller by using the
1722 `--unidirectional-new-file' option instead of `-N'. This option is
1723 like `-N' except that it only inserts the contents of files that appear
1724 in the second directory but not the first (that is, files that were
1725 added). At the top of the patch, write instructions for the user
1726 applying the patch to remove the files that were deleted before
1727 applying the patch. *Note Making Patches::, for more discussion of
1728 making patches for distribution.
1730 To ignore some files while comparing directories, use the
1731 `--exclude=PATTERN' (`-x PATTERN') option. This option ignores any
1732 files or subdirectories whose base names match the shell pattern
1733 PATTERN. Unlike in the shell, a period at the start of the base of a
1734 file name matches a wildcard at the start of a pattern. You should
1735 enclose PATTERN in quotes so that the shell does not expand it. For
1736 example, the option `-x '*.[ao]'' ignores any file whose name ends with
1739 This option accumulates if you specify it more than once. For
1740 example, using the options `-x 'RCS' -x '*,v'' ignores any file or
1741 subdirectory whose base name is `RCS' or ends with `,v'.
1743 If you need to give this option many times, you can instead put the
1744 patterns in a file, one pattern per line, and use the
1745 `--exclude-from=FILE' (`-X FILE') option. Trailing white space and
1746 empty lines are ignored in the pattern file.
1748 If you have been comparing two directories and stopped partway
1749 through, later you might want to continue where you left off. You can
1750 do this by using the `--starting-file=FILE' (`-S FILE') option. This
1751 compares only the file FILE and all alphabetically later files in the
1752 topmost directory level.
1754 If two directories differ only in that file names are lower case in
1755 one directory and upper case in the upper, `diff' normally reports many
1756 differences because it compares file names in a case sensitive way.
1757 With the `--ignore-file-name-case' option, `diff' ignores case
1758 differences in file names, so that for example the contents of the file
1759 `Tao' in one directory are compared to the contents of the file `TAO'
1760 in the other. The `--no-ignore-file-name-case' option cancels the
1761 effect of the `--ignore-file-name-case' option, reverting to the default
1764 If an `--exclude=PATTERN' (`-x PATTERN') option, or an
1765 `--exclude-from=FILE' (`-X FILE') option, is specified while the
1766 `--ignore-file-name-case' option is in effect, case is ignored when
1767 excluding file names matching the specified patterns.
1770 File: diffutils.info, Node: Adjusting Output, Next: diff Performance, Prev: Comparing Directories, Up: Top
1772 5 Making `diff' Output Prettier
1773 *******************************
1775 `diff' provides several ways to adjust the appearance of its output.
1776 These adjustments can be applied to any output format.
1780 * Tabs:: Preserving the alignment of tab stops.
1781 * Trailing Blanks:: Suppressing blanks before empty output lines.
1782 * Pagination:: Page numbering and time-stamping `diff' output.
1785 File: diffutils.info, Node: Tabs, Next: Trailing Blanks, Up: Adjusting Output
1787 5.1 Preserving Tab Stop Alignment
1788 =================================
1790 The lines of text in some of the `diff' output formats are preceded by
1791 one or two characters that indicate whether the text is inserted,
1792 deleted, or changed. The addition of those characters can cause tabs
1793 to move to the next tab stop, throwing off the alignment of columns in
1794 the line. GNU `diff' provides two ways to make tab-aligned columns
1797 The first way is to have `diff' convert all tabs into the correct
1798 number of spaces before outputting them; select this method with the
1799 `--expand-tabs' (`-t') option. To use this form of output with
1800 `patch', you must give `patch' the `-l' or `--ignore-white-space'
1801 option (*note Changed White Space::, for more information). `diff'
1802 normally assumes that tab stops are set every 8 print columns, but this
1803 can be altered by the `--tabsize=COLUMNS' option.
1805 The other method for making tabs line up correctly is to add a tab
1806 character instead of a space after the indicator character at the
1807 beginning of the line. This ensures that all following tab characters
1808 are in the same position relative to tab stops that they were in the
1809 original files, so that the output is aligned correctly. Its
1810 disadvantage is that it can make long lines too long to fit on one line
1811 of the screen or the paper. It also does not work with the unified
1812 output format, which does not have a space character after the change
1813 type indicator character. Select this method with the `-T' or
1814 `--initial-tab' option.
1817 File: diffutils.info, Node: Trailing Blanks, Next: Pagination, Prev: Tabs, Up: Adjusting Output
1819 5.2 Omitting trailing blanks
1820 ============================
1822 When outputting lines in normal or context format, or outputting an
1823 unchanged line in unified format, `diff' normally outputs a blank just
1824 before each line. If the line is empty, the output of `diff' therefore
1825 contains trailing blanks even though the input does not contain them.
1826 For example, when outputting an unchanged empty line in context format,
1827 `diff' normally outputs a line with two leading spaces.
1829 Some text editors and email agents routinely delete trailing blanks,
1830 so it can be a problem to deal with diff output files that contain
1831 them. You can avoid this problem with the `--suppress-blank-empty'
1832 option. It causes `diff' to omit trailing blanks at the end of output
1833 lines in normal, context, and unified format, unless the trailing
1834 blanks were already present in the input. This changes the output
1835 format slightly, so that output lines are guaranteed to never end in a
1836 blank unless an input line ends in a blank. This format is less likely
1837 to be munged by text editors or by transmission via email. It is
1838 accepted by GNU `patch' as well.
1841 File: diffutils.info, Node: Pagination, Prev: Trailing Blanks, Up: Adjusting Output
1843 5.3 Paginating `diff' Output
1844 ============================
1846 It can be convenient to have long output page-numbered and time-stamped.
1847 The `--paginate' (`-l') option does this by sending the `diff' output
1848 through the `pr' program. Here is what the page header might look like
1849 for `diff -lc lao tzu':
1851 2002-02-22 14:20 diff -lc lao tzu Page 1
1854 File: diffutils.info, Node: diff Performance, Next: Comparing Three Files, Prev: Adjusting Output, Up: Top
1856 6 `diff' Performance Tradeoffs
1857 ******************************
1859 GNU `diff' runs quite efficiently; however, in some circumstances you
1860 can cause it to run faster or produce a more compact set of changes.
1862 One way to improve `diff' performance is to use hard or symbolic
1863 links to files instead of copies. This improves performance because
1864 `diff' normally does not need to read two hard or symbolic links to the
1865 same file, since their contents must be identical. For example,
1866 suppose you copy a large directory hierarchy, make a few changes to the
1867 copy, and then often use `diff -r' to compare the original to the copy.
1868 If the original files are read-only, you can greatly improve
1869 performance by creating the copy using hard or symbolic links (e.g.,
1870 with GNU `cp -lR' or `cp -sR'). Before editing a file in the copy for
1871 the first time, you should break the link and replace it with a regular
1874 You can also affect the performance of GNU `diff' by giving it
1875 options that change the way it compares files. Performance has more
1876 than one dimension. These options improve one aspect of performance at
1877 the cost of another, or they improve performance in some cases while
1878 hurting it in others.
1880 The way that GNU `diff' determines which lines have changed always
1881 comes up with a near-minimal set of differences. Usually it is good
1882 enough for practical purposes. If the `diff' output is large, you
1883 might want `diff' to use a modified algorithm that sometimes produces a
1884 smaller set of differences. The `--minimal' (`-d') option does this;
1885 however, it can also cause `diff' to run more slowly than usual, so it
1886 is not the default behavior.
1888 When the files you are comparing are large and have small groups of
1889 changes scattered throughout them, you can use the
1890 `--speed-large-files' option to make a different modification to the
1891 algorithm that `diff' uses. If the input files have a constant small
1892 density of changes, this option speeds up the comparisons without
1893 changing the output. If not, `diff' might produce a larger set of
1894 differences; however, the output will still be correct.
1896 Normally `diff' discards the prefix and suffix that is common to
1897 both files before it attempts to find a minimal set of differences.
1898 This makes `diff' run faster, but occasionally it may produce
1899 non-minimal output. The `--horizon-lines=LINES' option prevents `diff'
1900 from discarding the last LINES lines of the prefix and the first LINES
1901 lines of the suffix. This gives `diff' further opportunities to find a
1904 Suppose a run of changed lines includes a sequence of lines at one
1905 end and there is an identical sequence of lines just outside the other
1906 end. The `diff' command is free to choose which identical sequence is
1907 included in the hunk. In this case, `diff' normally shifts the hunk's
1908 boundaries when this merges adjacent hunks, or shifts a hunk's lines
1909 towards the end of the file. Merging hunks can make the output look
1910 nicer in some cases.
1913 File: diffutils.info, Node: Comparing Three Files, Next: diff3 Merging, Prev: diff Performance, Up: Top
1915 7 Comparing Three Files
1916 ***********************
1918 Use the program `diff3' to compare three files and show any differences
1919 among them. (`diff3' can also merge files; see *note diff3 Merging::).
1921 The "normal" `diff3' output format shows each hunk of differences
1922 without surrounding context. Hunks are labeled depending on whether
1923 they are two-way or three-way, and lines are annotated by their
1924 location in the input files.
1926 *Note Invoking diff3::, for more information on how to run `diff3'.
1930 * Sample diff3 Input:: Sample `diff3' input for examples.
1931 * Example diff3 Normal:: Sample output in the normal format.
1932 * diff3 Hunks:: The format of normal output format.
1933 * Detailed diff3 Normal:: A detailed description of normal output format.
1936 File: diffutils.info, Node: Sample diff3 Input, Next: Example diff3 Normal, Up: Comparing Three Files
1938 7.1 A Third Sample Input File
1939 =============================
1941 Here is a third sample file that will be used in examples to illustrate
1942 the output of `diff3' and how various options can change it. The first
1943 two files are the same that we used for `diff' (*note Sample diff
1944 Input::). This is the third sample file, called `tao':
1946 The Way that can be told of is not the eternal Way;
1947 The name that can be named is not the eternal name.
1948 The Nameless is the origin of Heaven and Earth;
1949 The named is the mother of all things.
1951 Therefore let there always be non-being,
1952 so we may see their subtlety,
1953 And let there always be being,
1954 so we may see their result.
1955 The two are the same,
1956 But after they are produced,
1957 they have different names.
1959 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
1962 File: diffutils.info, Node: Example diff3 Normal, Next: diff3 Hunks, Prev: Sample diff3 Input, Up: Comparing Three Files
1964 7.2 An Example of `diff3' Normal Format
1965 =======================================
1967 Here is the output of the command `diff3 lao tzu tao' (*note Sample
1968 diff3 Input::, for the complete contents of the files). Notice that it
1969 shows only the lines that are different among the three files.
1974 The Way that can be told of is not the eternal Way;
1975 The name that can be named is not the eternal name.
1979 The Named is the mother of all things.
1982 The named is the mother of all things.
1987 so we may see their outcome.
1989 so we may see their result.
1993 They both may be called deep and profound.
1994 Deeper and more profound,
1995 The door of all subtleties!
1998 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2001 File: diffutils.info, Node: Detailed diff3 Normal, Prev: diff3 Hunks, Up: Comparing Three Files
2003 7.3 Detailed Description of `diff3' Normal Format
2004 =================================================
2006 Each hunk begins with a line marked `===='. Three-way hunks have plain
2007 `====' lines, and two-way hunks have `1', `2', or `3' appended to
2008 specify which of the three input files differ in that hunk. The hunks
2009 contain copies of two or three sets of input lines each preceded by one
2010 or two commands identifying where the lines came from.
2012 Normally, two spaces precede each copy of an input line to
2013 distinguish it from the commands. But with the `--initial-tab' (`-T')
2014 option, `diff3' uses a tab instead of two spaces; this lines up tabs
2015 correctly. *Note Tabs::, for more information.
2017 Commands take the following forms:
2020 This hunk appears after line L of file FILE, and contains no lines
2021 in that file. To edit this file to yield the other files, one
2022 must append hunk lines taken from the other files. For example,
2023 `1:11a' means that the hunk follows line 11 in the first file and
2024 contains no lines from that file.
2027 This hunk contains the lines in the range R of file FILE. The
2028 range R is a comma-separated pair of line numbers, or just one
2029 number if there is only one line. To edit this file to yield the
2030 other files, one must change the specified lines to be the lines
2031 taken from the other files. For example, `2:11,13c' means that
2032 the hunk contains lines 11 through 13 from the second file.
2034 If the last line in a set of input lines is incomplete (*note
2035 Incomplete Lines::), it is distinguished on output from a full line by
2036 a following line that starts with `\'.
2039 File: diffutils.info, Node: diff3 Hunks, Next: Detailed diff3 Normal, Prev: Example diff3 Normal, Up: Comparing Three Files
2044 Groups of lines that differ in two or three of the input files are
2045 called "diff3 hunks", by analogy with `diff' hunks (*note Hunks::). If
2046 all three input files differ in a `diff3' hunk, the hunk is called a
2047 "three-way hunk"; if just two input files differ, it is a "two-way
2050 As with `diff', several solutions are possible. When comparing the
2051 files `A', `B', and `C', `diff3' normally finds `diff3' hunks by
2052 merging the two-way hunks output by the two commands `diff A B' and
2053 `diff A C'. This does not necessarily minimize the size of the output,
2054 but exceptions should be rare.
2056 For example, suppose `F' contains the three lines `a', `b', `f', `G'
2057 contains the lines `g', `b', `g', and `H' contains the lines `a', `b',
2058 `h'. `diff3 F G H' might output the following:
2074 because it found a two-way hunk containing `a' in the first and third
2075 files and `g' in the second file, then the single line `b' common to
2076 all three files, then a three-way hunk containing the last line of each
2080 File: diffutils.info, Node: diff3 Merging, Next: Interactive Merging, Prev: Comparing Three Files, Up: Top
2082 8 Merging From a Common Ancestor
2083 ********************************
2085 When two people have made changes to copies of the same file, `diff3'
2086 can produce a merged output that contains both sets of changes together
2087 with warnings about conflicts.
2089 One might imagine programs with names like `diff4' and `diff5' to
2090 compare more than three files simultaneously, but in practice the need
2091 rarely arises. You can use `diff3' to merge three or more sets of
2092 changes to a file by merging two change sets at a time.
2094 `diff3' can incorporate changes from two modified versions into a
2095 common preceding version. This lets you merge the sets of changes
2096 represented by the two newer files. Specify the common ancestor version
2097 as the second argument and the two newer versions as the first and third
2098 arguments, like this:
2100 diff3 MINE OLDER YOURS
2102 You can remember the order of the arguments by noting that they are in
2105 You can think of this as subtracting OLDER from YOURS and adding the
2106 result to MINE, or as merging into MINE the changes that would turn
2107 OLDER into YOURS. This merging is well-defined as long as MINE and
2108 OLDER match in the neighborhood of each such change. This fails to be
2109 true when all three input files differ or when only OLDER differs; we
2110 call this a "conflict". When all three input files differ, we call the
2111 conflict an "overlap".
2113 `diff3' gives you several ways to handle overlaps and conflicts.
2114 You can omit overlaps or conflicts, or select only overlaps, or mark
2115 conflicts with special `<<<<<<<' and `>>>>>>>' lines.
2117 `diff3' can output the merge results as an `ed' script that that can
2118 be applied to the first file to yield the merged output. However, it
2119 is usually better to have `diff3' generate the merged output directly;
2120 this bypasses some problems with `ed'.
2124 * Which Changes:: Selecting changes to incorporate.
2125 * Marking Conflicts:: Marking conflicts.
2126 * Bypassing ed:: Generating merged output directly.
2127 * Merging Incomplete Lines:: How `diff3' merges incomplete lines.
2128 * Saving the Changed File:: Emulating System V behavior.
2131 File: diffutils.info, Node: Which Changes, Next: Marking Conflicts, Up: diff3 Merging
2133 8.1 Selecting Which Changes to Incorporate
2134 ==========================================
2136 You can select all unmerged changes from OLDER to YOURS for merging
2137 into MINE with the `--ed' (`-e') option. You can select only the
2138 nonoverlapping unmerged changes with `--easy-only' (`-3'), and you can
2139 select only the overlapping changes with `--overlap-only' (`-x').
2141 The `-e', `-3' and `-x' options select only "unmerged changes", i.e.
2142 changes where MINE and YOURS differ; they ignore changes from OLDER to
2143 YOURS where MINE and YOURS are identical, because they assume that such
2144 changes have already been merged. If this assumption is not a safe
2145 one, you can use the `--show-all' (`-A') option (*note Marking
2148 Here is the output of the command `diff3' with each of these three
2149 options (*note Sample diff3 Input::, for the complete contents of the
2150 files). Notice that `-e' outputs the union of the disjoint sets of
2151 changes output by `-3' and `-x'.
2153 Output of `diff3 -e lao tzu tao':
2156 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2159 so we may see their result.
2162 Output of `diff3 -3 lao tzu tao':
2164 so we may see their result.
2167 Output of `diff3 -x lao tzu tao':
2170 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2174 File: diffutils.info, Node: Marking Conflicts, Next: Bypassing ed, Prev: Which Changes, Up: diff3 Merging
2176 8.2 Marking Conflicts
2177 =====================
2179 `diff3' can mark conflicts in the merged output by bracketing them with
2180 special marker lines. A conflict that comes from two files A and B is
2189 A conflict that comes from three files A, B and C is marked as
2200 The `--show-all' (`-A') option acts like the `-e' option, except
2201 that it brackets conflicts, and it outputs all changes from OLDER to
2202 YOURS, not just the unmerged changes. Thus, given the sample input
2203 files (*note Sample diff3 Input::), `diff3 -A lao tzu tao' puts
2204 brackets around the conflict where only `tzu' differs:
2208 The Way that can be told of is not the eternal Way;
2209 The name that can be named is not the eternal name.
2212 And it outputs the three-way conflict as follows:
2216 They both may be called deep and profound.
2217 Deeper and more profound,
2218 The door of all subtleties!
2221 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2224 The `--show-overlap' (`-E') option outputs less information than the
2225 `--show-all' (`-A') option, because it outputs only unmerged changes,
2226 and it never outputs the contents of the second file. Thus the `-E'
2227 option acts like the `-e' option, except that it brackets the first and
2228 third files from three-way overlapping changes. Similarly, `-X' acts
2229 like `-x', except it brackets all its (necessarily overlapping)
2230 changes. For example, for the three-way overlapping change above, the
2231 `-E' and `-X' options output the following:
2236 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2239 If you are comparing files that have meaningless or uninformative
2240 names, you can use the `--label=LABEL' option to show alternate names
2241 in the `<<<<<<<', `|||||||' and `>>>>>>>' brackets. This option can be
2242 given up to three times, once for each input file. Thus `diff3 -A
2243 --label X --label Y --label Z A B C' acts like `diff3 -A A B C', except
2244 that the output looks like it came from files named `X', `Y' and `Z'
2245 rather than from files named `A', `B' and `C'.
2248 File: diffutils.info, Node: Bypassing ed, Next: Merging Incomplete Lines, Prev: Marking Conflicts, Up: diff3 Merging
2250 8.3 Generating the Merged Output Directly
2251 =========================================
2253 With the `--merge' (`-m') option, `diff3' outputs the merged file
2254 directly. This is more efficient than using `ed' to generate it, and
2255 works even with non-text files that `ed' would reject. If you specify
2256 `-m' without an `ed' script option, `-A' is assumed.
2258 For example, the command `diff3 -m lao tzu tao' (*note Sample diff3
2259 Input:: for a copy of the input files) would output the following:
2263 The Way that can be told of is not the eternal Way;
2264 The name that can be named is not the eternal name.
2266 The Nameless is the origin of Heaven and Earth;
2267 The Named is the mother of all things.
2268 Therefore let there always be non-being,
2269 so we may see their subtlety,
2270 And let there always be being,
2271 so we may see their result.
2272 The two are the same,
2273 But after they are produced,
2274 they have different names.
2277 They both may be called deep and profound.
2278 Deeper and more profound,
2279 The door of all subtleties!
2282 -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2286 File: diffutils.info, Node: Merging Incomplete Lines, Next: Saving the Changed File, Prev: Bypassing ed, Up: diff3 Merging
2288 8.4 How `diff3' Merges Incomplete Lines
2289 =======================================
2291 With `-m', incomplete lines (*note Incomplete Lines::) are simply
2292 copied to the output as they are found; if the merged output ends in an
2293 conflict and one of the input files ends in an incomplete line,
2294 succeeding `|||||||', `=======' or `>>>>>>>' brackets appear somewhere
2295 other than the start of a line because they are appended to the
2298 Without `-m', if an `ed' script option is specified and an
2299 incomplete line is found, `diff3' generates a warning and acts as if a
2300 newline had been present.
2303 File: diffutils.info, Node: Saving the Changed File, Prev: Merging Incomplete Lines, Up: diff3 Merging
2305 8.5 Saving the Changed File
2306 ===========================
2308 Traditional Unix `diff3' generates an `ed' script without the trailing
2309 `w' and `q' commands that save the changes. System V `diff3' generates
2310 these extra commands. GNU `diff3' normally behaves like traditional
2311 Unix `diff3', but with the `-i' option it behaves like System V `diff3'
2312 and appends the `w' and `q' commands.
2314 The `-i' option requires one of the `ed' script options `-AeExX3',
2315 and is incompatible with the merged output option `-m'.
2318 File: diffutils.info, Node: Interactive Merging, Next: Merging with patch, Prev: diff3 Merging, Up: Top
2320 9 Interactive Merging with `sdiff'
2321 **********************************
2323 With `sdiff', you can merge two files interactively based on a
2324 side-by-side `-y' format comparison (*note Side by Side::). Use
2325 `--output=FILE' (`-o FILE') to specify where to put the merged text.
2326 *Note Invoking sdiff::, for more details on the options to `sdiff'.
2328 Another way to merge files interactively is to use the Emacs Lisp
2329 package `emerge'. *Note emerge: (emacs)emerge, for more information.
2333 * sdiff Option Summary:: Summary of `sdiff' options.
2334 * Merge Commands:: Merging two files interactively.
2337 File: diffutils.info, Node: sdiff Option Summary, Next: Merge Commands, Up: Interactive Merging
2339 9.1 Specifying `diff' Options to `sdiff'
2340 ========================================
2342 The following `sdiff' options have the same meaning as for `diff'.
2343 *Note diff Options::, for the use of these options.
2349 --ignore-blank-lines --ignore-case
2350 --ignore-matching-lines=REGEXP --ignore-space-change
2351 --ignore-tab-expansion --ignore-trailing-space
2352 --left-column --minimal --speed-large-files
2353 --strip-trailing-cr --suppress-common-lines
2354 --tabsize=COLUMNS --text --version --width=COLUMNS
2356 For historical reasons, `sdiff' has alternate names for some
2357 options. The `-l' option is equivalent to the `--left-column' option,
2358 and similarly `-s' is equivalent to `--suppress-common-lines'. The
2359 meaning of the `sdiff' `-w' and `-W' options is interchanged from that
2360 of `diff': with `sdiff', `-w COLUMNS' is equivalent to
2361 `--width=COLUMNS', and `-W' is equivalent to `--ignore-all-space'.
2362 `sdiff' without the `-o' option is equivalent to `diff' with the
2363 `--side-by-side' (`-y') option (*note Side by Side::).
2366 File: diffutils.info, Node: Merge Commands, Prev: sdiff Option Summary, Up: Interactive Merging
2371 Groups of common lines, with a blank gutter, are copied from the first
2372 file to the output. After each group of differing lines, `sdiff'
2373 prompts with `%' and pauses, waiting for one of the following commands.
2374 Follow each command with <RET>.
2377 Discard both versions. Invoke a text editor on an empty temporary
2378 file, then copy the resulting file to the output.
2381 Concatenate the two versions, edit the result in a temporary file,
2382 then copy the edited result to the output.
2385 Like `eb', except precede each version with a header that shows
2386 what file and lines the version came from.
2390 Edit a copy of the left version, then copy the result to the
2395 Edit a copy of the right version, then copy the result to the
2400 Copy the left version to the output.
2407 Copy the right version to the output.
2410 Silently copy common lines.
2413 Verbosely copy common lines. This is the default.
2415 The text editor invoked is specified by the `EDITOR' environment
2416 variable if it is set. The default is system-dependent.
2419 File: diffutils.info, Node: Merging with patch, Next: Making Patches, Prev: Interactive Merging, Up: Top
2421 10 Merging with `patch'
2422 ***********************
2424 `patch' takes comparison output produced by `diff' and applies the
2425 differences to a copy of the original file, producing a patched
2426 version. With `patch', you can distribute just the changes to a set of
2427 files instead of distributing the entire file set; your correspondents
2428 can apply `patch' to update their copy of the files with your changes.
2429 `patch' automatically determines the diff format, skips any leading or
2430 trailing headers, and uses the headers to determine which file to
2431 patch. This lets your correspondents feed a mail message containing a
2432 difference listing directly to `patch'.
2434 `patch' detects and warns about common problems like forward
2435 patches. It saves any patches that it could not apply. It can also
2436 maintain a `patchlevel.h' file to ensure that your correspondents apply
2437 diffs in the proper order.
2439 `patch' accepts a series of diffs in its standard input, usually
2440 separated by headers that specify which file to patch. It applies
2441 `diff' hunks (*note Hunks::) one by one. If a hunk does not exactly
2442 match the original file, `patch' uses heuristics to try to patch the
2443 file as well as it can. If no approximate match can be found, `patch'
2444 rejects the hunk and skips to the next hunk. `patch' normally replaces
2445 each file F with its new version, putting reject hunks (if any) into
2448 *Note Invoking patch::, for detailed information on the options to
2453 * patch Input:: Selecting the type of `patch' input.
2454 * Revision Control:: Getting files from RCS, SCCS, etc.
2455 * Imperfect:: Dealing with imperfect patches.
2456 * Creating and Removing:: Creating and removing files with a patch.
2457 * Patching Time Stamps:: Updating time stamps on patched files.
2458 * Multiple Patches:: Handling multiple patches in a file.
2459 * patch Directories:: Changing directory and stripping directories.
2460 * Backups:: Whether backup files are made.
2461 * Backup Names:: Backup file names.
2462 * Reject Names:: Reject file names.
2463 * patch Messages:: Messages and questions `patch' can produce.
2464 * patch and POSIX:: Conformance to the POSIX standard.
2465 * patch and Tradition:: GNU versus traditional `patch'.
2468 File: diffutils.info, Node: patch Input, Next: Revision Control, Up: Merging with patch
2470 10.1 Selecting the `patch' Input Format
2471 =======================================
2473 `patch' normally determines which `diff' format the patch file uses by
2474 examining its contents. For patch files that contain particularly
2475 confusing leading text, you might need to use one of the following
2476 options to force `patch' to interpret the patch file as a certain
2477 format of diff. The output formats listed here are the only ones that
2478 `patch' can understand.
2497 File: diffutils.info, Node: Revision Control, Next: Imperfect, Prev: patch Input, Up: Merging with patch
2499 10.2 Revision Control
2500 =====================
2502 If a nonexistent input file is under a revision control system
2503 supported by `patch', `patch' normally asks the user whether to get (or
2504 check out) the file from the revision control system. Patch currently
2505 supports RCS, ClearCase and SCCS. Under RCS and SCCS, `patch' also
2506 asks when the input file is read-only and matches the default version
2507 in the revision control system.
2509 The `--get=NUM' (`-g NUM') option affects access to files under
2510 supported revision control systems. If NUM is positive, `patch' gets
2511 the file without asking the user; if zero, `patch' neither asks the
2512 user nor gets the file; and if negative, `patch' asks the user before
2513 getting the file. The default value of NUM is given by the value of the
2514 `PATCH_GET' environment variable if it is set; if not, the default
2515 value is zero if `patch' is conforming to POSIX, negative otherwise.
2516 *Note patch and POSIX::.
2518 The choice of revision control system is unaffected by the
2519 `VERSION_CONTROL' environment variable (*note Backup Names::).
2522 File: diffutils.info, Node: Imperfect, Next: Creating and Removing, Prev: Revision Control, Up: Merging with patch
2524 10.3 Applying Imperfect Patches
2525 ===============================
2527 `patch' tries to skip any leading text in the patch file, apply the
2528 diff, and then skip any trailing text. Thus you can feed a mail
2529 message directly to `patch', and it should work. If the entire diff is
2530 indented by a constant amount of white space, `patch' automatically
2531 ignores the indentation. If a context diff contains trailing carriage
2532 return on each line, `patch' automatically ignores the carriage return.
2533 If a context diff has been encapsulated by prepending `- ' to lines
2534 beginning with `-' as per Internet RFC 934
2535 (ftp://ftp.isi.edu/in-notes/rfc934.txt), `patch' automatically
2536 unencapsulates the input.
2538 However, certain other types of imperfect input require user
2539 intervention or testing.
2543 * Changed White Space:: When tabs and spaces don't match exactly.
2544 * Reversed Patches:: Applying reversed patches correctly.
2545 * Inexact:: Helping `patch' find close matches.
2546 * Dry Runs:: Predicting what `patch' will do.
2549 File: diffutils.info, Node: Changed White Space, Next: Reversed Patches, Up: Imperfect
2551 10.3.1 Applying Patches with Changed White Space
2552 ------------------------------------------------
2554 Sometimes mailers, editors, or other programs change spaces into tabs,
2555 or vice versa. If this happens to a patch file or an input file, the
2556 files might look the same, but `patch' will not be able to match them
2557 properly. If this problem occurs, use the `-l' or
2558 `--ignore-white-space' option, which makes `patch' compare blank
2559 characters (i.e. spaces and tabs) loosely so that any nonempty sequence
2560 of blanks in the patch file matches any nonempty sequence of blanks in
2561 the input files. Non-blank characters must still match exactly. Each
2562 line of the context must still match a line in the input file.
2565 File: diffutils.info, Node: Reversed Patches, Next: Inexact, Prev: Changed White Space, Up: Imperfect
2567 10.3.2 Applying Reversed Patches
2568 --------------------------------
2570 Sometimes people run `diff' with the new file first instead of second.
2571 This creates a diff that is "reversed". To apply such patches, give
2572 `patch' the `--reverse' (`-R') option. `patch' then attempts to swap
2573 each hunk around before applying it. Rejects come out in the swapped
2576 Often `patch' can guess that the patch is reversed. If the first
2577 hunk of a patch fails, `patch' reverses the hunk to see if it can apply
2578 it that way. If it can, `patch' asks you if you want to have the `-R'
2579 option set; if it can't, `patch' continues to apply the patch normally.
2580 This method cannot detect a reversed patch if it is a normal diff and
2581 the first command is an append (which should have been a delete) since
2582 appends always succeed, because a null context matches anywhere. But
2583 most patches add or change lines rather than delete them, so most
2584 reversed normal diffs begin with a delete, which fails, and `patch'
2587 If you apply a patch that you have already applied, `patch' thinks
2588 it is a reversed patch and offers to un-apply the patch. This could be
2589 construed as a feature. If you did this inadvertently and you don't
2590 want to un-apply the patch, just answer `n' to this offer and to the
2591 subsequent "apply anyway" question--or type `C-c' to kill the `patch'
2595 File: diffutils.info, Node: Inexact, Next: Dry Runs, Prev: Reversed Patches, Up: Imperfect
2597 10.3.3 Helping `patch' Find Inexact Matches
2598 -------------------------------------------
2600 For context diffs, and to a lesser extent normal diffs, `patch' can
2601 detect when the line numbers mentioned in the patch are incorrect, and
2602 it attempts to find the correct place to apply each hunk of the patch.
2603 As a first guess, it takes the line number mentioned in the hunk, plus
2604 or minus any offset used in applying the previous hunk. If that is not
2605 the correct place, `patch' scans both forward and backward for a set of
2606 lines matching the context given in the hunk.
2608 First `patch' looks for a place where all lines of the context
2609 match. If it cannot find such a place, and it is reading a context or
2610 unified diff, and the maximum fuzz factor is set to 1 or more, then
2611 `patch' makes another scan, ignoring the first and last line of
2612 context. If that fails, and the maximum fuzz factor is set to 2 or
2613 more, it makes another scan, ignoring the first two and last two lines
2614 of context are ignored. It continues similarly if the maximum fuzz
2617 The `--fuzz=LINES' (`-F LINES') option sets the maximum fuzz factor
2618 to LINES. This option only applies to context and unified diffs; it
2619 ignores up to LINES lines while looking for the place to install a
2620 hunk. Note that a larger fuzz factor increases the odds of making a
2621 faulty patch. The default fuzz factor is 2; there is no point to
2622 setting it to more than the number of lines of context in the diff,
2625 If `patch' cannot find a place to install a hunk of the patch, it
2626 writes the hunk out to a reject file (*note Reject Names::, for
2627 information on how reject files are named). It writes out rejected
2628 hunks in context format no matter what form the input patch is in. If
2629 the input is a normal or `ed' diff, many of the contexts are simply
2630 null. The line numbers on the hunks in the reject file may be
2631 different from those in the patch file: they show the approximate
2632 location where `patch' thinks the failed hunks belong in the new file
2633 rather than in the old one.
2635 If the `--verbose' option is given, then as it completes each hunk
2636 `patch' tells you whether the hunk succeeded or failed, and if it
2637 failed, on which line (in the new file) `patch' thinks the hunk should
2638 go. If this is different from the line number specified in the diff,
2639 it tells you the offset. A single large offset _may_ indicate that
2640 `patch' installed a hunk in the wrong place. `patch' also tells you if
2641 it used a fuzz factor to make the match, in which case you should also
2642 be slightly suspicious.
2644 `patch' cannot tell if the line numbers are off in an `ed' script,
2645 and can only detect wrong line numbers in a normal diff when it finds a
2646 change or delete command. It may have the same problem with a context
2647 diff using a fuzz factor equal to or greater than the number of lines
2648 of context shown in the diff (typically 3). In these cases, you should
2649 probably look at a context diff between your original and patched input
2650 files to see if the changes make sense. Compiling without errors is a
2651 pretty good indication that the patch worked, but not a guarantee.
2653 A patch against an empty file applies to a nonexistent file, and vice
2654 versa. *Note Creating and Removing::.
2656 `patch' usually produces the correct results, even when it must make
2657 many guesses. However, the results are guaranteed only when the patch
2658 is applied to an exact copy of the file that the patch was generated
2662 File: diffutils.info, Node: Dry Runs, Prev: Inexact, Up: Imperfect
2664 10.3.4 Predicting what `patch' will do
2665 --------------------------------------
2667 It may not be obvious in advance what `patch' will do with a
2668 complicated or poorly formatted patch. If you are concerned that the
2669 input might cause `patch' to modify the wrong files, you can use the
2670 `--dry-run' option, which causes `patch' to print the results of
2671 applying patches without actually changing any files. You can then
2672 inspect the diagnostics generated by the dry run to see whether `patch'
2673 will modify the files that you expect. If the patch does not do what
2674 you want, you can modify the patch (or the other options to `patch')
2675 and try another dry run. Once you are satisfied with the proposed
2676 patch you can apply it by invoking `patch' as before, but this time
2677 without the `--dry-run' option.
2680 File: diffutils.info, Node: Creating and Removing, Next: Patching Time Stamps, Prev: Imperfect, Up: Merging with patch
2682 10.4 Creating and Removing Files
2683 ================================
2685 Sometimes when comparing two directories, a file may exist in one
2686 directory but not the other. If you give `diff' the `--new-file'
2687 (`-N') option, or if you supply an old or new file that is named
2688 `/dev/null' or is empty and is dated the Epoch (1970-01-01 00:00:00
2689 UTC), `diff' outputs a patch that adds or deletes the contents of this
2690 file. When given such a patch, `patch' normally creates a new file or
2691 removes the old file. However, when conforming to POSIX (*note patch
2692 and POSIX::), `patch' does not remove the old file, but leaves it empty.
2693 The `--remove-empty-files' (`-E') option causes `patch' to remove
2694 output files that are empty after applying a patch, even if the patch
2695 does not appear to be one that removed the file.
2697 If the patch appears to create a file that already exists, `patch'
2698 asks for confirmation before applying the patch.
2701 File: diffutils.info, Node: Patching Time Stamps, Next: Multiple Patches, Prev: Creating and Removing, Up: Merging with patch
2703 10.5 Updating Time Stamps on Patched Files
2704 ==========================================
2706 When `patch' updates a file, it normally sets the file's last-modified
2707 time stamp to the current time of day. If you are using `patch' to
2708 track a software distribution, this can cause `make' to incorrectly
2709 conclude that a patched file is out of date. For example, if
2710 `syntax.c' depends on `syntax.y', and `patch' updates `syntax.c' and
2711 then `syntax.y', then `syntax.c' will normally appear to be out of date
2712 with respect to `syntax.y' even though its contents are actually up to
2715 The `--set-utc' (`-Z') option causes `patch' to set a patched file's
2716 modification and access times to the time stamps given in context diff
2717 headers. If the context diff headers do not specify a time zone, they
2718 are assumed to use Coordinated Universal Time (UTC, often known as GMT).
2720 The `--set-time' (`-T') option acts like `-Z' or `--set-utc', except
2721 that it assumes that the context diff headers' time stamps use local
2722 time instead of UTC. This option is not recommended, because patches
2723 using local time cannot easily be used by people in other time zones,
2724 and because local time stamps are ambiguous when local clocks move
2725 backwards during daylight-saving time adjustments. If the context diff
2726 headers specify a time zone, this option is equivalent to `--set-utc'
2729 `patch' normally refrains from setting a file's time stamps if the
2730 file's original last-modified time stamp does not match the time given
2731 in the diff header, of if the file's contents do not exactly match the
2732 patch. However, if the `--force' (`-f') option is given, the file's
2733 time stamps are set regardless.
2735 Due to the limitations of the current `diff' format, `patch' cannot
2736 update the times of files whose contents have not changed. Also, if
2737 you set file time stamps to values other than the current time of day,
2738 you should also remove (e.g., with `make clean') all files that depend
2739 on the patched files, so that later invocations of `make' do not get
2740 confused by the patched files' times.
2743 File: diffutils.info, Node: Multiple Patches, Next: patch Directories, Prev: Patching Time Stamps, Up: Merging with patch
2745 10.6 Multiple Patches in a File
2746 ===============================
2748 If the patch file contains more than one patch, and if you do not
2749 specify an input file on the command line, `patch' tries to apply each
2750 patch as if they came from separate patch files. This means that it
2751 determines the name of the file to patch for each patch, and that it
2752 examines the leading text before each patch for file names and
2753 prerequisite revision level (*note Making Patches::, for more on that
2756 `patch' uses the following rules to intuit a file name from the
2757 leading text before a patch. First, `patch' takes an ordered list of
2758 candidate file names as follows:
2760 * If the header is that of a context diff, `patch' takes the old and
2761 new file names in the header. A name is ignored if it does not
2762 have enough slashes to satisfy the `-pNUM' or `--strip=NUM'
2763 option. The name `/dev/null' is also ignored.
2765 * If there is an `Index:' line in the leading garbage and if either
2766 the old and new names are both absent or if `patch' is conforming
2767 to POSIX, `patch' takes the name in the `Index:' line.
2769 * For the purpose of the following rules, the candidate file names
2770 are considered to be in the order (old, new, index), regardless of
2771 the order that they appear in the header.
2773 Then `patch' selects a file name from the candidate list as follows:
2775 * If some of the named files exist, `patch' selects the first name
2776 if conforming to POSIX, and the best name otherwise.
2778 * If `patch' is not ignoring RCS, ClearCase, and SCCS (*note
2779 Revision Control::), and no named files exist but an RCS,
2780 ClearCase, or SCCS master is found, `patch' selects the first
2781 named file with an RCS, ClearCase, or SCCS master.
2783 * If no named files exist, no RCS, ClearCase, or SCCS master was
2784 found, some names are given, `patch' is not conforming to POSIX,
2785 and the patch appears to create a file, `patch' selects the best
2786 name requiring the creation of the fewest directories.
2788 * If no file name results from the above heuristics, you are asked
2789 for the name of the file to patch, and `patch' selects that name.
2791 To determine the "best" of a nonempty list of file names, `patch'
2792 first takes all the names with the fewest path name components; of
2793 those, it then takes all the names with the shortest basename; of
2794 those, it then takes all the shortest names; finally, it takes the
2795 first remaining name.
2797 *Note patch and POSIX::, to see whether `patch' is conforming to
2801 File: diffutils.info, Node: patch Directories, Next: Backups, Prev: Multiple Patches, Up: Merging with patch
2803 10.7 Applying Patches in Other Directories
2804 ==========================================
2806 The `--directory=DIRECTORY' (`-d DIRECTORY') option to `patch' makes
2807 directory DIRECTORY the current directory for interpreting both file
2808 names in the patch file, and file names given as arguments to other
2809 options (such as `-B' and `-o'). For example, while in a mail reading
2810 program, you can patch a file in the `/usr/src/emacs' directory
2811 directly from a message containing the patch like this:
2813 | patch -d /usr/src/emacs
2815 Sometimes the file names given in a patch contain leading
2816 directories, but you keep your files in a directory different from the
2817 one given in the patch. In those cases, you can use the
2818 `--strip=NUMBER' (`-pNUMBER') option to set the file name strip count
2819 to NUMBER. The strip count tells `patch' how many slashes, along with
2820 the directory names between them, to strip from the front of file
2821 names. A sequence of one or more adjacent slashes is counted as a
2822 single slash. By default, `patch' strips off all leading directories,
2823 leaving just the base file names.
2825 For example, suppose the file name in the patch file is
2826 `/gnu/src/emacs/etc/NEWS'. Using `-p0' gives the entire file name
2827 unmodified, `-p1' gives `gnu/src/emacs/etc/NEWS' (no leading slash),
2828 `-p4' gives `etc/NEWS', and not specifying `-p' at all gives `NEWS'.
2830 `patch' looks for each file (after any slashes have been stripped)
2831 in the current directory, or if you used the `-d DIRECTORY' option, in
2835 File: diffutils.info, Node: Backups, Next: Backup Names, Prev: patch Directories, Up: Merging with patch
2840 Normally, `patch' creates a backup file if the patch does not exactly
2841 match the original input file, because in that case the original data
2842 might not be recovered if you undo the patch with `patch -R' (*note
2843 Reversed Patches::). However, when conforming to POSIX, `patch' does
2844 not create backup files by default. *Note patch and POSIX::.
2846 The `--backup' (`-b') option causes `patch' to make a backup file
2847 regardless of whether the patch matches the original input. The
2848 `--backup-if-mismatch' option causes `patch' to create backup files for
2849 mismatches files; this is the default when not conforming to POSIX. The
2850 `--no-backup-if-mismatch' option causes `patch' to not create backup
2851 files, even for mismatched patches; this is the default when conforming
2854 When backing up a file that does not exist, an empty, unreadable
2855 backup file is created as a placeholder to represent the nonexistent
2859 File: diffutils.info, Node: Backup Names, Next: Reject Names, Prev: Backups, Up: Merging with patch
2861 10.9 Backup File Names
2862 ======================
2864 Normally, `patch' renames an original input file into a backup file by
2865 appending to its name the extension `.orig', or `~' if using `.orig'
2866 would make the backup file name too long.(1) The `-z BACKUP-SUFFIX' or
2867 `--suffix=BACKUP-SUFFIX' option causes `patch' to use BACKUP-SUFFIX as
2868 the backup extension instead.
2870 Alternately, you can specify the extension for backup files with the
2871 `SIMPLE_BACKUP_SUFFIX' environment variable, which the options override.
2873 `patch' can also create numbered backup files the way GNU Emacs
2874 does. With this method, instead of having a single backup of each
2875 file, `patch' makes a new backup file name each time it patches a file.
2876 For example, the backups of a file named `sink' would be called,
2877 successively, `sink.~1~', `sink.~2~', `sink.~3~', etc.
2879 The `-V BACKUP-STYLE' or `--version-control=BACKUP-STYLE' option
2880 takes as an argument a method for creating backup file names. You can
2881 alternately control the type of backups that `patch' makes with the
2882 `PATCH_VERSION_CONTROL' environment variable, which the `-V' option
2883 overrides. If `PATCH_VERSION_CONTROL' is not set, the
2884 `VERSION_CONTROL' environment variable is used instead. Please note
2885 that these options and variables control backup file names; they do not
2886 affect the choice of revision control system (*note Revision Control::).
2888 The values of these environment variables and the argument to the
2889 `-V' option are like the GNU Emacs `version-control' variable (*note
2890 Backup Names: (emacs)Backup Names, for more information on backup
2891 versions in Emacs). They also recognize synonyms that are more
2892 descriptive. The valid values are listed below; unique abbreviations
2897 Always make numbered backups.
2901 Make numbered backups of files that already have them, simple
2902 backups of the others. This is the default.
2906 Always make simple backups.
2908 You can also tell `patch' to prepend a prefix, such as a directory
2909 name, to produce backup file names. The `--prefix=PREFIX' (`-B
2910 PREFIX') option makes backup files by prepending PREFIX to them. The
2911 `--basename-prefix=PREFIX' (`-Y PREFIX') prepends PREFIX to the last
2912 file name component of backup file names instead; for example, `-Y ~'
2913 causes the backup name for `dir/file.c' to be `dir/~file.c'. If you
2914 use either of these prefix options, the suffix-based options are
2917 If you specify the output file with the `-o' option, that file is
2918 the one that is backed up, not the input file.
2920 Options that affect the names of backup files do not affect whether
2921 backups are made. For example, if you specify the
2922 `--no-backup-if-mismatch' option, none of the options described in this
2923 section have any affect, because no backups are made.
2925 ---------- Footnotes ----------
2927 (1) A coding error in GNU `patch' version 2.5.4 causes it to always
2928 use `~', but this should be fixed in the next release.
2931 File: diffutils.info, Node: Reject Names, Next: patch Messages, Prev: Backup Names, Up: Merging with patch
2933 10.10 Reject File Names
2934 =======================
2936 The names for reject files (files containing patches that `patch' could
2937 not find a place to apply) are normally the name of the output file
2938 with `.rej' appended (or `#' if using `.rej' would make the backup file
2941 Alternatively, you can tell `patch' to place all of the rejected
2942 patches in a single file. The `-r REJECT-FILE' or
2943 `--reject-file=REJECT-FILE' option uses REJECT-FILE as the reject file
2947 File: diffutils.info, Node: patch Messages, Next: patch and POSIX, Prev: Reject Names, Up: Merging with patch
2949 10.11 Messages and Questions from `patch'
2950 =========================================
2952 `patch' can produce a variety of messages, especially if it has trouble
2953 decoding its input. In a few situations where it's not sure how to
2954 proceed, `patch' normally prompts you for more information from the
2955 keyboard. There are options to produce more or fewer messages, to have
2956 it not ask for keyboard input, and to affect the way that file names
2957 are quoted in messages.
2961 * More or Fewer Messages:: Controlling the verbosity of `patch'.
2962 * patch and Keyboard Input:: Inhibiting keyboard input.
2963 * patch Quoting Style:: Quoting file names in diagnostics.
2965 `patch' exits with status 0 if all hunks are applied successfully, 1
2966 if some hunks cannot be applied, and 2 if there is more serious trouble.
2967 When applying a set of patches in a loop, you should check the exit
2968 status, so you don't apply a later patch to a partially patched file.
2971 File: diffutils.info, Node: More or Fewer Messages, Next: patch and Keyboard Input, Up: patch Messages
2973 10.11.1 Controlling the Verbosity of `patch'
2974 --------------------------------------------
2976 You can cause `patch' to produce more messages by using the `--verbose'
2977 option. For example, when you give this option, the message `Hmm...'
2978 indicates that `patch' is reading text in the patch file, attempting to
2979 determine whether there is a patch in that text, and if so, what kind
2982 You can inhibit all terminal output from `patch', unless an error
2983 occurs, by using the `-s', `--quiet', or `--silent' option.
2986 File: diffutils.info, Node: patch and Keyboard Input, Next: patch Quoting Style, Prev: More or Fewer Messages, Up: patch Messages
2988 10.11.2 Inhibiting Keyboard Input
2989 ---------------------------------
2991 There are two ways you can prevent `patch' from asking you any
2992 questions. The `--force' (`-f') option assumes that you know what you
2993 are doing. It causes `patch' to do the following:
2995 * Skip patches that do not contain file names in their headers.
2997 * Patch files even though they have the wrong version for the
2998 `Prereq:' line in the patch;
3000 * Assume that patches are not reversed even if they look like they
3003 The `--batch' (`-t') option is similar to `-f', in that it suppresses
3004 questions, but it makes somewhat different assumptions:
3006 * Skip patches that do not contain file names in their headers (the
3009 * Skip patches for which the file has the wrong version for the
3010 `Prereq:' line in the patch;
3012 * Assume that patches are reversed if they look like they are.
3015 File: diffutils.info, Node: patch Quoting Style, Prev: patch and Keyboard Input, Up: patch Messages
3017 10.11.3 `patch' Quoting Style
3018 -----------------------------
3020 When `patch' outputs a file name in a diagnostic message, it can format
3021 the name in any of several ways. This can be useful to output file
3022 names unambiguously, even if they contain punctuation or special
3023 characters like newlines. The `--quoting-style=WORD' option controls
3024 how names are output. The WORD should be one of the following:
3030 Quote names for the shell if they contain shell metacharacters or
3031 would cause ambiguous output.
3034 Quote names for the shell, even if they would normally not require
3038 Quote names as for a C language string.
3041 Quote as with `c' except omit the surrounding double-quote
3044 You can specify the default value of the `--quoting-style' option
3045 with the environment variable `QUOTING_STYLE'. If that environment
3046 variable is not set, the default value is `shell', but this default may
3047 change in a future version of `patch'.
3050 File: diffutils.info, Node: patch and POSIX, Next: patch and Tradition, Prev: patch Messages, Up: Merging with patch
3052 10.12 `patch' and the POSIX Standard
3053 ====================================
3055 If you specify the `--posix' option, or set the `POSIXLY_CORRECT'
3056 environment variable, `patch' conforms more strictly to the POSIX
3057 standard, as follows:
3059 * Take the first existing file from the list (old, new, index) when
3060 intuiting file names from diff headers. *Note Multiple Patches::.
3062 * Do not remove files that are removed by a diff. *Note Creating
3065 * Do not ask whether to get files from RCS, ClearCase, or SCCS.
3066 *Note Revision Control::.
3068 * Require that all options precede the files in the command line.
3070 * Do not backup files, even when there is a mismatch. *Note
3075 File: diffutils.info, Node: patch and Tradition, Prev: patch and POSIX, Up: Merging with patch
3077 10.13 GNU `patch' and Traditional `patch'
3078 =========================================
3080 The current version of GNU `patch' normally follows the POSIX standard.
3081 *Note patch and POSIX::, for the few exceptions to this general rule.
3083 Unfortunately, POSIX redefined the behavior of `patch' in several
3084 important ways. You should be aware of the following differences if
3085 you must interoperate with traditional `patch', or with GNU `patch'
3086 version 2.1 and earlier.
3088 * In traditional `patch', the `-p' option's operand was optional,
3089 and a bare `-p' was equivalent to `-p0'. The `-p' option now
3090 requires an operand, and `-p 0' is now equivalent to `-p0'. For
3091 maximum compatibility, use options like `-p0' and `-p1'.
3093 Also, traditional `patch' simply counted slashes when stripping
3094 path prefixes; `patch' now counts pathname components. That is, a
3095 sequence of one or more adjacent slashes now counts as a single
3096 slash. For maximum portability, avoid sending patches containing
3099 * In traditional `patch', backups were enabled by default. This
3100 behavior is now enabled with the `--backup' (`-b') option.
3102 Conversely, in POSIX `patch', backups are never made, even when
3103 there is a mismatch. In GNU `patch', this behavior is enabled
3104 with the `--no-backup-if-mismatch' option, or by conforming to
3107 The `-b SUFFIX' option of traditional `patch' is equivalent to the
3108 `-b -z SUFFIX' options of GNU `patch'.
3110 * Traditional `patch' used a complicated (and incompletely
3111 documented) method to intuit the name of the file to be patched
3112 from the patch header. This method did not conform to POSIX, and
3113 had a few gotchas. Now `patch' uses a different, equally
3114 complicated (but better documented) method that is optionally
3115 POSIX-conforming; we hope it has fewer gotchas. The two methods
3116 are compatible if the file names in the context diff header and the
3117 `Index:' line are all identical after prefix-stripping. Your
3118 patch is normally compatible if each header's file names all
3119 contain the same number of slashes.
3121 * When traditional `patch' asked the user a question, it sent the
3122 question to standard error and looked for an answer from the first
3123 file in the following list that was a terminal: standard error,
3124 standard output, `/dev/tty', and standard input. Now `patch'
3125 sends questions to standard output and gets answers from
3126 `/dev/tty'. Defaults for some answers have been changed so that
3127 `patch' never goes into an infinite loop when using default
3130 * Traditional `patch' exited with a status value that counted the
3131 number of bad hunks, or with status 1 if there was real trouble.
3132 Now `patch' exits with status 1 if some hunks failed, or with 2 if
3133 there was real trouble.
3135 * Limit yourself to the following options when sending instructions
3136 meant to be executed by anyone running GNU `patch', traditional
3137 `patch', or a `patch' that conforms to POSIX. Spaces are
3138 significant in the following list, and operands are required.
3154 File: diffutils.info, Node: Making Patches, Next: Invoking cmp, Prev: Merging with patch, Up: Top
3156 11 Tips for Making and Using Patches
3157 ************************************
3159 Use some common sense when making and using patches. For example, when
3160 sending bug fixes to a program's maintainer, send several small
3161 patches, one per independent subject, instead of one large,
3162 harder-to-digest patch that covers all the subjects.
3164 Here are some other things you should keep in mind if you are going
3165 to distribute patches for updating a software package.
3169 * Tips for Patch Producers:: Advice for making patches.
3170 * Tips for Patch Consumers:: Advice for using patches.
3171 * Avoiding Common Mistakes:: Avoiding common mistakes when using `patch'.
3172 * Generating Smaller Patches:: How to generate smaller patches.
3175 File: diffutils.info, Node: Tips for Patch Producers, Next: Tips for Patch Consumers, Up: Making Patches
3177 11.1 Tips for Patch Producers
3178 =============================
3180 To create a patch that changes an older version of a package into a
3181 newer version, first make a copy of the older and newer versions in
3182 adjacent subdirectories. It is common to do that by unpacking `tar'
3183 archives of the two versions.
3185 To generate the patch, use the command `diff -Naur OLD NEW' where
3186 OLD and NEW identify the old and new directories. The names OLD and
3187 NEW should not contain any slashes. The `-N' option lets the patch
3188 create and remove files; `-a' lets the patch update non-text files; `-u'
3189 generates useful time stamps and enough context; and `-r' lets the
3190 patch update subdirectories. Here is an example command, using Bourne
3193 diff -Naur gcc-3.0.3 gcc-3.0.4
3195 Tell your recipients how to apply the patches. This should include
3196 which working directory to use, and which `patch' options to use; the
3197 option `-p1' is recommended. Test your procedure by pretending to be a
3198 recipient and applying your patches to a copy of the original files.
3200 *Note Avoiding Common Mistakes::, for how to avoid common mistakes
3201 when generating a patch.
3204 File: diffutils.info, Node: Tips for Patch Consumers, Next: Avoiding Common Mistakes, Prev: Tips for Patch Producers, Up: Making Patches
3206 11.2 Tips for Patch Consumers
3207 =============================
3209 A patch producer should tell recipients how to apply the patches, so
3210 the first rule of thumb for a patch consumer is to follow the
3211 instructions supplied with the patch.
3213 GNU `diff' can analyze files with arbitrarily long lines and files
3214 that end in incomplete lines. However, older versions of `patch'
3215 cannot patch such files. If you are having trouble applying such
3216 patches, try upgrading to a recent version of GNU `patch'.
3219 File: diffutils.info, Node: Avoiding Common Mistakes, Next: Generating Smaller Patches, Prev: Tips for Patch Consumers, Up: Making Patches
3221 11.3 Avoiding Common Mistakes
3222 =============================
3224 When producing a patch for multiple files, apply `diff' to directories
3225 whose names do not have slashes. This reduces confusion when the patch
3226 consumer specifies the `-pNUMBER' option, since this option can have
3227 surprising results when the old and new file names have different
3228 numbers of slashes. For example, do not send a patch with a header
3229 that looks like this:
3231 diff -Naur v2.0.29/prog/README prog/README
3232 --- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800
3233 +++ prog/README 2002-03-17 20:49:32.442260588 -0800
3235 because the two file names have different numbers of slashes, and
3236 different versions of `patch' interpret the file names differently. To
3237 avoid confusion, send output that looks like this instead:
3239 diff -Naur v2.0.29/prog/README v2.0.30/prog/README
3240 --- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800
3241 +++ v2.0.30/prog/README 2002-03-17 20:49:32.442260588 -0800
3243 Make sure you have specified the file names correctly, either in a
3244 context diff header or with an `Index:' line. Take care to not send out
3245 reversed patches, since these make people wonder whether they have
3246 already applied the patch.
3248 Avoid sending patches that compare backup file names like
3249 `README.orig' or `README~', since this might confuse `patch' into
3250 patching a backup file instead of the real file. Instead, send patches
3251 that compare the same base file names in different directories, e.g.
3252 `old/README' and `new/README'.
3254 To save people from partially applying a patch before other patches
3255 that should have gone before it, you can make the first patch in the
3256 patch file update a file with a name like `patchlevel.h' or
3257 `version.c', which contains a patch level or version number. If the
3258 input file contains the wrong version number, `patch' will complain
3261 An even clearer way to prevent this problem is to put a `Prereq:'
3262 line before the patch. If the leading text in the patch file contains a
3263 line that starts with `Prereq:', `patch' takes the next word from that
3264 line (normally a version number) and checks whether the next input file
3265 contains that word, preceded and followed by either white space or a
3266 newline. If not, `patch' prompts you for confirmation before
3267 proceeding. This makes it difficult to accidentally apply patches in
3271 File: diffutils.info, Node: Generating Smaller Patches, Prev: Avoiding Common Mistakes, Up: Making Patches
3273 11.4 Generating Smaller Patches
3274 ===============================
3276 The simplest way to generate a patch is to use `diff -Naur' (*note Tips
3277 for Patch Producers::), but you might be able to reduce the size of the
3278 patch by renaming or removing some files before making the patch. If
3279 the older version of the package contains any files that the newer
3280 version does not, or if any files have been renamed between the two
3281 versions, make a list of `rm' and `mv' commands for the user to execute
3282 in the old version directory before applying the patch. Then run those
3283 commands yourself in the scratch directory.
3285 If there are any files that you don't need to include in the patch
3286 because they can easily be rebuilt from other files (for example,
3287 `TAGS' and output from `yacc' and `makeinfo'), exclude them from the
3288 patch by giving `diff' the `-x PATTERN' option (*note Comparing
3289 Directories::). If you want your patch to modify a derived file
3290 because your recipients lack tools to build it, make sure that the
3291 patch for the derived file follows any patches for files that it
3292 depends on, so that the recipients' time stamps will not confuse `make'.
3294 Now you can create the patch using `diff -Naur'. Make sure to
3295 specify the scratch directory first and the newer directory second.
3297 Add to the top of the patch a note telling the user any `rm' and
3298 `mv' commands to run before applying the patch. Then you can remove
3299 the scratch directory.
3301 You can also shrink the patch size by using fewer lines of context,
3302 but bear in mind that `patch' typically needs at least two lines for
3303 proper operation when patches do not exactly match the input files.
3306 File: diffutils.info, Node: Invoking cmp, Next: Invoking diff, Prev: Making Patches, Up: Top
3311 The `cmp' command compares two files, and if they differ, tells the
3312 first byte and line number where they differ or reports that one file
3313 is a prefix of the other. Bytes and lines are numbered starting with
3314 1. The arguments of `cmp' are as follows:
3316 cmp OPTIONS... FROM-FILE [TO-FILE [FROM-SKIP [TO-SKIP]]]
3318 The file name `-' is always the standard input. `cmp' also uses the
3319 standard input if one file name is omitted. The FROM-SKIP and TO-SKIP
3320 operands specify how many bytes to ignore at the start of each file;
3321 they are equivalent to the `--ignore-initial=FROM-SKIP:TO-SKIP' option.
3323 By default, `cmp' outputs nothing if the two files have the same
3324 contents. If one file is a prefix of the other, `cmp' prints to
3325 standard error a message of the following form:
3327 cmp: EOF on SHORTER-FILE
3329 Otherwise, `cmp' prints to standard output a message of the
3332 FROM-FILE TO-FILE differ: char BYTE-NUMBER, line LINE-NUMBER
3334 The message formats can differ outside the POSIX locale. Also,
3335 POSIX allows the EOF message to be followed by a blank and some
3336 additional information.
3338 An exit status of 0 means no differences were found, 1 means some
3339 differences were found, and 2 means trouble.
3343 * cmp Options:: Summary of options to `cmp'.
3346 File: diffutils.info, Node: cmp Options, Up: Invoking cmp
3348 12.1 Options to `cmp'
3349 =====================
3351 Below is a summary of all of the options that GNU `cmp' accepts. Most
3352 options have two equivalent names, one of which is a single letter
3353 preceded by `-', and the other of which is a long name preceded by
3354 `--'. Multiple single letter options (unless they take an argument)
3355 can be combined into a single command line word: `-bl' is equivalent to
3360 Print the differing bytes. Display control bytes as a `^'
3361 followed by a letter of the alphabet and precede bytes that have
3362 the high bit set with `M-' (which stands for "meta").
3365 Output a summary of usage and then exit.
3368 `--ignore-initial=SKIP'
3369 Ignore any differences in the first SKIP bytes of the input files.
3370 Treat files with fewer than SKIP bytes as if they are empty. If
3371 SKIP is of the form `FROM-SKIP:TO-SKIP', skip the first FROM-SKIP
3372 bytes of the first input file and the first TO-SKIP bytes of the
3377 Output the (decimal) byte numbers and (octal) values of all
3378 differing bytes, instead of the default standard output. Also,
3379 output the EOF message if one file is shorter than the other.
3383 Compare at most COUNT input bytes.
3388 Do not print anything; only return an exit status indicating
3389 whether the files differ.
3393 Output version information and then exit.
3395 In the above table, operands that are byte counts are normally
3396 decimal, but may be preceded by `0' for octal and `0x' for hexadecimal.
3398 A byte count can be followed by a suffix to specify a multiple of
3399 that count; in this case an omitted integer is understood to be 1. A
3400 bare size letter, or one followed by `iB', specifies a multiple using
3401 powers of 1024. A size letter followed by `B' specifies powers of 1000
3402 instead. For example, `-n 4M' and `-n 4MiB' are equivalent to `-n
3403 4194304', whereas `-n 4MB' is equivalent to `-n 4000000'. This
3404 notation is upward compatible with the SI prefixes
3405 (http://www.bipm.fr/enus/3_SI/si-prefixes.html) for decimal multiples
3406 and with the IEC 60027-2 prefixes for binary multiples
3407 (http://physics.nist.gov/cuu/Units/binary.html).
3409 The following suffixes are defined. Large sizes like `1Y' may be
3410 rejected by your computer due to limitations of its arithmetic.
3413 kilobyte: 10^3 = 1000.
3418 kibibyte: 2^10 = 1024. `K' is special: the SI prefix is `k' and
3419 the IEC 60027-2 prefix is `Ki', but tradition and POSIX use `k' to
3423 megabyte: 10^6 = 1,000,000.
3427 mebibyte: 2^20 = 1,048,576.
3430 gigabyte: 10^9 = 1,000,000,000.
3434 gibibyte: 2^30 = 1,073,741,824.
3437 terabyte: 10^12 = 1,000,000,000,000.
3441 tebibyte: 2^40 = 1,099,511,627,776.
3444 petabyte: 10^15 = 1,000,000,000,000,000.
3448 pebibyte: 2^50 = 1,125,899,906,842,624.
3451 exabyte: 10^18 = 1,000,000,000,000,000,000.
3455 exbibyte: 2^60 = 1,152,921,504,606,846,976.
3458 zettabyte: 10^21 = 1,000,000,000,000,000,000,000
3462 2^70 = 1,180,591,620,717,411,303,424. (`Zi' is a GNU extension to
3466 yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000.
3470 2^80 = 1,208,925,819,614,629,174,706,176. (`Yi' is a GNU
3471 extension to IEC 60027-2.)
3474 File: diffutils.info, Node: Invoking diff, Next: Invoking diff3, Prev: Invoking cmp, Up: Top
3479 The format for running the `diff' command is:
3481 diff OPTIONS... FILES...
3483 In the simplest case, two file names FROM-FILE and TO-FILE are
3484 given, and `diff' compares the contents of FROM-FILE and TO-FILE. A
3485 file name of `-' stands for text read from the standard input. As a
3486 special case, `diff - -' compares a copy of standard input to itself.
3488 If one file is a directory and the other is not, `diff' compares the
3489 file in the directory whose name is that of the non-directory. The
3490 non-directory file must not be `-'.
3492 If two file names are given and both are directories, `diff'
3493 compares corresponding files in both directories, in alphabetical
3494 order; this comparison is not recursive unless the `--recursive' (`-r')
3495 option is given. `diff' never compares the actual contents of a
3496 directory as if it were a file. The file that is fully specified may
3497 not be standard input, because standard input is nameless and the
3498 notion of "file with the same name" does not apply.
3500 If the `--from-file=FILE' option is given, the number of file names
3501 is arbitrary, and FILE is compared to each named file. Similarly, if
3502 the `--to-file=FILE' option is given, each named file is compared to
3505 `diff' options begin with `-', so normally file names may not begin
3506 with `-'. However, `--' as an argument by itself treats the remaining
3507 arguments as file names even if they begin with `-'.
3509 An exit status of 0 means no differences were found, 1 means some
3510 differences were found, and 2 means trouble. Normally, differing
3511 binary files count as trouble, but this can be altered by using the
3512 `--text' (`-a') option, or the `-q' or `--brief' option.
3516 * diff Options:: Summary of options to `diff'.
3519 File: diffutils.info, Node: diff Options, Up: Invoking diff
3521 13.1 Options to `diff'
3522 ======================
3524 Below is a summary of all of the options that GNU `diff' accepts. Most
3525 options have two equivalent names, one of which is a single letter
3526 preceded by `-', and the other of which is a long name preceded by
3527 `--'. Multiple single letter options (unless they take an argument)
3528 can be combined into a single command line word: `-ac' is equivalent to
3529 `-a -c'. Long named options can be abbreviated to any unique prefix of
3530 their name. Brackets ([ and ]) indicate that an option takes an
3535 Treat all files as text and compare them line-by-line, even if they
3536 do not seem to be text. *Note Binary::.
3539 `--ignore-space-change'
3540 Ignore changes in amount of white space. *Note White Space::.
3543 `--ignore-blank-lines'
3544 Ignore changes that just insert or delete blank lines. *Note
3548 Read and write data in binary mode. *Note Binary::.
3551 Use the context output format, showing three lines of context.
3552 *Note Context Format::.
3556 Use the context output format, showing LINES (an integer) lines of
3557 context, or three if LINES is not given. *Note Context Format::.
3558 For proper operation, `patch' typically needs at least two lines of
3561 For compatibility `diff' also supports an obsolete option syntax
3562 `-LINES' that has effect when combined with `-c', `-p', or `-u'.
3563 New scripts should use `-U LINES' (`-C LINES') instead.
3565 `--changed-group-format=FORMAT'
3566 Use FORMAT to output a line group containing differing lines from
3567 both files in if-then-else format. *Note Line Group Formats::.
3571 Change the algorithm perhaps find a smaller set of changes. This
3572 makes `diff' slower (sometimes much slower). *Note diff
3577 Make merged `#ifdef' format output, conditional on the preprocessor
3578 macro NAME. *Note If-then-else::.
3582 Make output that is a valid `ed' script. *Note ed Scripts::.
3585 `--ignore-tab-expansion'
3586 Ignore changes due to tab expansion. *Note White Space::.
3590 Make output that looks vaguely like an `ed' script but has changes
3591 in the order they appear in the file. *Note Forward ed::.
3594 `--show-function-line=REGEXP'
3595 In context and unified format, for each hunk of differences, show
3596 some of the last preceding line that matches REGEXP. *Note
3597 Specified Headings::.
3600 Compare FILE to each operand; FILE may be a directory.
3603 Output a summary of usage and then exit.
3605 `--horizon-lines=LINES'
3606 Do not discard the last LINES lines of the common prefix and the
3607 first LINES lines of the common suffix. *Note diff Performance::.
3611 Ignore changes in case; consider upper- and lower-case letters
3612 equivalent. *Note Case Folding::.
3615 `--ignore-matching-lines=REGEXP'
3616 Ignore changes that just insert or delete lines that match REGEXP.
3617 *Note Specified Lines::.
3619 `--ignore-file-name-case'
3620 Ignore case when comparing file names. For example, recursive
3621 comparison of `d' to `e' might compare the contents of `d/Init'
3622 and `e/inIt'. At the top level, `diff d inIt' might compare the
3623 contents of `d/Init' and `inIt'. *Note Comparing Directories::.
3627 Pass the output through `pr' to paginate it. *Note Pagination::.
3631 Use LABEL instead of the file name in the context format (*note
3632 Context Format::) and unified format (*note Unified Format::)
3633 headers. *Note RCS::.
3636 Print only the left column of two common lines in side by side
3637 format. *Note Side by Side Format::.
3639 `--line-format=FORMAT'
3640 Use FORMAT to output all input lines in if-then-else format.
3641 *Note Line Formats::.
3645 Output RCS-format diffs; like `-f' except that each command
3646 specifies the number of lines affected. *Note RCS::.
3650 In directory comparison, if a file is found in only one directory,
3651 treat it as present but empty in the other directory. *Note
3652 Comparing Directories::.
3654 `--new-group-format=FORMAT'
3655 Use FORMAT to output a group of lines taken from just the second
3656 file in if-then-else format. *Note Line Group Formats::.
3658 `--new-line-format=FORMAT'
3659 Use FORMAT to output a line taken from just the second file in
3660 if-then-else format. *Note Line Formats::.
3662 `--old-group-format=FORMAT'
3663 Use FORMAT to output a group of lines taken from just the first
3664 file in if-then-else format. *Note Line Group Formats::.
3666 `--old-line-format=FORMAT'
3667 Use FORMAT to output a line taken from just the first file in
3668 if-then-else format. *Note Line Formats::.
3672 Show which C function each change is in. *Note C Function
3677 Report only whether the files differ, not the details of the
3678 differences. *Note Brief::.
3682 When comparing directories, recursively compare any subdirectories
3683 found. *Note Comparing Directories::.
3686 `--report-identical-files'
3687 Report when two files are the same. *Note Comparing Directories::.
3690 `--starting-file=FILE'
3691 When comparing directories, start with the file FILE. This is
3692 used for resuming an aborted comparison. *Note Comparing
3695 `--speed-large-files'
3696 Use heuristics to speed handling of large files that have numerous
3697 scattered small changes. *Note diff Performance::.
3699 `--strip-trailing-cr'
3700 Strip any trailing carriage return at the end of an input line.
3703 `--suppress-common-lines'
3704 Do not print common lines in side by side format. *Note Side by
3709 Expand tabs to spaces in the output, to preserve the alignment of
3710 tabs in the input files. *Note Tabs::.
3714 Output a tab rather than a space before the text of a line in
3715 normal or context format. This causes the alignment of tabs in
3716 the line to look normal. *Note Tabs::.
3719 Assume that tab stops are set every COLUMNS (default 8) print
3720 columns. *Note Tabs::.
3722 `--suppress-blank-empty'
3723 Suppress any blanks before newlines when printing the
3724 representation of an empty line, when outputting normal, context,
3725 or unified format. *Note Trailing Blanks::.
3728 Compare each operand to FILE; FILE may be a directory.
3731 Use the unified output format, showing three lines of context.
3732 *Note Unified Format::.
3734 `--unchanged-group-format=FORMAT'
3735 Use FORMAT to output a group of common lines taken from both files
3736 in if-then-else format. *Note Line Group Formats::.
3738 `--unchanged-line-format=FORMAT'
3739 Use FORMAT to output a line common to both files in if-then-else
3740 format. *Note Line Formats::.
3742 `--unidirectional-new-file'
3743 When comparing directories, if a file appears only in the second
3744 directory of the two, treat it as present but empty in the other.
3745 *Note Comparing Directories::.
3749 Use the unified output format, showing LINES (an integer) lines of
3750 context, or three if LINES is not given. *Note Unified Format::.
3751 For proper operation, `patch' typically needs at least two lines of
3754 On older systems, `diff' supports an obsolete option `-LINES' that
3755 has effect when combined with `-u'. POSIX 1003.1-2001 (*note
3756 Standards conformance::) does not allow this; use `-U LINES'
3761 Output version information and then exit.
3764 `--ignore-all-space'
3765 Ignore white space when comparing lines. *Note White Space::.
3769 Output at most COLUMNS (default 130) print columns per line in
3770 side by side format. *Note Side by Side Format::.
3774 When comparing directories, ignore files and subdirectories whose
3775 basenames match PATTERN. *Note Comparing Directories::.
3778 `--exclude-from=FILE'
3779 When comparing directories, ignore files and subdirectories whose
3780 basenames match any pattern contained in FILE. *Note Comparing
3785 Use the side by side output format. *Note Side by Side Format::.
3788 `--ignore-trailing-space'
3789 Ignore white space at line end. *Note White Space::.
3792 File: diffutils.info, Node: Invoking diff3, Next: Invoking patch, Prev: Invoking diff, Up: Top
3797 The `diff3' command compares three files and outputs descriptions of
3798 their differences. Its arguments are as follows:
3800 diff3 OPTIONS... MINE OLDER YOURS
3802 The files to compare are MINE, OLDER, and YOURS. At most one of
3803 these three file names may be `-', which tells `diff3' to read the
3804 standard input for that file.
3806 An exit status of 0 means `diff3' was successful, 1 means some
3807 conflicts were found, and 2 means trouble.
3811 * diff3 Options:: Summary of options to `diff3'.
3814 File: diffutils.info, Node: diff3 Options, Up: Invoking diff3
3816 14.1 Options to `diff3'
3817 =======================
3819 Below is a summary of all of the options that GNU `diff3' accepts.
3820 Multiple single letter options (unless they take an argument) can be
3821 combined into a single command line argument.
3825 Treat all files as text and compare them line-by-line, even if they
3826 do not appear to be text. *Note Binary::.
3830 Incorporate all unmerged changes from OLDER to YOURS into MINE,
3831 surrounding conflicts with bracket lines. *Note Marking
3834 `--diff-program=PROGRAM'
3835 Use the compatible comparison program PROGRAM to compare files
3840 Generate an `ed' script that incorporates all the changes from
3841 OLDER to YOURS into MINE. *Note Which Changes::.
3845 Like `-e', except bracket lines from overlapping changes' first
3846 and third files. *Note Marking Conflicts::. With `-E', an
3847 overlapping change looks like this:
3856 Output a summary of usage and then exit.
3859 Generate `w' and `q' commands at the end of the `ed' script for
3860 System V compatibility. This option must be combined with one of
3861 the `-AeExX3' options, and may not be combined with `-m'. *Note
3862 Saving the Changed File::.
3865 Use the label LABEL for the brackets output by the `-A', `-E' and
3866 `-X' options. This option may be given up to three times, one for
3867 each input file. The default labels are the names of the input
3868 files. Thus `diff3 --label X --label Y --label Z -m A B C' acts
3869 like `diff3 -m A B C', except that the output looks like it came
3870 from files named `X', `Y' and `Z' rather than from files named
3871 `A', `B' and `C'. *Note Marking Conflicts::.
3875 Apply the edit script to the first file and send the result to
3876 standard output. Unlike piping the output from `diff3' to `ed',
3877 this works even for binary files and incomplete lines. `-A' is
3878 assumed if no edit script option is specified. *Note Bypassing
3881 `--strip-trailing-cr'
3882 Strip any trailing carriage return at the end of an input line.
3887 Output a tab rather than two spaces before the text of a line in
3888 normal format. This causes the alignment of tabs in the line to
3889 look normal. *Note Tabs::.
3893 Output version information and then exit.
3897 Like `-e', except output only the overlapping changes. *Note
3901 Like `-E', except output only the overlapping changes. In other
3902 words, like `-x', except bracket changes as in `-E'. *Note
3903 Marking Conflicts::.
3907 Like `-e', except output only the nonoverlapping changes. *Note
3911 File: diffutils.info, Node: Invoking patch, Next: Invoking sdiff, Prev: Invoking diff3, Up: Top
3916 Normally `patch' is invoked like this:
3920 The full format for invoking `patch' is:
3922 patch OPTIONS... [ORIGFILE [PATCHFILE]]
3924 You can also specify where to read the patch from with the `-i
3925 PATCHFILE' or `--input=PATCHFILE' option. If you do not specify
3926 PATCHFILE, or if PATCHFILE is `-', `patch' reads the patch (that is,
3927 the `diff' output) from the standard input.
3929 If you do not specify an input file on the command line, `patch'
3930 tries to intuit from the "leading text" (any text in the patch that
3931 comes before the `diff' output) which file to edit. *Note Multiple
3934 By default, `patch' replaces the original input file with the
3935 patched version, possibly after renaming the original file into a
3936 backup file (*note Backup Names::, for a description of how `patch'
3937 names backup files). You can also specify where to put the output with
3938 the `-o FILE' or `--output=FILE' option; however, do not use this option
3939 if FILE is one of the input files.
3943 * patch Options:: Summary table of options to `patch'.
3946 File: diffutils.info, Node: patch Options, Up: Invoking patch
3948 15.1 Options to `patch'
3949 =======================
3951 Here is a summary of all of the options that GNU `patch' accepts.
3952 *Note patch and Tradition::, for which of these options are safe to use
3953 in older versions of `patch'.
3955 Multiple single-letter options that do not take an argument can be
3956 combined into a single command line argument with only one dash.
3960 Back up the original contents of each file, even if backups would
3961 normally not be made. *Note Backups::.
3965 Prepend PREFIX to backup file names. *Note Backup Names::.
3967 `--backup-if-mismatch'
3968 Back up the original contents of each file if the patch does not
3969 exactly match the file. This is the default behavior when not
3970 conforming to POSIX. *Note Backups::.
3973 Read and write all files in binary mode, except for standard output
3974 and `/dev/tty'. This option has no effect on POSIX-conforming
3975 systems like GNU/Linux. On systems where this option makes a
3976 difference, the patch should be generated by `diff -a --binary'.
3981 Interpret the patch file as a context diff. *Note patch Input::.
3984 `--directory=DIRECTORY'
3985 Make directory DIRECTORY the current directory for interpreting
3986 both file names in the patch file, and file names given as
3987 arguments to other options. *Note patch Directories::.
3991 Make merged if-then-else output using NAME. *Note If-then-else::.
3994 Print the results of applying the patches without actually changing
3995 any files. *Note Dry Runs::.
3999 Interpret the patch file as an `ed' script. *Note patch Input::.
4002 `--remove-empty-files'
4003 Remove output files that are empty after the patches have been
4004 applied. *Note Creating and Removing::.
4008 Assume that the user knows exactly what he or she is doing, and do
4009 not ask any questions. *Note patch Messages::.
4013 Set the maximum fuzz factor to LINES. *Note Inexact::.
4017 If NUM is positive, get input files from a revision control system
4018 as necessary; if zero, do not get the files; if negative, ask the
4019 user whether to get the files. *Note Revision Control::.
4022 Output a summary of usage and then exit.
4026 Read the patch from PATCHFILE rather than from standard input.
4027 *Note patch Options::.
4030 `--ignore-white-space'
4031 Let any sequence of blanks (spaces or tabs) in the patch file match
4032 any sequence of blanks in the input file. *Note Changed White
4037 Interpret the patch file as a normal diff. *Note patch Input::.
4041 Ignore patches that `patch' thinks are reversed or already applied.
4042 See also `-R'. *Note Reversed Patches::.
4044 `--no-backup-if-mismatch'
4045 Do not back up the original contents of files. This is the default
4046 behavior when conforming to POSIX. *Note Backups::.
4050 Use FILE as the output file name. *Note patch Options::.
4054 Set the file name strip count to NUMBER. *Note patch
4058 Conform to POSIX, as if the `POSIXLY_CORRECT' environment variable
4059 had been set. *Note patch and POSIX::.
4061 `--quoting-style=WORD'
4062 Use style WORD to quote names in diagnostics, as if the
4063 `QUOTING_STYLE' environment variable had been set to WORD. *Note
4064 patch Quoting Style::.
4067 `--reject-file=REJECT-FILE'
4068 Use REJECT-FILE as the reject file name. *Note Reject Names::.
4072 Assume that this patch was created with the old and new files
4073 swapped. *Note Reversed Patches::.
4078 Work silently unless an error occurs. *Note patch Messages::.
4082 Do not ask any questions. *Note patch Messages::.
4086 Set the modification and access times of patched files from time
4087 stamps given in context diff headers, assuming that the context
4088 diff headers use local time. *Note Patching Time Stamps::.
4092 Interpret the patch file as a unified diff. *Note patch Input::.
4096 Output version information and then exit.
4099 `--version=control=BACKUP-STYLE'
4100 Select the naming convention for backup file names. *Note Backup
4104 Print more diagnostics than usual. *Note patch Messages::.
4108 Set internal debugging flags. Of interest only to `patch'
4112 `--basename-prefix=PREFIX'
4113 Prepend PREFIX to base names of backup files. *Note Backup
4118 Use SUFFIX as the backup extension instead of `.orig' or `~'.
4119 *Note Backup Names::.
4123 Set the modification and access times of patched files from time
4124 stamps given in context diff headers, assuming that the context
4125 diff headers use UTC. *Note Patching Time Stamps::.
4129 File: diffutils.info, Node: Invoking sdiff, Next: Standards conformance, Prev: Invoking patch, Up: Top
4134 The `sdiff' command merges two files and interactively outputs the
4135 results. Its arguments are as follows:
4137 sdiff -o OUTFILE OPTIONS... FROM-FILE TO-FILE
4139 This merges FROM-FILE with TO-FILE, with output to OUTFILE. If
4140 FROM-FILE is a directory and TO-FILE is not, `sdiff' compares the file
4141 in FROM-FILE whose file name is that of TO-FILE, and vice versa.
4142 FROM-FILE and TO-FILE may not both be directories.
4144 `sdiff' options begin with `-', so normally FROM-FILE and TO-FILE
4145 may not begin with `-'. However, `--' as an argument by itself treats
4146 the remaining arguments as file names even if they begin with `-'. You
4147 may not use `-' as an input file.
4149 `sdiff' without `--output' (`-o') produces a side-by-side
4150 difference. This usage is obsolete; use the `--side-by-side' (`-y')
4151 option of `diff' instead.
4153 An exit status of 0 means no differences were found, 1 means some
4154 differences were found, and 2 means trouble.
4158 * sdiff Options:: Summary of options to `diff'.
4161 File: diffutils.info, Node: sdiff Options, Up: Invoking sdiff
4163 16.1 Options to `sdiff'
4164 =======================
4166 Below is a summary of all of the options that GNU `sdiff' accepts.
4167 Each option has two equivalent names, one of which is a single letter
4168 preceded by `-', and the other of which is a long name preceded by
4169 `--'. Multiple single letter options (unless they take an argument)
4170 can be combined into a single command line argument. Long named
4171 options can be abbreviated to any unique prefix of their name.
4175 Treat all files as text and compare them line-by-line, even if they
4176 do not appear to be text. *Note Binary::.
4179 `--ignore-space-change'
4180 Ignore changes in amount of white space. *Note White Space::.
4183 `--ignore-blank-lines'
4184 Ignore changes that just insert or delete blank lines. *Note
4189 Change the algorithm to perhaps find a smaller set of changes.
4190 This makes `sdiff' slower (sometimes much slower). *Note diff
4193 `--diff-program=PROGRAM'
4194 Use the compatible comparison program PROGRAM to compare files
4198 `--ignore-tab-expansion'
4199 Ignore changes due to tab expansion. *Note White Space::.
4202 Output a summary of usage and then exit.
4206 Ignore changes in case; consider upper- and lower-case to be the
4207 same. *Note Case Folding::.
4210 `--ignore-matching-lines=REGEXP'
4211 Ignore changes that just insert or delete lines that match REGEXP.
4212 *Note Specified Lines::.
4216 Print only the left column of two common lines. *Note Side by
4221 Put merged output into FILE. This option is required for merging.
4224 `--suppress-common-lines'
4225 Do not print common lines. *Note Side by Side Format::.
4227 `--speed-large-files'
4228 Use heuristics to speed handling of large files that have numerous
4229 scattered small changes. *Note diff Performance::.
4231 `--strip-trailing-cr'
4232 Strip any trailing carriage return at the end of an input line.
4237 Expand tabs to spaces in the output, to preserve the alignment of
4238 tabs in the input files. *Note Tabs::.
4241 Assume that tab stops are set every COLUMNS (default 8) print
4242 columns. *Note Tabs::.
4246 Output version information and then exit.
4250 Output at most COLUMNS (default 130) print columns per line.
4251 *Note Side by Side Format::. Note that for historical reasons,
4252 this option is `-W' in `diff', `-w' in `sdiff'.
4255 `--ignore-all-space'
4256 Ignore white space when comparing lines. *Note White Space::.
4257 Note that for historical reasons, this option is `-w' in `diff',
4261 `--ignore-trailing-space'
4262 Ignore white space at line end. *Note White Space::.
4265 File: diffutils.info, Node: Standards conformance, Next: Projects, Prev: Invoking sdiff, Up: Top
4267 17 Standards conformance
4268 ************************
4270 In a few cases, the GNU utilities' default behavior is incompatible
4271 with the POSIX standard. To suppress these incompatibilities, define
4272 the `POSIXLY_CORRECT' environment variable. Unless you are checking
4273 for POSIX conformance, you probably do not need to define
4276 Normally options and operands can appear in any order, and programs
4277 act as if all the options appear before any operands. For example,
4278 `diff lao tzu -C 2' acts like `diff -C 2 lao tzu', since `2' is an
4279 option-argument of `-C'. However, if the `POSIXLY_CORRECT' environment
4280 variable is set, options must appear before operands, unless otherwise
4281 specified for a particular command.
4283 Newer versions of POSIX are occasionally incompatible with older
4284 versions. For example, older versions of POSIX allowed the command
4285 `diff -c -10' to have the same meaning as `diff -C 10', but POSIX
4286 1003.1-2001 `diff' no longer allows digit-string options like `-10'.
4288 The GNU utilities normally conform to the version of POSIX that is
4289 standard for your system. To cause them to conform to a different
4290 version of POSIX, define the `_POSIX2_VERSION' environment variable to
4291 a value of the form YYYYMM specifying the year and month the standard
4292 was adopted. Two values are currently supported for `_POSIX2_VERSION':
4293 `199209' stands for POSIX 1003.2-1992, and `200112' stands for POSIX
4294 1003.1-2001. For example, if you are running older software that
4295 assumes an older version of POSIX and uses `diff -c -10', you can work
4296 around the compatibility problems by setting `_POSIX2_VERSION=199209'
4297 in your environment.
4300 File: diffutils.info, Node: Projects, Next: Copying This Manual, Prev: Standards conformance, Up: Top
4305 Here are some ideas for improving GNU `diff' and `patch'. The GNU
4306 project has identified some improvements as potential programming
4307 projects for volunteers. You can also help by reporting any bugs that
4310 If you are a programmer and would like to contribute something to the
4311 GNU project, please consider volunteering for one of these projects.
4312 If you are seriously contemplating work, please write to <gvc@gnu.org>
4313 to coordinate with other volunteers.
4317 * Shortcomings:: Suggested projects for improvements.
4318 * Bugs:: Reporting bugs.
4321 File: diffutils.info, Node: Shortcomings, Next: Bugs, Up: Projects
4323 18.1 Suggested Projects for Improving GNU `diff' and `patch'
4324 ============================================================
4326 One should be able to use GNU `diff' to generate a patch from any pair
4327 of directory trees, and given the patch and a copy of one such tree,
4328 use `patch' to generate a faithful copy of the other. Unfortunately,
4329 some changes to directory trees cannot be expressed using current patch
4330 formats; also, `patch' does not handle some of the existing formats.
4331 These shortcomings motivate the following suggested projects.
4335 * Internationalization:: Handling multibyte and varying-width characters.
4336 * Changing Structure:: Handling changes to the directory structure.
4337 * Special Files:: Handling symbolic links, device special files, etc.
4338 * Unusual File Names:: Handling file names that contain unusual characters.
4339 * Time Stamp Order:: Outputting diffs in time stamp order.
4340 * Ignoring Changes:: Ignoring certain changes while showing others.
4341 * Speedups:: Improving performance.
4344 File: diffutils.info, Node: Internationalization, Next: Changing Structure, Up: Shortcomings
4346 18.1.1 Handling Multibyte and Varying-Width Characters
4347 ------------------------------------------------------
4349 `diff', `diff3' and `sdiff' treat each line of input as a string of
4350 unibyte characters. This can mishandle multibyte characters in some
4351 cases. For example, when asked to ignore spaces, `diff' does not
4352 properly ignore a multibyte space character.
4354 Also, `diff' currently assumes that each byte is one column wide,
4355 and this assumption is incorrect in some locales, e.g., locales that
4356 use UTF-8 encoding. This causes problems with the `-y' or
4357 `--side-by-side' option of `diff'.
4359 These problems need to be fixed without unduly affecting the
4360 performance of the utilities in unibyte environments.
4362 The IBM GNU/Linux Technology Center Internationalization Team has
4363 proposed patches to support internationalized `diff'
4364 (http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz).
4365 Unfortunately, these patches are incomplete and are to an older version
4366 of `diff', so more work needs to be done in this area.
4369 File: diffutils.info, Node: Changing Structure, Next: Special Files, Prev: Internationalization, Up: Shortcomings
4371 18.1.2 Handling Changes to the Directory Structure
4372 --------------------------------------------------
4374 `diff' and `patch' do not handle some changes to directory structure.
4375 For example, suppose one directory tree contains a directory named `D'
4376 with some subsidiary files, and another contains a file with the same
4377 name `D'. `diff -r' does not output enough information for `patch' to
4378 transform the directory subtree into the file.
4380 There should be a way to specify that a file has been removed without
4381 having to include its entire contents in the patch file. There should
4382 also be a way to tell `patch' that a file was renamed, even if there is
4383 no way for `diff' to generate such information. There should be a way
4384 to tell `patch' that a file's time stamp has changed, even if its
4385 contents have not changed.
4387 These problems can be fixed by extending the `diff' output format to
4388 represent changes in directory structure, and extending `patch' to
4389 understand these extensions.
4392 File: diffutils.info, Node: Special Files, Next: Unusual File Names, Prev: Changing Structure, Up: Shortcomings
4394 18.1.3 Files that are Neither Directories Nor Regular Files
4395 -----------------------------------------------------------
4397 Some files are neither directories nor regular files: they are unusual
4398 files like symbolic links, device special files, named pipes, and
4399 sockets. Currently, `diff' treats symbolic links as if they were the
4400 pointed-to files, except that a recursive `diff' reports an error if it
4401 detects infinite loops of symbolic links (e.g., symbolic links to
4402 `..'). `diff' treats other special files like regular files if they
4403 are specified at the top level, but simply reports their presence when
4404 comparing directories. This means that `patch' cannot represent
4405 changes to such files. For example, if you change which file a
4406 symbolic link points to, `diff' outputs the difference between the two
4407 files, instead of the change to the symbolic link.
4409 `diff' should optionally report changes to special files specially,
4410 and `patch' should be extended to understand these extensions.
4413 File: diffutils.info, Node: Unusual File Names, Next: Time Stamp Order, Prev: Special Files, Up: Shortcomings
4415 18.1.4 File Names that Contain Unusual Characters
4416 -------------------------------------------------
4418 When a file name contains an unusual character like a newline or white
4419 space, `diff -r' generates a patch that `patch' cannot parse. The
4420 problem is with format of `diff' output, not just with `patch', because
4421 with odd enough file names one can cause `diff' to generate a patch
4422 that is syntactically correct but patches the wrong files. The format
4423 of `diff' output should be extended to handle all possible file names.
4426 File: diffutils.info, Node: Time Stamp Order, Next: Ignoring Changes, Prev: Unusual File Names, Up: Shortcomings
4428 18.1.5 Outputting Diffs in Time Stamp Order
4429 -------------------------------------------
4431 Applying `patch' to a multiple-file diff can result in files whose time
4432 stamps are out of order. GNU `patch' has options to restore the time
4433 stamps of the updated files (*note Patching Time Stamps::), but
4434 sometimes it is useful to generate a patch that works even if the
4435 recipient does not have GNU patch, or does not use these options. One
4436 way to do this would be to implement a `diff' option to output diffs in
4440 File: diffutils.info, Node: Ignoring Changes, Next: Speedups, Prev: Time Stamp Order, Up: Shortcomings
4442 18.1.6 Ignoring Certain Changes
4443 -------------------------------
4445 It would be nice to have a feature for specifying two strings, one in
4446 FROM-FILE and one in TO-FILE, which should be considered to match.
4447 Thus, if the two strings are `foo' and `bar', then if two lines differ
4448 only in that `foo' in file 1 corresponds to `bar' in file 2, the lines
4449 are treated as identical.
4451 It is not clear how general this feature can or should be, or what
4452 syntax should be used for it.
4454 A partial substitute is to filter one or both files before comparing,
4457 sed 's/foo/bar/g' file1 | diff - file2
4459 However, this outputs the filtered text, not the original.
4462 File: diffutils.info, Node: Speedups, Prev: Ignoring Changes, Up: Shortcomings
4464 18.1.7 Improving Performance
4465 ----------------------------
4467 When comparing two large directory structures, one of which was
4468 originally copied from the other with time stamps preserved (e.g., with
4469 `cp -pR'), it would greatly improve performance if an option told
4470 `diff' to assume that two files with the same size and time stamps have
4471 the same content. *Note diff Performance::.
4474 File: diffutils.info, Node: Bugs, Prev: Shortcomings, Up: Projects
4479 If you think you have found a bug in GNU `cmp', `diff', `diff3', or
4480 `sdiff', please report it by electronic mail to the GNU utilities bug
4482 (http://mail.gnu.org/mailman/listinfo/bug-gnu-utils)
4483 <bug-gnu-utils@gnu.org>. Please send bug reports for GNU `patch' to
4484 <bug-patch@gnu.org>. Send as precise a description of the problem as
4485 you can, including the output of the `--version' option and sample
4486 input files that produce the bug, if applicable. If you have a
4487 nontrivial fix for the bug, please send it as well. If you have a
4488 patch, please send it too. It may simplify the maintainer's job if the
4489 patch is relative to a recent test release, which you can find in the
4490 directory `ftp://alpha.gnu.org/gnu/diffutils/'.
4493 File: diffutils.info, Node: Copying This Manual, Next: Translations, Prev: Projects, Up: Top
4495 Appendix A Copying This Manual
4496 ******************************
4498 Version 1.3, 3 November 2008
4500 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
4503 Everyone is permitted to copy and distribute verbatim copies
4504 of this license document, but changing it is not allowed.
4508 The purpose of this License is to make a manual, textbook, or other
4509 functional and useful document "free" in the sense of freedom: to
4510 assure everyone the effective freedom to copy and redistribute it,
4511 with or without modifying it, either commercially or
4512 noncommercially. Secondarily, this License preserves for the
4513 author and publisher a way to get credit for their work, while not
4514 being considered responsible for modifications made by others.
4516 This License is a kind of "copyleft", which means that derivative
4517 works of the document must themselves be free in the same sense.
4518 It complements the GNU General Public License, which is a copyleft
4519 license designed for free software.
4521 We have designed this License in order to use it for manuals for
4522 free software, because free software needs free documentation: a
4523 free program should come with manuals providing the same freedoms
4524 that the software does. But this License is not limited to
4525 software manuals; it can be used for any textual work, regardless
4526 of subject matter or whether it is published as a printed book.
4527 We recommend this License principally for works whose purpose is
4528 instruction or reference.
4530 1. APPLICABILITY AND DEFINITIONS
4532 This License applies to any manual or other work, in any medium,
4533 that contains a notice placed by the copyright holder saying it
4534 can be distributed under the terms of this License. Such a notice
4535 grants a world-wide, royalty-free license, unlimited in duration,
4536 to use that work under the conditions stated herein. The
4537 "Document", below, refers to any such manual or work. Any member
4538 of the public is a licensee, and is addressed as "you". You
4539 accept the license if you copy, modify or distribute the work in a
4540 way requiring permission under copyright law.
4542 A "Modified Version" of the Document means any work containing the
4543 Document or a portion of it, either copied verbatim, or with
4544 modifications and/or translated into another language.
4546 A "Secondary Section" is a named appendix or a front-matter section
4547 of the Document that deals exclusively with the relationship of the
4548 publishers or authors of the Document to the Document's overall
4549 subject (or to related matters) and contains nothing that could
4550 fall directly within that overall subject. (Thus, if the Document
4551 is in part a textbook of mathematics, a Secondary Section may not
4552 explain any mathematics.) The relationship could be a matter of
4553 historical connection with the subject or with related matters, or
4554 of legal, commercial, philosophical, ethical or political position
4557 The "Invariant Sections" are certain Secondary Sections whose
4558 titles are designated, as being those of Invariant Sections, in
4559 the notice that says that the Document is released under this
4560 License. If a section does not fit the above definition of
4561 Secondary then it is not allowed to be designated as Invariant.
4562 The Document may contain zero Invariant Sections. If the Document
4563 does not identify any Invariant Sections then there are none.
4565 The "Cover Texts" are certain short passages of text that are
4566 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
4567 that says that the Document is released under this License. A
4568 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
4569 be at most 25 words.
4571 A "Transparent" copy of the Document means a machine-readable copy,
4572 represented in a format whose specification is available to the
4573 general public, that is suitable for revising the document
4574 straightforwardly with generic text editors or (for images
4575 composed of pixels) generic paint programs or (for drawings) some
4576 widely available drawing editor, and that is suitable for input to
4577 text formatters or for automatic translation to a variety of
4578 formats suitable for input to text formatters. A copy made in an
4579 otherwise Transparent file format whose markup, or absence of
4580 markup, has been arranged to thwart or discourage subsequent
4581 modification by readers is not Transparent. An image format is
4582 not Transparent if used for any substantial amount of text. A
4583 copy that is not "Transparent" is called "Opaque".
4585 Examples of suitable formats for Transparent copies include plain
4586 ASCII without markup, Texinfo input format, LaTeX input format,
4587 SGML or XML using a publicly available DTD, and
4588 standard-conforming simple HTML, PostScript or PDF designed for
4589 human modification. Examples of transparent image formats include
4590 PNG, XCF and JPG. Opaque formats include proprietary formats that
4591 can be read and edited only by proprietary word processors, SGML or
4592 XML for which the DTD and/or processing tools are not generally
4593 available, and the machine-generated HTML, PostScript or PDF
4594 produced by some word processors for output purposes only.
4596 The "Title Page" means, for a printed book, the title page itself,
4597 plus such following pages as are needed to hold, legibly, the
4598 material this License requires to appear in the title page. For
4599 works in formats which do not have any title page as such, "Title
4600 Page" means the text near the most prominent appearance of the
4601 work's title, preceding the beginning of the body of the text.
4603 The "publisher" means any person or entity that distributes copies
4604 of the Document to the public.
4606 A section "Entitled XYZ" means a named subunit of the Document
4607 whose title either is precisely XYZ or contains XYZ in parentheses
4608 following text that translates XYZ in another language. (Here XYZ
4609 stands for a specific section name mentioned below, such as
4610 "Acknowledgements", "Dedications", "Endorsements", or "History".)
4611 To "Preserve the Title" of such a section when you modify the
4612 Document means that it remains a section "Entitled XYZ" according
4615 The Document may include Warranty Disclaimers next to the notice
4616 which states that this License applies to the Document. These
4617 Warranty Disclaimers are considered to be included by reference in
4618 this License, but only as regards disclaiming warranties: any other
4619 implication that these Warranty Disclaimers may have is void and
4620 has no effect on the meaning of this License.
4624 You may copy and distribute the Document in any medium, either
4625 commercially or noncommercially, provided that this License, the
4626 copyright notices, and the license notice saying this License
4627 applies to the Document are reproduced in all copies, and that you
4628 add no other conditions whatsoever to those of this License. You
4629 may not use technical measures to obstruct or control the reading
4630 or further copying of the copies you make or distribute. However,
4631 you may accept compensation in exchange for copies. If you
4632 distribute a large enough number of copies you must also follow
4633 the conditions in section 3.
4635 You may also lend copies, under the same conditions stated above,
4636 and you may publicly display copies.
4638 3. COPYING IN QUANTITY
4640 If you publish printed copies (or copies in media that commonly
4641 have printed covers) of the Document, numbering more than 100, and
4642 the Document's license notice requires Cover Texts, you must
4643 enclose the copies in covers that carry, clearly and legibly, all
4644 these Cover Texts: Front-Cover Texts on the front cover, and
4645 Back-Cover Texts on the back cover. Both covers must also clearly
4646 and legibly identify you as the publisher of these copies. The
4647 front cover must present the full title with all words of the
4648 title equally prominent and visible. You may add other material
4649 on the covers in addition. Copying with changes limited to the
4650 covers, as long as they preserve the title of the Document and
4651 satisfy these conditions, can be treated as verbatim copying in
4654 If the required texts for either cover are too voluminous to fit
4655 legibly, you should put the first ones listed (as many as fit
4656 reasonably) on the actual cover, and continue the rest onto
4659 If you publish or distribute Opaque copies of the Document
4660 numbering more than 100, you must either include a
4661 machine-readable Transparent copy along with each Opaque copy, or
4662 state in or with each Opaque copy a computer-network location from
4663 which the general network-using public has access to download
4664 using public-standard network protocols a complete Transparent
4665 copy of the Document, free of added material. If you use the
4666 latter option, you must take reasonably prudent steps, when you
4667 begin distribution of Opaque copies in quantity, to ensure that
4668 this Transparent copy will remain thus accessible at the stated
4669 location until at least one year after the last time you
4670 distribute an Opaque copy (directly or through your agents or
4671 retailers) of that edition to the public.
4673 It is requested, but not required, that you contact the authors of
4674 the Document well before redistributing any large number of
4675 copies, to give them a chance to provide you with an updated
4676 version of the Document.
4680 You may copy and distribute a Modified Version of the Document
4681 under the conditions of sections 2 and 3 above, provided that you
4682 release the Modified Version under precisely this License, with
4683 the Modified Version filling the role of the Document, thus
4684 licensing distribution and modification of the Modified Version to
4685 whoever possesses a copy of it. In addition, you must do these
4686 things in the Modified Version:
4688 A. Use in the Title Page (and on the covers, if any) a title
4689 distinct from that of the Document, and from those of
4690 previous versions (which should, if there were any, be listed
4691 in the History section of the Document). You may use the
4692 same title as a previous version if the original publisher of
4693 that version gives permission.
4695 B. List on the Title Page, as authors, one or more persons or
4696 entities responsible for authorship of the modifications in
4697 the Modified Version, together with at least five of the
4698 principal authors of the Document (all of its principal
4699 authors, if it has fewer than five), unless they release you
4700 from this requirement.
4702 C. State on the Title page the name of the publisher of the
4703 Modified Version, as the publisher.
4705 D. Preserve all the copyright notices of the Document.
4707 E. Add an appropriate copyright notice for your modifications
4708 adjacent to the other copyright notices.
4710 F. Include, immediately after the copyright notices, a license
4711 notice giving the public permission to use the Modified
4712 Version under the terms of this License, in the form shown in
4715 G. Preserve in that license notice the full lists of Invariant
4716 Sections and required Cover Texts given in the Document's
4719 H. Include an unaltered copy of this License.
4721 I. Preserve the section Entitled "History", Preserve its Title,
4722 and add to it an item stating at least the title, year, new
4723 authors, and publisher of the Modified Version as given on
4724 the Title Page. If there is no section Entitled "History" in
4725 the Document, create one stating the title, year, authors,
4726 and publisher of the Document as given on its Title Page,
4727 then add an item describing the Modified Version as stated in
4728 the previous sentence.
4730 J. Preserve the network location, if any, given in the Document
4731 for public access to a Transparent copy of the Document, and
4732 likewise the network locations given in the Document for
4733 previous versions it was based on. These may be placed in
4734 the "History" section. You may omit a network location for a
4735 work that was published at least four years before the
4736 Document itself, or if the original publisher of the version
4737 it refers to gives permission.
4739 K. For any section Entitled "Acknowledgements" or "Dedications",
4740 Preserve the Title of the section, and preserve in the
4741 section all the substance and tone of each of the contributor
4742 acknowledgements and/or dedications given therein.
4744 L. Preserve all the Invariant Sections of the Document,
4745 unaltered in their text and in their titles. Section numbers
4746 or the equivalent are not considered part of the section
4749 M. Delete any section Entitled "Endorsements". Such a section
4750 may not be included in the Modified Version.
4752 N. Do not retitle any existing section to be Entitled
4753 "Endorsements" or to conflict in title with any Invariant
4756 O. Preserve any Warranty Disclaimers.
4758 If the Modified Version includes new front-matter sections or
4759 appendices that qualify as Secondary Sections and contain no
4760 material copied from the Document, you may at your option
4761 designate some or all of these sections as invariant. To do this,
4762 add their titles to the list of Invariant Sections in the Modified
4763 Version's license notice. These titles must be distinct from any
4764 other section titles.
4766 You may add a section Entitled "Endorsements", provided it contains
4767 nothing but endorsements of your Modified Version by various
4768 parties--for example, statements of peer review or that the text
4769 has been approved by an organization as the authoritative
4770 definition of a standard.
4772 You may add a passage of up to five words as a Front-Cover Text,
4773 and a passage of up to 25 words as a Back-Cover Text, to the end
4774 of the list of Cover Texts in the Modified Version. Only one
4775 passage of Front-Cover Text and one of Back-Cover Text may be
4776 added by (or through arrangements made by) any one entity. If the
4777 Document already includes a cover text for the same cover,
4778 previously added by you or by arrangement made by the same entity
4779 you are acting on behalf of, you may not add another; but you may
4780 replace the old one, on explicit permission from the previous
4781 publisher that added the old one.
4783 The author(s) and publisher(s) of the Document do not by this
4784 License give permission to use their names for publicity for or to
4785 assert or imply endorsement of any Modified Version.
4787 5. COMBINING DOCUMENTS
4789 You may combine the Document with other documents released under
4790 this License, under the terms defined in section 4 above for
4791 modified versions, provided that you include in the combination
4792 all of the Invariant Sections of all of the original documents,
4793 unmodified, and list them all as Invariant Sections of your
4794 combined work in its license notice, and that you preserve all
4795 their Warranty Disclaimers.
4797 The combined work need only contain one copy of this License, and
4798 multiple identical Invariant Sections may be replaced with a single
4799 copy. If there are multiple Invariant Sections with the same name
4800 but different contents, make the title of each such section unique
4801 by adding at the end of it, in parentheses, the name of the
4802 original author or publisher of that section if known, or else a
4803 unique number. Make the same adjustment to the section titles in
4804 the list of Invariant Sections in the license notice of the
4807 In the combination, you must combine any sections Entitled
4808 "History" in the various original documents, forming one section
4809 Entitled "History"; likewise combine any sections Entitled
4810 "Acknowledgements", and any sections Entitled "Dedications". You
4811 must delete all sections Entitled "Endorsements."
4813 6. COLLECTIONS OF DOCUMENTS
4815 You may make a collection consisting of the Document and other
4816 documents released under this License, and replace the individual
4817 copies of this License in the various documents with a single copy
4818 that is included in the collection, provided that you follow the
4819 rules of this License for verbatim copying of each of the
4820 documents in all other respects.
4822 You may extract a single document from such a collection, and
4823 distribute it individually under this License, provided you insert
4824 a copy of this License into the extracted document, and follow
4825 this License in all other respects regarding verbatim copying of
4828 7. AGGREGATION WITH INDEPENDENT WORKS
4830 A compilation of the Document or its derivatives with other
4831 separate and independent documents or works, in or on a volume of
4832 a storage or distribution medium, is called an "aggregate" if the
4833 copyright resulting from the compilation is not used to limit the
4834 legal rights of the compilation's users beyond what the individual
4835 works permit. When the Document is included in an aggregate, this
4836 License does not apply to the other works in the aggregate which
4837 are not themselves derivative works of the Document.
4839 If the Cover Text requirement of section 3 is applicable to these
4840 copies of the Document, then if the Document is less than one half
4841 of the entire aggregate, the Document's Cover Texts may be placed
4842 on covers that bracket the Document within the aggregate, or the
4843 electronic equivalent of covers if the Document is in electronic
4844 form. Otherwise they must appear on printed covers that bracket
4845 the whole aggregate.
4849 Translation is considered a kind of modification, so you may
4850 distribute translations of the Document under the terms of section
4851 4. Replacing Invariant Sections with translations requires special
4852 permission from their copyright holders, but you may include
4853 translations of some or all Invariant Sections in addition to the
4854 original versions of these Invariant Sections. You may include a
4855 translation of this License, and all the license notices in the
4856 Document, and any Warranty Disclaimers, provided that you also
4857 include the original English version of this License and the
4858 original versions of those notices and disclaimers. In case of a
4859 disagreement between the translation and the original version of
4860 this License or a notice or disclaimer, the original version will
4863 If a section in the Document is Entitled "Acknowledgements",
4864 "Dedications", or "History", the requirement (section 4) to
4865 Preserve its Title (section 1) will typically require changing the
4870 You may not copy, modify, sublicense, or distribute the Document
4871 except as expressly provided under this License. Any attempt
4872 otherwise to copy, modify, sublicense, or distribute it is void,
4873 and will automatically terminate your rights under this License.
4875 However, if you cease all violation of this License, then your
4876 license from a particular copyright holder is reinstated (a)
4877 provisionally, unless and until the copyright holder explicitly
4878 and finally terminates your license, and (b) permanently, if the
4879 copyright holder fails to notify you of the violation by some
4880 reasonable means prior to 60 days after the cessation.
4882 Moreover, your license from a particular copyright holder is
4883 reinstated permanently if the copyright holder notifies you of the
4884 violation by some reasonable means, this is the first time you have
4885 received notice of violation of this License (for any work) from
4886 that copyright holder, and you cure the violation prior to 30 days
4887 after your receipt of the notice.
4889 Termination of your rights under this section does not terminate
4890 the licenses of parties who have received copies or rights from
4891 you under this License. If your rights have been terminated and
4892 not permanently reinstated, receipt of a copy of some or all of
4893 the same material does not give you any rights to use it.
4895 10. FUTURE REVISIONS OF THIS LICENSE
4897 The Free Software Foundation may publish new, revised versions of
4898 the GNU Free Documentation License from time to time. Such new
4899 versions will be similar in spirit to the present version, but may
4900 differ in detail to address new problems or concerns. See
4901 `http://www.gnu.org/copyleft/'.
4903 Each version of the License is given a distinguishing version
4904 number. If the Document specifies that a particular numbered
4905 version of this License "or any later version" applies to it, you
4906 have the option of following the terms and conditions either of
4907 that specified version or of any later version that has been
4908 published (not as a draft) by the Free Software Foundation. If
4909 the Document does not specify a version number of this License,
4910 you may choose any version ever published (not as a draft) by the
4911 Free Software Foundation. If the Document specifies that a proxy
4912 can decide which future versions of this License can be used, that
4913 proxy's public statement of acceptance of a version permanently
4914 authorizes you to choose that version for the Document.
4918 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
4919 World Wide Web server that publishes copyrightable works and also
4920 provides prominent facilities for anybody to edit those works. A
4921 public wiki that anybody can edit is an example of such a server.
4922 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
4923 site means any set of copyrightable works thus published on the MMC
4926 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
4927 license published by Creative Commons Corporation, a not-for-profit
4928 corporation with a principal place of business in San Francisco,
4929 California, as well as future copyleft versions of that license
4930 published by that same organization.
4932 "Incorporate" means to publish or republish a Document, in whole or
4933 in part, as part of another Document.
4935 An MMC is "eligible for relicensing" if it is licensed under this
4936 License, and if all works that were first published under this
4937 License somewhere other than this MMC, and subsequently
4938 incorporated in whole or in part into the MMC, (1) had no cover
4939 texts or invariant sections, and (2) were thus incorporated prior
4940 to November 1, 2008.
4942 The operator of an MMC Site may republish an MMC contained in the
4943 site under CC-BY-SA on the same site at any time before August 1,
4944 2009, provided the MMC is eligible for relicensing.
4947 ADDENDUM: How to use this License for your documents
4948 ====================================================
4950 To use this License in a document you have written, include a copy of
4951 the License in the document and put the following copyright and license
4952 notices just after the title page:
4954 Copyright (C) YEAR YOUR NAME.
4955 Permission is granted to copy, distribute and/or modify this document
4956 under the terms of the GNU Free Documentation License, Version 1.3
4957 or any later version published by the Free Software Foundation;
4958 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
4959 Texts. A copy of the license is included in the section entitled ``GNU
4960 Free Documentation License''.
4962 If you have Invariant Sections, Front-Cover Texts and Back-Cover
4963 Texts, replace the "with...Texts." line with this:
4965 with the Invariant Sections being LIST THEIR TITLES, with
4966 the Front-Cover Texts being LIST, and with the Back-Cover Texts
4969 If you have Invariant Sections without Cover Texts, or some other
4970 combination of the three, merge those two alternatives to suit the
4973 If your document contains nontrivial examples of program code, we
4974 recommend releasing these examples in parallel under your choice of
4975 free software license, such as the GNU General Public License, to
4976 permit their use in free software.
4979 File: diffutils.info, Node: Translations, Next: Index, Prev: Copying This Manual, Up: Top
4981 Appendix B Translations of This Manual
4982 **************************************
4984 Nishio Futoshi of the GNUjdoc project has prepared a Japanese
4985 translation of this manual. Its most recent version can be found at
4986 `http://openlab.ring.gr.jp/gnujdoc/cvsweb/cvsweb.cgi/gnujdoc/'.
4989 File: diffutils.info, Node: Index, Prev: Translations, Up: Top
4997 * ! output format: Context. (line 6)
4998 * +- output format: Unified Format. (line 6)
4999 * < output format: Normal. (line 6)
5000 * <<<<<<< for marking conflicts: Marking Conflicts. (line 6)
5001 * _POSIX2_VERSION: Standards conformance.
5003 * aligning tab stops: Tabs. (line 6)
5004 * alternate file names: Alternate Names. (line 6)
5005 * backup file names: Backup Names. (line 6)
5006 * backup file strategy: Backups. (line 6)
5007 * binary file diff: Binary. (line 6)
5008 * blank and tab difference suppression: White Space. (line 6)
5009 * blank line difference suppression: Blank Lines. (line 6)
5010 * brief difference reports: Brief. (line 6)
5011 * bug reports: Bugs. (line 6)
5012 * C function headings: C Function Headings. (line 6)
5013 * C if-then-else output format: If-then-else. (line 6)
5014 * case difference suppression: Case Folding. (line 6)
5015 * ClearCase: Revision Control. (line 6)
5016 * cmp invocation: Invoking cmp. (line 6)
5017 * cmp options: cmp Options. (line 6)
5018 * columnar output: Side by Side. (line 6)
5019 * common mistakes with patches: Avoiding Common Mistakes.
5021 * comparing three files: Comparing Three Files.
5023 * conflict: diff3 Merging. (line 26)
5024 * conflict marking: Marking Conflicts. (line 6)
5025 * context output format: Context. (line 6)
5026 * creating files: Creating and Removing.
5028 * diagnostics from patch: patch Messages. (line 6)
5029 * diff invocation: Invoking diff. (line 6)
5030 * diff merging: Interactive Merging. (line 6)
5031 * diff options: diff Options. (line 6)
5032 * diff sample input: Sample diff Input. (line 6)
5033 * diff3 hunks: diff3 Hunks. (line 6)
5034 * diff3 invocation: Invoking diff3. (line 6)
5035 * diff3 options: diff3 Options. (line 6)
5036 * diff3 sample input: Sample diff3 Input. (line 6)
5037 * directories and patch: patch Directories. (line 6)
5038 * directory structure changes: Changing Structure. (line 6)
5039 * dry runs for patch: Dry Runs. (line 6)
5040 * ed script output format: ed Scripts. (line 6)
5041 * EDITOR: Merge Commands. (line 50)
5042 * empty files, removing: Creating and Removing.
5044 * exabyte, definition of: cmp Options. (line 106)
5045 * exbibyte, definition of: cmp Options. (line 110)
5046 * file name alternates: Alternate Names. (line 6)
5047 * file names with unusual characters: Unusual File Names. (line 6)
5048 * format of diff output: Output Formats. (line 6)
5049 * format of diff3 output: Comparing Three Files.
5051 * formats for if-then-else line groups: Line Group Formats. (line 6)
5052 * forward ed script output format: Forward ed. (line 6)
5053 * full lines: Incomplete Lines. (line 6)
5054 * function headings, C: C Function Headings. (line 6)
5055 * fuzz factor when patching: Inexact. (line 6)
5056 * gibibyte, definition of: cmp Options. (line 89)
5057 * gigabyte, definition of: cmp Options. (line 85)
5058 * headings: Sections. (line 6)
5059 * hunks: Hunks. (line 6)
5060 * hunks for diff3: diff3 Hunks. (line 6)
5061 * if-then-else output format: If-then-else. (line 6)
5062 * ifdef output format: If-then-else. (line 6)
5063 * imperfect patch application: Imperfect. (line 6)
5064 * incomplete line merging: Merging Incomplete Lines.
5066 * incomplete lines: Incomplete Lines. (line 6)
5067 * inexact patches: Inexact. (line 6)
5068 * inhibit messages from patch: More or Fewer Messages.
5070 * interactive merging: Interactive Merging. (line 6)
5071 * introduction: Comparison. (line 6)
5072 * intuiting file names from patches: Multiple Patches. (line 6)
5073 * invoking cmp: Invoking cmp. (line 6)
5074 * invoking diff: Invoking diff. (line 6)
5075 * invoking diff3: Invoking diff3. (line 6)
5076 * invoking patch: Invoking patch. (line 6)
5077 * invoking sdiff: Invoking sdiff. (line 6)
5078 * keyboard input to patch: patch and Keyboard Input.
5080 * kibibyte, definition of: cmp Options. (line 73)
5081 * kilobyte, definition of: cmp Options. (line 68)
5082 * LC_COLLATE: Comparing Directories.
5084 * LC_NUMERIC: Line Group Formats. (line 144)
5085 * LC_TIME: Detailed Context. (line 12)
5086 * line formats: Line Formats. (line 6)
5087 * line group formats: Line Group Formats. (line 6)
5088 * mebibyte, definition of: cmp Options. (line 82)
5089 * megabyte, definition of: cmp Options. (line 78)
5090 * merge commands: Merge Commands. (line 6)
5091 * merged diff3 format: Bypassing ed. (line 6)
5092 * merged output format: If-then-else. (line 6)
5093 * merging from a common ancestor: diff3 Merging. (line 6)
5094 * merging interactively: Merge Commands. (line 6)
5095 * messages from patch: patch Messages. (line 6)
5096 * multibyte characters: Internationalization.
5098 * multiple patches: Multiple Patches. (line 6)
5099 * newline treatment by diff: Incomplete Lines. (line 6)
5100 * normal output format: Normal. (line 6)
5101 * options for cmp: cmp Options. (line 6)
5102 * options for diff: diff Options. (line 6)
5103 * options for diff3: diff3 Options. (line 6)
5104 * options for patch: patch Options. (line 6)
5105 * options for sdiff: sdiff Options. (line 6)
5106 * output formats: Output Formats. (line 6)
5107 * overlap: diff3 Merging. (line 26)
5108 * overlapping change, selection of: Which Changes. (line 6)
5109 * overview of diff and patch: Overview. (line 6)
5110 * paginating diff output: Pagination. (line 6)
5111 * patch consumer tips: Tips for Patch Consumers.
5113 * patch input format: patch Input. (line 6)
5114 * patch invocation: Invoking patch. (line 6)
5115 * patch messages and questions: patch Messages. (line 6)
5116 * patch options: patch Options. (line 6)
5117 * patch producer tips: Tips for Patch Producers.
5119 * patch, common mistakes: Avoiding Common Mistakes.
5121 * PATCH_GET: Revision Control. (line 13)
5122 * PATCH_VERSION_CONTROL: Backup Names. (line 21)
5123 * patches, shrinking: Generating Smaller Patches.
5125 * patching directories: patch Directories. (line 6)
5126 * pebibyte, definition of: cmp Options. (line 103)
5127 * performance of diff: diff Performance. (line 6)
5128 * petabyte, definition of: cmp Options. (line 99)
5129 * POSIX <1>: Standards conformance.
5131 * POSIX: patch and POSIX. (line 6)
5132 * POSIXLY_CORRECT <1>: Standards conformance.
5134 * POSIXLY_CORRECT: patch and POSIX. (line 6)
5135 * projects for directories: Shortcomings. (line 6)
5136 * quoting style: patch Quoting Style. (line 6)
5137 * QUOTING_STYLE: patch Quoting Style. (line 30)
5138 * RCS: Revision Control. (line 6)
5139 * RCS script output format: RCS. (line 6)
5140 * regular expression matching headings: Specified Headings. (line 6)
5141 * regular expression suppression: Specified Lines. (line 6)
5142 * reject file names: Reject Names. (line 6)
5143 * removing empty files: Creating and Removing.
5145 * reporting bugs: Bugs. (line 6)
5146 * reversed patches: Reversed Patches. (line 6)
5147 * revision control: Revision Control. (line 6)
5148 * sample input for diff: Sample diff Input. (line 6)
5149 * sample input for diff3: Sample diff3 Input. (line 6)
5150 * SCCS: Revision Control. (line 6)
5151 * script output formats: Scripts. (line 6)
5152 * sdiff invocation: Invoking sdiff. (line 6)
5153 * sdiff options: sdiff Options. (line 6)
5154 * sdiff output format: sdiff Option Summary.
5156 * section headings: Sections. (line 6)
5157 * side by side: Side by Side. (line 6)
5158 * side by side format: Side by Side Format. (line 6)
5159 * SIMPLE_BACKUP_SUFFIX: Backup Names. (line 12)
5160 * special files: Special Files. (line 6)
5161 * specified headings: Specified Headings. (line 6)
5162 * summarizing which files differ: Brief. (line 6)
5163 * System V diff3 compatibility: Saving the Changed File.
5165 * tab and blank difference suppression: White Space. (line 6)
5166 * tab stop alignment: Tabs. (line 6)
5167 * tebibyte, definition of: cmp Options. (line 96)
5168 * terabyte, definition of: cmp Options. (line 92)
5169 * testing patch: Dry Runs. (line 6)
5170 * text versus binary diff: Binary. (line 6)
5171 * time stamp format, context diffs: Detailed Context. (line 12)
5172 * time stamp format, unified diffs: Detailed Unified. (line 12)
5173 * time stamps on patched files: Patching Time Stamps.
5175 * traditional patch: patch and Tradition. (line 6)
5176 * trailing blanks: Trailing Blanks. (line 6)
5177 * two-column output: Side by Side. (line 6)
5178 * unified output format: Unified Format. (line 6)
5179 * unmerged change: Which Changes. (line 6)
5180 * varying-width characters: Internationalization.
5182 * verbose messages from patch: More or Fewer Messages.
5184 * version control: Revision Control. (line 6)
5185 * VERSION_CONTROL <1>: Backup Names. (line 21)
5186 * VERSION_CONTROL: Revision Control. (line 22)
5187 * white space in patches: Changed White Space. (line 6)
5188 * yottabyte, definition of: cmp Options. (line 121)
5189 * zettabyte, definition of: cmp Options. (line 113)
5195 Node: Overview
\7f3646
5196 Node: Comparison
\7f7275
5198 Node: White Space
\7f11420
5199 Node: Blank Lines
\7f13259
5200 Node: Specified Lines
\7f14251
5201 Node: Case Folding
\7f15377
5203 Node: Binary
\7f17117
5204 Node: Output Formats
\7f21202
5205 Node: Sample diff Input
\7f21927
5206 Node: Context
\7f23426
5207 Node: Context Format
\7f25003
5208 Node: Example Context
\7f25795
5209 Node: Less Context
\7f27302
5210 Node: Detailed Context
\7f28491
5211 Node: Unified Format
\7f30689
5212 Node: Example Unified
\7f31486
5213 Node: Detailed Unified
\7f32524
5214 Node: Sections
\7f34171
5215 Node: Specified Headings
\7f34930
5216 Node: C Function Headings
\7f36481
5217 Node: Alternate Names
\7f37326
5218 Node: Side by Side
\7f38240
5219 Node: Side by Side Format
\7f40389
5220 Node: Example Side by Side
\7f41290
5221 Node: Normal
\7f42630
5222 Node: Example Normal
\7f43630
5223 Node: Detailed Normal
\7f44366
5224 Node: Scripts
\7f46105
5225 Node: ed Scripts
\7f46510
5226 Node: Example ed
\7f47716
5227 Node: Detailed ed
\7f48166
5228 Node: Forward ed
\7f49925
5230 Node: If-then-else
\7f51916
5231 Node: Line Group Formats
\7f53594
5232 Node: Line Formats
\7f59470
5233 Node: Example If-then-else
\7f62740
5234 Node: Detailed If-then-else
\7f63819
5235 Node: Incomplete Lines
\7f65702
5236 Node: Comparing Directories
\7f67339
5237 Node: Adjusting Output
\7f71383
5239 Node: Trailing Blanks
\7f73504
5240 Node: Pagination
\7f74730
5241 Node: diff Performance
\7f75198
5242 Node: Comparing Three Files
\7f78285
5243 Node: Sample diff3 Input
\7f79163
5244 Node: Example diff3 Normal
\7f80111
5245 Node: Detailed diff3 Normal
\7f81161
5246 Node: diff3 Hunks
\7f82920
5247 Node: diff3 Merging
\7f84216
5248 Node: Which Changes
\7f86460
5249 Node: Marking Conflicts
\7f87860
5250 Node: Bypassing ed
\7f90316
5251 Node: Merging Incomplete Lines
\7f91659
5252 Node: Saving the Changed File
\7f92385
5253 Node: Interactive Merging
\7f93001
5254 Node: sdiff Option Summary
\7f93710
5255 Node: Merge Commands
\7f94913
5256 Node: Merging with patch
\7f96202
5257 Node: patch Input
\7f98574
5258 Node: Revision Control
\7f99256
5259 Node: Imperfect
\7f100426
5260 Node: Changed White Space
\7f101574
5261 Node: Reversed Patches
\7f102371
5262 Node: Inexact
\7f103835
5263 Node: Dry Runs
\7f107393
5264 Node: Creating and Removing
\7f108257
5265 Node: Patching Time Stamps
\7f109306
5266 Node: Multiple Patches
\7f111505
5267 Node: patch Directories
\7f114168
5268 Node: Backups
\7f115793
5269 Node: Backup Names
\7f116858
5270 Ref: Backup Names-Footnote-1
\7f119825
5271 Node: Reject Names
\7f119952
5272 Node: patch Messages
\7f120541
5273 Node: More or Fewer Messages
\7f121601
5274 Node: patch and Keyboard Input
\7f122232
5275 Node: patch Quoting Style
\7f123261
5276 Node: patch and POSIX
\7f124411
5277 Node: patch and Tradition
\7f125251
5278 Node: Making Patches
\7f128707
5279 Node: Tips for Patch Producers
\7f129533
5280 Node: Tips for Patch Consumers
\7f130789
5281 Node: Avoiding Common Mistakes
\7f131426
5282 Node: Generating Smaller Patches
\7f133951
5283 Node: Invoking cmp
\7f135712
5284 Node: cmp Options
\7f137135
5285 Node: Invoking diff
\7f140627
5286 Node: diff Options
\7f142483
5287 Node: Invoking diff3
\7f151185
5288 Node: diff3 Options
\7f151823
5289 Node: Invoking patch
\7f154856
5290 Node: patch Options
\7f156064
5291 Node: Invoking sdiff
\7f161291
5292 Node: sdiff Options
\7f162434
5293 Node: Standards conformance
\7f165405
5294 Node: Projects
\7f167151
5295 Node: Shortcomings
\7f167862
5296 Node: Internationalization
\7f168964
5297 Node: Changing Structure
\7f170130
5298 Node: Special Files
\7f171234
5299 Node: Unusual File Names
\7f172346
5300 Node: Time Stamp Order
\7f172985
5301 Node: Ignoring Changes
\7f173628
5302 Node: Speedups
\7f174398
5304 Node: Copying This Manual
\7f175715
5305 Node: Translations
\7f200854
5306 Node: Index
\7f201226