source: trunk/third/diffutils/diff.info-3 @ 16149

Revision 16149, 46.0 KB checked in by rbasch, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16148, which included commits to RCS files with non-trunk default branches.
RevLine 
[16148]1This is Info file diff.info, produced by Makeinfo-1.55 from the input
2file ./diff.texi.
3
4   This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
5commands for showing the differences between text files and the `patch'
6command for using their output to update files.
7
8   Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
9
10   Permission is granted to make and distribute verbatim copies of this
11manual provided the copyright notice and this permission notice are
12preserved on all copies.
13
14   Permission is granted to copy and distribute modified versions of
15this manual under the conditions for verbatim copying, provided that
16the entire resulting derived work is distributed under the terms of a
17permission notice identical to this one.
18
19   Permission is granted to copy and distribute translations of this
20manual into another language, under the above conditions for modified
21versions, except that this permission notice may be stated in a
22translation approved by the Foundation.
23
24
25File: diff.info,  Node: Making Patches,  Next: Invoking cmp,  Prev: Merging with patch,  Up: Top
26
27Tips for Making Patch Distributions
28***********************************
29
30   Here are some things you should keep in mind if you are going to
31distribute patches for updating a software package.
32
33   Make sure you have specified the file names correctly, either in a
34context diff header or with an `Index:' line.  If you are patching
35files in a subdirectory, be sure to tell the patch user to specify a
36`-p' or `--strip' option as needed.  Take care to not send out reversed
37patches, since these make people wonder whether they have already
38applied the patch.
39
40   To save people from partially applying a patch before other patches
41that should have gone before it, you can make the first patch in the
42patch file update a file with a name like `patchlevel.h' or
43`version.c', which contains a patch level or version number.  If the
44input file contains the wrong version number, `patch' will complain
45immediately.
46
47   An even clearer way to prevent this problem is to put a `Prereq:'
48line before the patch.  If the leading text in the patch file contains a
49line that starts with `Prereq:', `patch' takes the next word from that
50line (normally a version number) and checks whether the next input file
51contains that word, preceded and followed by either white space or a
52newline.  If not, `patch' prompts you for confirmation before
53proceeding.  This makes it difficult to accidentally apply patches in
54the wrong order.
55
56   Since `patch' does not handle incomplete lines properly, make sure
57that all the source files in your program end with a newline whenever
58you release a version.
59
60   To create a patch that changes an older version of a package into a
61newer version, first make a copy of the older version in a scratch
62directory.  Typically you do that by unpacking a `tar' or `shar'
63archive of the older version.
64
65   You might be able to reduce the size of the patch by renaming or
66removing some files before making the patch.  If the older version of
67the package contains any files that the newer version does not, or if
68any files have been renamed between the two versions, make a list of
69`rm' and `mv' commands for the user to execute in the old version
70directory before applying the patch.  Then run those commands yourself
71in the scratch directory.
72
73   If there are any files that you don't need to include in the patch
74because they can easily be rebuilt from other files (for example,
75`TAGS' and output from `yacc' and `makeinfo'), replace the versions in
76the scratch directory with the newer versions, using `rm' and `ln' or
77`cp'.
78
79   Now you can create the patch.  The de-facto standard `diff' format
80for patch distributions is context format with two lines of context,
81produced by giving `diff' the `-C 2' option.  Do not use less than two
82lines of context, because `patch' typically needs at least two lines
83for proper operation.  Give `diff' the `-P' option in case the newer
84version of the package contains any files that the older one does not.
85Make sure to specify the scratch directory first and the newer
86directory second.
87
88   Add to the top of the patch a note telling the user any `rm' and
89`mv' commands to run before applying the patch.  Then you can remove
90the scratch directory.
91
92
93File: diff.info,  Node: Invoking cmp,  Next: Invoking diff,  Prev: Making Patches,  Up: Top
94
95Invoking `cmp'
96**************
97
98   The `cmp' command compares two files, and if they differ, tells the
99first byte and line number where they differ.  Its arguments are as
100follows:
101
102     cmp OPTIONS... FROM-FILE [TO-FILE]
103
104   The file name `-' is always the standard input.  `cmp' also uses the
105standard input if one file name is omitted.
106
107   An exit status of 0 means no differences were found, 1 means some
108differences were found, and 2 means trouble.
109
110* Menu:
111
112* cmp Options::         Summary of options to `cmp'.
113
114
115File: diff.info,  Node: cmp Options,  Up: Invoking cmp
116
117Options to `cmp'
118================
119
120   Below is a summary of all of the options that GNU `cmp' accepts.
121Most options have two equivalent names, one of which is a single letter
122preceded by `-', and the other of which is a long name preceded by
123`--'.  Multiple single letter options (unless they take an argument)
124can be combined into a single command line word: `-cl' is equivalent to
125`-c -l'.
126
127`-c'
128     Print the differing characters.  Display control characters as a
129     `^' followed by a letter of the alphabet and precede characters
130     that have the high bit set with `M-' (which stands for "meta").
131
132`--ignore-initial=BYTES'
133     Ignore any differences in the the first BYTES bytes of the input
134     files.  Treat files with fewer than BYTES bytes as if they are
135     empty.
136
137`-l'
138     Print the (decimal) offsets and (octal) values of all differing
139     bytes.
140
141`--print-chars'
142     Print the differing characters.  Display control characters as a
143     `^' followed by a letter of the alphabet and precede characters
144     that have the high bit set with `M-' (which stands for "meta").
145
146`--quiet'
147`-s'
148`--silent'
149     Do not print anything; only return an exit status indicating
150     whether the files differ.
151
152`--verbose'
153     Print the (decimal) offsets and (octal) values of all differing
154     bytes.
155
156`-v'
157`--version'
158     Output the version number of `cmp'.
159
160
161File: diff.info,  Node: Invoking diff,  Next: Invoking diff3,  Prev: Invoking cmp,  Up: Top
162
163Invoking `diff'
164***************
165
166   The format for running the `diff' command is:
167
168     diff OPTIONS... FROM-FILE TO-FILE
169
170   In the simplest case, `diff' compares the contents of the two files
171FROM-FILE and TO-FILE.  A file name of `-' stands for text read from
172the standard input.  As a special case, `diff - -' compares a copy of
173standard input to itself.
174
175   If FROM-FILE is a directory and TO-FILE is not, `diff' compares the
176file in FROM-FILE whose file name is that of TO-FILE, and vice versa.
177The non-directory file must not be `-'.
178
179   If both FROM-FILE and TO-FILE are directories, `diff' compares
180corresponding files in both directories, in alphabetical order; this
181comparison is not recursive unless the `-r' or `--recursive' option is
182given.  `diff' never compares the actual contents of a directory as if
183it were a file.  The file that is fully specified may not be standard
184input, because standard input is nameless and the notion of "file with
185the same name" does not apply.
186
187   `diff' options begin with `-', so normally FROM-FILE and TO-FILE may
188not begin with `-'.  However, `--' as an argument by itself treats the
189remaining arguments as file names even if they begin with `-'.
190
191   An exit status of 0 means no differences were found, 1 means some
192differences were found, and 2 means trouble.
193
194* Menu:
195
196* diff Options::        Summary of options to `diff'.
197
198
199File: diff.info,  Node: diff Options,  Up: Invoking diff
200
201Options to `diff'
202=================
203
204   Below is a summary of all of the options that GNU `diff' accepts.
205Most options have two equivalent names, one of which is a single letter
206preceded by `-', and the other of which is a long name preceded by
207`--'.  Multiple single letter options (unless they take an argument)
208can be combined into a single command line word: `-ac' is equivalent to
209`-a -c'.  Long named options can be abbreviated to any unique prefix of
210their name.  Brackets ([ and ]) indicate that an option takes an
211optional argument.
212
213`-LINES'
214     Show LINES (an integer) lines of context.  This option does not
215     specify an output format by itself; it has no effect unless it is
216     combined with `-c' (*note Context Format::.) or `-u' (*note
217     Unified Format::.).  This option is obsolete.  For proper
218     operation, `patch' typically needs at least two lines of context.
219
220`-a'
221     Treat all files as text and compare them line-by-line, even if they
222     do not seem to be text.  *Note Binary::.
223
224`-b'
225     Ignore changes in amount of white space.  *Note White Space::.
226
227`-B'
228     Ignore changes that just insert or delete blank lines.  *Note
229     Blank Lines::.
230
231`--binary'
232     Read and write data in binary mode.  *Note Binary::.
233
234`--brief'
235     Report only whether the files differ, not the details of the
236     differences.  *Note Brief::.
237
238`-c'
239     Use the context output format.  *Note Context Format::.
240
241`-C LINES'
242`--context[=LINES]'
243     Use the context output format, showing LINES (an integer) lines of
244     context, or three if LINES is not given.  *Note Context Format::.
245     For proper operation, `patch' typically needs at least two lines of
246     context.
247
248`--changed-group-format=FORMAT'
249     Use FORMAT to output a line group containing differing lines from
250     both files in if-then-else format.  *Note Line Group Formats::.
251
252`-d'
253     Change the algorithm perhaps find a smaller set of changes.  This
254     makes `diff' slower (sometimes much slower).  *Note diff
255     Performance::.
256
257`-D NAME'
258     Make merged `#ifdef' format output, conditional on the preprocessor
259     macro NAME.  *Note If-then-else::.
260
261`-e'
262`--ed'
263     Make output that is a valid `ed' script.  *Note ed Scripts::.
264
265`--exclude=PATTERN'
266     When comparing directories, ignore files and subdirectories whose
267     basenames match PATTERN.  *Note Comparing Directories::.
268
269`--exclude-from=FILE'
270     When comparing directories, ignore files and subdirectories whose
271     basenames match any pattern contained in FILE.  *Note Comparing
272     Directories::.
273
274`--expand-tabs'
275     Expand tabs to spaces in the output, to preserve the alignment of
276     tabs in the input files.  *Note Tabs::.
277
278`-f'
279     Make output that looks vaguely like an `ed' script but has changes
280     in the order they appear in the file.  *Note Forward ed::.
281
282`-F REGEXP'
283     In context and unified format, for each hunk of differences, show
284     some of the last preceding line that matches REGEXP.  *Note
285     Specified Headings::.
286
287`--forward-ed'
288     Make output that looks vaguely like an `ed' script but has changes
289     in the order they appear in the file.  *Note Forward ed::.
290
291`-h'
292     This option currently has no effect; it is present for Unix
293     compatibility.
294
295`-H'
296     Use heuristics to speed handling of large files that have numerous
297     scattered small changes.  *Note diff Performance::.
298
299`--horizon-lines=LINES'
300     Do not discard the last LINES lines of the common prefix and the
301     first LINES lines of the common suffix.  *Note diff Performance::.
302
303`-i'
304     Ignore changes in case; consider upper- and lower-case letters
305     equivalent.  *Note Case Folding::.
306
307`-I REGEXP'
308     Ignore changes that just insert or delete lines that match REGEXP.
309     *Note Specified Folding::.
310
311`--ifdef=NAME'
312     Make merged if-then-else output using NAME.  *Note If-then-else::.
313
314`--ignore-all-space'
315     Ignore white space when comparing lines.  *Note White Space::.
316
317`--ignore-blank-lines'
318     Ignore changes that just insert or delete blank lines.  *Note
319     Blank Lines::.
320
321`--ignore-case'
322     Ignore changes in case; consider upper- and lower-case to be the
323     same.  *Note Case Folding::.
324
325`--ignore-matching-lines=REGEXP'
326     Ignore changes that just insert or delete lines that match REGEXP.
327     *Note Specified Folding::.
328
329`--ignore-space-change'
330     Ignore changes in amount of white space.  *Note White Space::.
331
332`--initial-tab'
333     Output a tab rather than a space before the text of a line in
334     normal or context format.  This causes the alignment of tabs in
335     the line to look normal.  *Note Tabs::.
336
337`-l'
338     Pass the output through `pr' to paginate it.  *Note Pagination::.
339
340`-L LABEL'
341     Use LABEL instead of the file name in the context format (*note
342     Context Format::.) and unified format (*note Unified Format::.)
343     headers.  *Note RCS::.
344
345`--label=LABEL'
346     Use LABEL instead of the file name in the context format (*note
347     Context Format::.) and unified format (*note Unified Format::.)
348     headers.
349
350`--left-column'
351     Print only the left column of two common lines in side by side
352     format.  *Note Side by Side Format::.
353
354`--line-format=FORMAT'
355     Use FORMAT to output all input lines in if-then-else format.
356     *Note Line Formats::.
357
358`--minimal'
359     Change the algorithm to perhaps find a smaller set of changes.
360     This makes `diff' slower (sometimes much slower).  *Note diff
361     Performance::.
362
363`-n'
364     Output RCS-format diffs; like `-f' except that each command
365     specifies the number of lines affected.  *Note RCS::.
366
367`-N'
368`--new-file'
369     In directory comparison, if a file is found in only one directory,
370     treat it as present but empty in the other directory.  *Note
371     Comparing Directories::.
372
373`--new-group-format=FORMAT'
374     Use FORMAT to output a group of lines taken from just the second
375     file in if-then-else format.  *Note Line Group Formats::.
376
377`--new-line-format=FORMAT'
378     Use FORMAT to output a line taken from just the second file in
379     if-then-else format.  *Note Line Formats::.
380
381`--old-group-format=FORMAT'
382     Use FORMAT to output a group of lines taken from just the first
383     file in if-then-else format.  *Note Line Group Formats::.
384
385`--old-line-format=FORMAT'
386     Use FORMAT to output a line taken from just the first file in
387     if-then-else format.  *Note Line Formats::.
388
389`-p'
390     Show which C function each change is in.  *Note C Function
391     Headings::.
392
393`-P'
394     When comparing directories, if a file appears only in the second
395     directory of the two, treat it as present but empty in the other.
396     *Note Comparing Directories::.
397
398`--paginate'
399     Pass the output through `pr' to paginate it.  *Note Pagination::.
400
401`-q'
402     Report only whether the files differ, not the details of the
403     differences.  *Note Brief::.
404
405`-r'
406     When comparing directories, recursively compare any subdirectories
407     found.  *Note Comparing Directories::.
408
409`--rcs'
410     Output RCS-format diffs; like `-f' except that each command
411     specifies the number of lines affected.  *Note RCS::.
412
413`--recursive'
414     When comparing directories, recursively compare any subdirectories
415     found.  *Note Comparing Directories::.
416
417`--report-identical-files'
418     Report when two files are the same.  *Note Comparing Directories::.
419
420`-s'
421     Report when two files are the same.  *Note Comparing Directories::.
422
423`-S FILE'
424     When comparing directories, start with the file FILE.  This is
425     used for resuming an aborted comparison.  *Note Comparing
426     Directories::.
427
428`--sdiff-merge-assist'
429     Print extra information to help `sdiff'.  `sdiff' uses this option
430     when it runs `diff'.  This option is not intended for users to use
431     directly.
432
433`--show-c-function'
434     Show which C function each change is in.  *Note C Function
435     Headings::.
436
437`--show-function-line=REGEXP'
438     In context and unified format, for each hunk of differences, show
439     some of the last preceding line that matches REGEXP.  *Note
440     Specified Headings::.
441
442`--side-by-side'
443     Use the side by side output format.  *Note Side by Side Format::.
444
445`--speed-large-files'
446     Use heuristics to speed handling of large files that have numerous
447     scattered small changes.  *Note diff Performance::.
448
449`--starting-file=FILE'
450     When comparing directories, start with the file FILE.  This is
451     used for resuming an aborted comparison.  *Note Comparing
452     Directories::.
453
454`--suppress-common-lines'
455     Do not print common lines in side by side format.  *Note Side by
456     Side Format::.
457
458`-t'
459     Expand tabs to spaces in the output, to preserve the alignment of
460     tabs in the input files.  *Note Tabs::.
461
462`-T'
463     Output a tab rather than a space before the text of a line in
464     normal or context format.  This causes the alignment of tabs in
465     the line to look normal.  *Note Tabs::.
466
467`--text'
468     Treat all files as text and compare them line-by-line, even if they
469     do not appear to be text.  *Note Binary::.
470
471`-u'
472     Use the unified output format.  *Note Unified Format::.
473
474`--unchanged-group-format=FORMAT'
475     Use FORMAT to output a group of common lines taken from both files
476     in if-then-else format.  *Note Line Group Formats::.
477
478`--unchanged-line-format=FORMAT'
479     Use FORMAT to output a line common to both files in if-then-else
480     format.  *Note Line Formats::.
481
482`--unidirectional-new-file'
483     When comparing directories, if a file appears only in the second
484     directory of the two, treat it as present but empty in the other.
485     *Note Comparing Directories::.
486
487`-U LINES'
488`--unified[=LINES]'
489     Use the unified output format, showing LINES (an integer) lines of
490     context, or three if LINES is not given.  *Note Unified Format::.
491     For proper operation, `patch' typically needs at least two lines of
492     context.
493
494`-v'
495`--version'
496     Output the version number of `diff'.
497
498`-w'
499     Ignore white space when comparing lines.  *Note White Space::.
500
501`-W COLUMNS'
502`--width=COLUMNS'
503     Use an output width of COLUMNS in side by side format.  *Note Side
504     by Side Format::.
505
506`-x PATTERN'
507     When comparing directories, ignore files and subdirectories whose
508     basenames match PATTERN.  *Note Comparing Directories::.
509
510`-X FILE'
511     When comparing directories, ignore files and subdirectories whose
512     basenames match any pattern contained in FILE.  *Note Comparing
513     Directories::.
514
515`-y'
516     Use the side by side output format.  *Note Side by Side Format::.
517
518
519File: diff.info,  Node: Invoking diff3,  Next: Invoking patch,  Prev: Invoking diff,  Up: Top
520
521Invoking `diff3'
522****************
523
524   The `diff3' command compares three files and outputs descriptions of
525their differences.  Its arguments are as follows:
526
527     diff3 OPTIONS... MINE OLDER YOURS
528
529   The files to compare are MINE, OLDER, and YOURS.  At most one of
530these three file names may be `-', which tells `diff3' to read the
531standard input for that file.
532
533   An exit status of 0 means `diff3' was successful, 1 means some
534conflicts were found, and 2 means trouble.
535
536* Menu:
537
538* diff3 Options::               Summary of options to `diff3'.
539
540
541File: diff.info,  Node: diff3 Options,  Up: Invoking diff3
542
543Options to `diff3'
544==================
545
546   Below is a summary of all of the options that GNU `diff3' accepts.
547Multiple single letter options (unless they take an argument) can be
548combined into a single command line argument.
549
550`-a'
551     Treat all files as text and compare them line-by-line, even if they
552     do not appear to be text.  *Note Binary::.
553
554`-A'
555     Incorporate all changes from OLDER to YOURS into MINE, surrounding
556     all conflicts with bracket lines.  *Note Marking Conflicts::.
557
558`-e'
559     Generate an `ed' script that incorporates all the changes from
560     OLDER to YOURS into MINE.  *Note Which Changes::.
561
562`-E'
563     Like `-e', except bracket lines from overlapping changes' first
564     and third files.  *Note Marking Conflicts::.  With `-e', an
565     overlapping change looks like this:
566
567          <<<<<<< MINE
568          lines from MINE
569          =======
570          lines from YOURS
571          >>>>>>> YOURS
572
573`--ed'
574     Generate an `ed' script that incorporates all the changes from
575     OLDER to YOURS into MINE.  *Note Which Changes::.
576
577`--easy-only'
578     Like `-e', except output only the nonoverlapping changes.  *Note
579     Which Changes::.
580
581`-i'
582     Generate `w' and `q' commands at the end of the `ed' script for
583     System V compatibility.  This option must be combined with one of
584     the `-AeExX3' options, and may not be combined with `-m'.  *Note
585     Saving the Changed File::.
586
587`--initial-tab'
588     Output a tab rather than two spaces before the text of a line in
589     normal format.  This causes the alignment of tabs in the line to
590     look normal.  *Note Tabs::.
591
592`-L LABEL'
593`--label=LABEL'
594     Use the label LABEL for the brackets output by the `-A', `-E' and
595     `-X' options.  This option may be given up to three times, one for
596     each input file.  The default labels are the names of the input
597     files.  Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A
598     B C', except that the output looks like it came from files named
599     `X', `Y' and `Z' rather than from files named `A', `B' and `C'.
600     *Note Marking Conflicts::.
601
602`-m'
603`--merge'
604     Apply the edit script to the first file and send the result to
605     standard output.  Unlike piping the output from `diff3' to `ed',
606     this works even for binary files and incomplete lines.  `-A' is
607     assumed if no edit script option is specified.  *Note Bypassing
608     ed::.
609
610`--overlap-only'
611     Like `-e', except output only the overlapping changes.  *Note
612     Which Changes::.
613
614`--show-all'
615     Incorporate all unmerged changes from OLDER to YOURS into MINE,
616     surrounding all overlapping changes with bracket lines.  *Note
617     Marking Conflicts::.
618
619`--show-overlap'
620     Like `-e', except bracket lines from overlapping changes' first
621     and third files.  *Note Marking Conflicts::.
622
623`-T'
624     Output a tab rather than two spaces before the text of a line in
625     normal format.  This causes the alignment of tabs in the line to
626     look normal.  *Note Tabs::.
627
628`--text'
629     Treat all files as text and compare them line-by-line, even if they
630     do not appear to be text.  *Note Binary::.
631
632`-v'
633`--version'
634     Output the version number of `diff3'.
635
636`-x'
637     Like `-e', except output only the overlapping changes.  *Note
638     Which Changes::.
639
640`-X'
641     Like `-E', except output only the overlapping changes.  In other
642     words, like `-x', except bracket changes as in `-E'.  *Note
643     Marking Conflicts::.
644
645`-3'
646     Like `-e', except output only the nonoverlapping changes.  *Note
647     Which Changes::.
648
649
650File: diff.info,  Node: Invoking patch,  Next: Invoking sdiff,  Prev: Invoking diff3,  Up: Top
651
652Invoking `patch'
653****************
654
655   Normally `patch' is invoked like this:
656
657     patch <PATCHFILE
658
659   The full format for invoking `patch' is:
660
661     patch OPTIONS... [ORIGFILE [PATCHFILE]] [+ OPTIONS... [ORIGFILE]]...
662
663   If you do not specify PATCHFILE, or if PATCHFILE is `-', `patch'
664reads the patch (that is, the `diff' output) from the standard input.
665
666   You can specify one or more of the original files as ORIG arguments;
667each one and options for interpreting it is separated from the others
668with a `+'.  *Note Multiple Patches::, for more information.
669
670   If you do not specify an input file on the command line, `patch'
671tries to figure out from the "leading text" (any text in the patch that
672comes before the `diff' output) which file to edit.  In the header of a
673context or unified diff, `patch' looks in lines beginning with `***',
674`---', or `+++'; among those, it chooses the shortest name of an
675existing file.  Otherwise, if there is an `Index:' line in the leading
676text, `patch' tries to use the file name from that line.  If `patch'
677cannot figure out the name of an existing file from the leading text,
678it prompts you for the name of the file to patch.
679
680   If the input file does not exist or is read-only, and a suitable RCS
681or SCCS file exists, `patch' attempts to check out or get the file
682before proceeding.
683
684   By default, `patch' replaces the original input file with the
685patched version, after renaming the original file into a backup file
686(*note Backups::., for a description of how `patch' names backup
687files).  You can also specify where to put the output with the `-o
688OUTPUT-FILE' or `--output=OUTPUT-FILE' option.
689
690* Menu:
691
692* patch Directories::   Changing directory and stripping directories.
693* Backups::             Backup file names.
694* Rejects::             Reject file names.
695* patch Options::       Summary table of options to `patch'.
696
697
698File: diff.info,  Node: patch Directories,  Next: Backups,  Up: Invoking patch
699
700Applying Patches in Other Directories
701=====================================
702
703   The `-d DIRECTORY' or `--directory=DIRECTORY' option to `patch'
704makes directory DIRECTORY the current directory for interpreting both
705file names in the patch file, and file names given as arguments to
706other options (such as `-B' and `-o').  For example, while in a news
707reading program, you can patch a file in the `/usr/src/emacs' directory
708directly from the article containing the patch like this:
709
710     | patch -d /usr/src/emacs
711
712   Sometimes the file names given in a patch contain leading
713directories, but you keep your files in a directory different from the
714one given in the patch.  In those cases, you can use the `-p[NUMBER]'
715or `--strip[=NUMBER]' option to set the file name strip count to
716NUMBER.  The strip count tells `patch' how many slashes, along with the
717directory names between them, to strip from the front of file names.
718`-p' with no NUMBER given is equivalent to `-p0'.  By default, `patch'
719strips off all leading directories, leaving just the base file names,
720except that when a file name given in the patch is a relative file name
721and all of its leading directories already exist, `patch' does not
722strip off the leading directory.  (A "relative" file name is one that
723does not start with a slash.)
724
725   `patch' looks for each file (after any slashes have been stripped)
726in the current directory, or if you used the `-d DIRECTORY' option, in
727that directory.
728
729   For example, suppose the file name in the patch file is
730`/gnu/src/emacs/etc/NEWS'.  Using `-p' or `-p0' gives the entire file
731name unmodified, `-p1' gives `gnu/src/emacs/etc/NEWS' (no leading
732slash), `-p4' gives `etc/NEWS', and not specifying `-p' at all gives
733`NEWS'.
734
735
736File: diff.info,  Node: Backups,  Next: Rejects,  Prev: patch Directories,  Up: Invoking patch
737
738Backup File Names
739=================
740
741   Normally, `patch' renames an original input file into a backup file
742by appending to its name the extension `.orig', or `~' on systems that
743do not support long file names.  The `-b BACKUP-SUFFIX' or
744`--suffix=BACKUP-SUFFIX' option uses BACKUP-SUFFIX as the backup
745extension instead.
746
747   Alternately, you can specify the extension for backup files with the
748`SIMPLE_BACKUP_SUFFIX' environment variable, which the options override.
749
750   `patch' can also create numbered backup files the way GNU Emacs
751does.  With this method, instead of having a single backup of each file,
752`patch' makes a new backup file name each time it patches a file.  For
753example, the backups of a file named `sink' would be called,
754successively, `sink.~1~', `sink.~2~', `sink.~3~', etc.
755
756   The `-V BACKUP-STYLE' or `--version-control=BACKUP-STYLE' option
757takes as an argument a method for creating backup file names.  You can
758alternately control the type of backups that `patch' makes with the
759`VERSION_CONTROL' environment variable, which the `-V' option
760overrides.  The value of the `VERSION_CONTROL' environment variable and
761the argument to the `-V' option are like the GNU Emacs
762`version-control' variable (*note emacs: Backups., for more information
763on backup versions in Emacs).  They also recognize synonyms that are
764more descriptive.  The valid values are listed below; unique
765abbreviations are acceptable.
766
767`t'
768`numbered'
769     Always make numbered backups.
770
771`nil'
772`existing'
773     Make numbered backups of files that already have them, simple
774     backups of the others.  This is the default.
775
776`never'
777`simple'
778     Always make simple backups.
779
780   Alternately, you can tell `patch' to prepend a prefix, such as a
781directory name, to produce backup file names.  The `-B BACKUP-PREFIX'
782or `--prefix=BACKUP-PREFIX' option makes backup files by prepending
783BACKUP-PREFIX to them.  If you use this option, `patch' ignores any
784`-b' option that you give.
785
786   If the backup file already exists, `patch' creates a new backup file
787name by changing the first lowercase letter in the last component of
788the file name into uppercase.  If there are no more lowercase letters
789in the name, it removes the first character from the name.  It repeats
790this process until it comes up with a backup file name that does not
791already exist.
792
793   If you specify the output file with the `-o' option, that file is
794the one that is backed up, not the input file.
795
796
797File: diff.info,  Node: Rejects,  Next: patch Options,  Prev: Backups,  Up: Invoking patch
798
799Reject File Names
800=================
801
802   The names for reject files (files containing patches that `patch'
803could not find a place to apply) are normally the name of the output
804file with `.rej' appended (or `#' on systems that do not support long
805file names).
806
807   Alternatively, you can tell `patch' to place all of the rejected
808patches in a single file.  The `-r REJECT-FILE' or
809`--reject-file=REJECT-FILE' option uses REJECT-FILE as the reject file
810name.
811
812
813File: diff.info,  Node: patch Options,  Prev: Rejects,  Up: Invoking patch
814
815Options to `patch'
816==================
817
818   Here is a summary of all of the options that `patch' accepts.  Older
819versions of `patch' do not accept long-named options or the `-t', `-E',
820or `-V' options.
821
822   Multiple single-letter options that do not take an argument can be
823combined into a single command line argument (with only one dash).
824Brackets ([ and ]) indicate that an option takes an optional argument.
825
826`-b BACKUP-SUFFIX'
827     Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
828     `~'.  *Note Backups::.
829
830`-B BACKUP-PREFIX'
831     Use BACKUP-PREFIX as a prefix to the backup file name.  If this
832     option is specified, any `-b' option is ignored.  *Note Backups::.
833
834`--batch'
835     Do not ask any questions.  *Note patch Messages::.
836
837`-c'
838`--context'
839     Interpret the patch file as a context diff.  *Note patch Input::.
840
841`-d DIRECTORY'
842`--directory=DIRECTORY'
843     Makes directory DIRECTORY the current directory for interpreting
844     both file names in the patch file, and file names given as
845     arguments to other options.  *Note patch Directories::.
846
847`-D NAME'
848     Make merged if-then-else output using FORMAT.  *Note
849     If-then-else::.
850
851`--debug=NUMBER'
852     Set internal debugging flags.  Of interest only to `patch'
853     patchers.
854
855`-e'
856`--ed'
857     Interpret the patch file as an `ed' script.  *Note patch Input::.
858
859`-E'
860     Remove output files that are empty after the patches have been
861     applied.  *Note Empty Files::.
862
863`-f'
864     Assume that the user knows exactly what he or she is doing, and do
865     not ask any questions.  *Note patch Messages::.
866
867`-F LINES'
868     Set the maximum fuzz factor to LINES.  *Note Inexact::.
869
870`--force'
871     Assume that the user knows exactly what he or she is doing, and do
872     not ask any questions.  *Note patch Messages::.
873
874`--forward'
875     Ignore patches that `patch' thinks are reversed or already applied.
876     See also `-R'.  *Note Reversed Patches::.
877
878`--fuzz=LINES'
879     Set the maximum fuzz factor to LINES.  *Note Inexact::.
880
881`--help'
882     Print a summary of the options that `patch' recognizes, then exit.
883
884`--ifdef=NAME'
885     Make merged if-then-else output using FORMAT.  *Note
886     If-then-else::.
887
888`--ignore-white-space'
889`-l'
890     Let any sequence of white space in the patch file match any
891     sequence of white space in the input file.  *Note Changed White
892     Space::.
893
894`-n'
895`--normal'
896     Interpret the patch file as a normal diff.  *Note patch Input::.
897
898`-N'
899     Ignore patches that `patch' thinks are reversed or already applied.
900     See also `-R'.  *Note Reversed Patches::.
901
902`-o OUTPUT-FILE'
903`--output=OUTPUT-FILE'
904     Use OUTPUT-FILE as the output file name.  *Note patch Options::.
905
906`-p[NUMBER]'
907     Set the file name strip count to NUMBER.  *Note patch
908     Directories::.
909
910`--prefix=BACKUP-PREFIX'
911     Use BACKUP-PREFIX as a prefix to the backup file name.  If this
912     option is specified, any `-b' option is ignored.  *Note Backups::.
913
914`--quiet'
915     Work silently unless an error occurs.  *Note patch Messages::.
916
917`-r REJECT-FILE'
918     Use REJECT-FILE as the reject file name.  *Note Rejects::.
919
920`-R'
921     Assume that this patch was created with the old and new files
922     swapped.  *Note Reversed Patches::.
923
924`--reject-file=REJECT-FILE'
925     Use REJECT-FILE as the reject file name.  *Note Rejects::.
926
927`--remove-empty-files'
928     Remove output files that are empty after the patches have been
929     applied.  *Note Empty Files::.
930
931`--reverse'
932     Assume that this patch was created with the old and new files
933     swapped.  *Note Reversed Patches::.
934
935`-s'
936     Work silently unless an error occurs.  *Note patch Messages::.
937
938`-S'
939     Ignore this patch from the patch file, but continue looking for
940     the next patch in the file.  *Note Multiple Patches::.
941
942`--silent'
943     Work silently unless an error occurs.  *Note patch Messages::.
944
945`--skip'
946     Ignore this patch from the patch file, but continue looking for
947     the next patch in the file.  *Note Multiple Patches::.
948
949`--strip[=NUMBER]'
950     Set the file name strip count to NUMBER.  *Note patch
951     Directories::.
952
953`--suffix=BACKUP-SUFFIX'
954     Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
955     `~'.  *Note Backups::.
956
957`-t'
958     Do not ask any questions.  *Note patch Messages::.
959
960`-u'
961`--unified'
962     Interpret the patch file as a unified diff.  *Note patch Input::.
963
964`-v'
965     Output the revision header and patch level of `patch'.
966
967`-V BACKUP-STYLE'
968     Select the kind of backups to make.  *Note Backups::.
969
970`--version'
971     Output the revision header and patch level of `patch', then exit.
972
973`--version=control=BACKUP-STYLE'
974     Select the kind of backups to make.  *Note Backups::.
975
976`-x NUMBER'
977     Set internal debugging flags.  Of interest only to `patch'
978     patchers.
979
980
981File: diff.info,  Node: Invoking sdiff,  Next: Incomplete Lines,  Prev: Invoking patch,  Up: Top
982
983Invoking `sdiff'
984****************
985
986   The `sdiff' command merges two files and interactively outputs the
987results.  Its arguments are as follows:
988
989     sdiff -o OUTFILE OPTIONS... FROM-FILE TO-FILE
990
991   This merges FROM-FILE with TO-FILE, with output to OUTFILE.  If
992FROM-FILE is a directory and TO-FILE is not, `sdiff' compares the file
993in FROM-FILE whose file name is that of TO-FILE, and vice versa.
994fROM-FILE and TO-FILE may not both be directories.
995
996   `sdiff' options begin with `-', so normally FROM-FILE and TO-FILE
997may not begin with `-'.  However, `--' as an argument by itself treats
998the remaining arguments as file names even if they begin with `-'.  You
999may not use `-' as an input file.
1000
1001   An exit status of 0 means no differences were found, 1 means some
1002differences were found, and 2 means trouble.
1003
1004   `sdiff' without `-o' (or `--output') produces a side-by-side
1005difference.  This usage is obsolete; use `diff --side-by-side' instead.
1006
1007* Menu:
1008
1009* sdiff Options::       Summary of options to `diff'.
1010
1011
1012File: diff.info,  Node: sdiff Options,  Up: Invoking sdiff
1013
1014Options to `sdiff'
1015==================
1016
1017   Below is a summary of all of the options that GNU `sdiff' accepts.
1018Each option has two equivalent names, one of which is a single letter
1019preceded by `-', and the other of which is a long name preceded by
1020`--'.  Multiple single letter options (unless they take an argument)
1021can be combined into a single command line argument.  Long named
1022options can be abbreviated to any unique prefix of their name.
1023
1024`-a'
1025     Treat all files as text and compare them line-by-line, even if they
1026     do not appear to be text.  *Note Binary::.
1027
1028`-b'
1029     Ignore changes in amount of white space.  *Note White Space::.
1030
1031`-B'
1032     Ignore changes that just insert or delete blank lines.  *Note
1033     Blank Lines::.
1034
1035`-d'
1036     Change the algorithm to perhaps find a smaller set of changes.
1037     This makes `sdiff' slower (sometimes much slower).  *Note diff
1038     Performance::.
1039
1040`-H'
1041     Use heuristics to speed handling of large files that have numerous
1042     scattered small changes.  *Note diff Performance::.
1043
1044`--expand-tabs'
1045     Expand tabs to spaces in the output, to preserve the alignment of
1046     tabs in the input files.  *Note Tabs::.
1047
1048`-i'
1049     Ignore changes in case; consider upper- and lower-case to be the
1050     same.  *Note Case Folding::.
1051
1052`-I REGEXP'
1053     Ignore changes that just insert or delete lines that match REGEXP.
1054     *Note Specified Folding::.
1055
1056`--ignore-all-space'
1057     Ignore white space when comparing lines.  *Note White Space::.
1058
1059`--ignore-blank-lines'
1060     Ignore changes that just insert or delete blank lines.  *Note
1061     Blank Lines::.
1062
1063`--ignore-case'
1064     Ignore changes in case; consider upper- and lower-case to be the
1065     same.  *Note Case Folding::.
1066
1067`--ignore-matching-lines=REGEXP'
1068     Ignore changes that just insert or delete lines that match REGEXP.
1069     *Note Specified Folding::.
1070
1071`--ignore-space-change'
1072     Ignore changes in amount of white space.  *Note White Space::.
1073
1074`-l'
1075`--left-column'
1076     Print only the left column of two common lines.  *Note Side by
1077     Side Format::.
1078
1079`--minimal'
1080     Change the algorithm to perhaps find a smaller set of changes.
1081     This makes `sdiff' slower (sometimes much slower).  *Note diff
1082     Performance::.
1083
1084`-o FILE'
1085`--output=FILE'
1086     Put merged output into FILE.  This option is required for merging.
1087
1088`-s'
1089`--suppress-common-lines'
1090     Do not print common lines.  *Note Side by Side Format::.
1091
1092`--speed-large-files'
1093     Use heuristics to speed handling of large files that have numerous
1094     scattered small changes.  *Note diff Performance::.
1095
1096`-t'
1097     Expand tabs to spaces in the output, to preserve the alignment of
1098     tabs in the input files.  *Note Tabs::.
1099
1100`--text'
1101     Treat all files as text and compare them line-by-line, even if they
1102     do not appear to be text.  *Note Binary::.
1103
1104`-v'
1105`--version'
1106     Output the version number of `sdiff'.
1107
1108`-w COLUMNS'
1109`--width=COLUMNS'
1110     Use an output width of COLUMNS.  *Note Side by Side Format::.
1111     Note that for historical reasons, this option is `-W' in `diff',
1112     `-w' in `sdiff'.
1113
1114`-W'
1115     Ignore horizontal white space when comparing lines.  *Note White
1116     Space::.  Note that for historical reasons, this option is `-w' in
1117     `diff', `-W' in `sdiff'.
1118
1119
1120File: diff.info,  Node: Incomplete Lines,  Next: Projects,  Prev: Invoking sdiff,  Up: Top
1121
1122Incomplete Lines
1123****************
1124
1125   When an input file ends in a non-newline character, its last line is
1126called an "incomplete line" because its last character is not a
1127newline.  All other lines are called "full lines" and end in a newline
1128character.  Incomplete lines do not match full lines unless differences
1129in white space are ignored (*note White Space::.).
1130
1131   An incomplete line is normally distinguished on output from a full
1132line by a following line that starts with `\'.  However, the RCS format
1133(*note RCS::.) outputs the incomplete line as-is, without any trailing
1134newline or following line.  The side by side format normally represents
1135incomplete lines as-is, but in some cases uses a `\' or `/' gutter
1136marker; *Note Side by Side::.  The if-then-else line format preserves a
1137line's incompleteness with `%L', and discards the newline with `%l';
1138*Note Line Formats::.  Finally, with the `ed' and forward `ed' output
1139formats (*note Output Formats::.) `diff' cannot represent an incomplete
1140line, so it pretends there was a newline and reports an error.
1141
1142   For example, suppose `F' and `G' are one-byte files that contain
1143just `f' and `g', respectively.  Then `diff F G' outputs
1144
1145     1c1
1146     < f
1147     \ No newline at end of file
1148     ---
1149     > g
1150     \ No newline at end of file
1151
1152(The exact message may differ in non-English locales.) `diff -n F G'
1153outputs the following without a trailing newline:
1154
1155     d1 1
1156     a1 1
1157     g
1158
1159   `diff -e F G' reports two errors and outputs the following:
1160
1161     1c
1162     g
1163     .
1164
1165
1166File: diff.info,  Node: Projects,  Next: Concept Index,  Prev: Incomplete Lines,  Up: Top
1167
1168Future Projects
1169***************
1170
1171   Here are some ideas for improving GNU `diff' and `patch'.  The GNU
1172project has identified some improvements as potential programming
1173projects for volunteers.  You can also help by reporting any bugs that
1174you find.
1175
1176   If you are a programmer and would like to contribute something to the
1177GNU project, please consider volunteering for one of these projects.  If
1178you are seriously contemplating work, please write to
1179`gnu@prep.ai.mit.edu' to coordinate with other volunteers.
1180
1181* Menu:
1182
1183* Shortcomings::        Suggested projects for improvements.
1184* Bugs::                Reporting bugs.
1185
1186
1187File: diff.info,  Node: Shortcomings,  Next: Bugs,  Up: Projects
1188
1189Suggested Projects for Improving GNU `diff' and `patch'
1190=======================================================
1191
1192   One should be able to use GNU `diff' to generate a patch from any
1193pair of directory trees, and given the patch and a copy of one such
1194tree, use `patch' to generate a faithful copy of the other.
1195Unfortunately, some changes to directory trees cannot be expressed using
1196current patch formats; also, `patch' does not handle some of the
1197existing formats.  These shortcomings motivate the following suggested
1198projects.
1199
1200* Menu:
1201
1202* Changing Structure::  Handling changes to the directory structure.
1203* Special Files::       Handling symbolic links, device special files, etc.
1204* Unusual File Names::  Handling file names that contain unusual characters.
1205* Arbitrary Limits::    Patching non-text files.
1206* Large Files::         Handling files that do not fit in memory.
1207* Ignoring Changes::    Ignoring certain changes while showing others.
1208
1209
1210File: diff.info,  Node: Changing Structure,  Next: Special Files,  Up: Shortcomings
1211
1212Handling Changes to the Directory Structure
1213-------------------------------------------
1214
1215   `diff' and `patch' do not handle some changes to directory
1216structure.  For example, suppose one directory tree contains a directory
1217named `D' with some subsidiary files, and another contains a file with
1218the same name `D'.  `diff -r' does not output enough information for
1219`patch' to transform the the directory subtree into the file.
1220
1221   There should be a way to specify that a file has been deleted without
1222having to include its entire contents in the patch file.  There should
1223also be a way to tell `patch' that a file was renamed, even if there is
1224no way for `diff' to generate such information.
1225
1226   These problems can be fixed by extending the `diff' output format to
1227represent changes in directory structure, and extending `patch' to
1228understand these extensions.
1229
1230
1231File: diff.info,  Node: Special Files,  Next: Unusual File Names,  Prev: Changing Structure,  Up: Shortcomings
1232
1233Files that are Neither Directories Nor Regular Files
1234----------------------------------------------------
1235
1236   Some files are neither directories nor regular files: they are
1237unusual files like symbolic links, device special files, named pipes,
1238and sockets.  Currently, `diff' treats symbolic links like regular
1239files; it treats other special files like regular files if they are
1240specified at the top level, but simply reports their presence when
1241comparing directories.  This means that `patch' cannot represent changes
1242to such files.  For example, if you change which file a symbolic link
1243points to, `diff' outputs the difference between the two files, instead
1244of the change to the symbolic link.
1245
1246   `diff' should optionally report changes to special files specially,
1247and `patch' should be extended to understand these extensions.
1248
1249
1250File: diff.info,  Node: Unusual File Names,  Next: Arbitrary Limits,  Prev: Special Files,  Up: Shortcomings
1251
1252File Names that Contain Unusual Characters
1253------------------------------------------
1254
1255   When a file name contains an unusual character like a newline or
1256white space, `diff -r' generates a patch that `patch' cannot parse.
1257The problem is with format of `diff' output, not just with `patch',
1258because with odd enough file names one can cause `diff' to generate a
1259patch that is syntactically correct but patches the wrong files.  The
1260format of `diff' output should be extended to handle all possible file
1261names.
1262
1263
1264File: diff.info,  Node: Arbitrary Limits,  Next: Large Files,  Prev: Unusual File Names,  Up: Shortcomings
1265
1266Arbitrary Limits
1267----------------
1268
1269   GNU `diff' can analyze files with arbitrarily long lines and files
1270that end in incomplete lines.  However, `patch' cannot patch such
1271files.  The `patch' internal limits on line lengths should be removed,
1272and `patch' should be extended to parse `diff' reports of incomplete
1273lines.
1274
1275
1276File: diff.info,  Node: Large Files,  Next: Ignoring Changes,  Prev: Arbitrary Limits,  Up: Shortcomings
1277
1278Handling Files that Do Not Fit in Memory
1279----------------------------------------
1280
1281   `diff' operates by reading both files into memory.  This method
1282fails if the files are too large, and `diff' should have a fallback.
1283
1284   One way to do this is to scan the files sequentially to compute hash
1285codes of the lines and put the lines in equivalence classes based only
1286on hash code.  Then compare the files normally.  This does produce some
1287false matches.
1288
1289   Then scan the two files sequentially again, checking each match to
1290see whether it is real.  When a match is not real, mark both the
1291"matching" lines as changed.  Then build an edit script as usual.
1292
1293   The output routines would have to be changed to scan the files
1294sequentially looking for the text to print.
1295
1296
1297File: diff.info,  Node: Ignoring Changes,  Prev: Large Files,  Up: Shortcomings
1298
1299Ignoring Certain Changes
1300------------------------
1301
1302   It would be nice to have a feature for specifying two strings, one in
1303FROM-FILE and one in TO-FILE, which should be considered to match.
1304Thus, if the two strings are `foo' and `bar', then if two lines differ
1305only in that `foo' in file 1 corresponds to `bar' in file 2, the lines
1306are treated as identical.
1307
1308   It is not clear how general this feature can or should be, or what
1309syntax should be used for it.
1310
1311
1312File: diff.info,  Node: Bugs,  Prev: Shortcomings,  Up: Projects
1313
1314Reporting Bugs
1315==============
1316
1317   If you think you have found a bug in GNU `cmp', `diff', `diff3',
1318`sdiff', or `patch', please report it by electronic mail to
1319`bug-gnu-utils@prep.ai.mit.edu'.  Send as precise a description of the
1320problem as you can, including sample input files that produce the bug,
1321if applicable.
1322
1323   Because Larry Wall has not released a new version of `patch' since
1324mid 1988 and the GNU version of `patch' has been changed since then,
1325please send bug reports for `patch' by electronic mail to both
1326`bug-gnu-utils@prep.ai.mit.edu' and `lwall@netlabs.com'.
1327
Note: See TracBrowser for help on using the repository browser.