source: vendor/patch/2.5.9/patch.man@ 3493

Last change on this file since 3493 was 3444, checked in by bird, 18 years ago

patch 2.5.9

File size: 31.1 KB
Line 
1.\" patch man page
2.de Id
3.ds Dt \\$4
4..
5.Id $Id: patch.man,v 1.31 2002/05/25 10:36:44 eggert Exp $
6.ds = \-\^\-
7.de Sp
8.if t .sp .3
9.if n .sp
10..
11.TH PATCH 1 \*(Dt GNU
12.ta 3n
13.SH NAME
14patch \- apply a diff file to an original
15.SH SYNOPSIS
16.B patch
17.RI [ options ]
18.RI [ originalfile
19.RI [ patchfile ]]
20.Sp
21but usually just
22.Sp
23.BI "patch \-p" "num"
24.BI < patchfile
25.SH DESCRIPTION
26.B patch
27takes a patch file
28.I patchfile
29containing a difference listing produced by the
30.B diff
31program and applies those differences to one or more original files,
32producing patched versions.
33Normally the patched versions are put in place of the originals.
34Backups can be made; see the
35.B \-b
36or
37.B \*=backup
38option.
39The names of the files to be patched are usually taken from the patch file,
40but if there's just one file to be patched it can specified on the
41command line as
42.IR originalfile .
43.PP
44Upon startup, patch attempts to determine the type of the diff listing,
45unless overruled by a
46\fB\-c\fP (\fB\*=context\fP),
47\fB\-e\fP (\fB\*=ed\fP),
48\fB\-n\fP (\fB\*=normal\fP),
49or
50\fB\-u\fP (\fB\*=unified\fP)
51option.
52Context diffs (old-style, new-style, and unified) and
53normal diffs are applied by the
54.B patch
55program itself, while
56.B ed
57diffs are simply fed to the
58.BR ed (1)
59editor via a pipe.
60.PP
61.B patch
62tries to skip any leading garbage, apply the diff,
63and then skip any trailing garbage.
64Thus you could feed an article or message containing a
65diff listing to
66.BR patch ,
67and it should work.
68If the entire diff is indented by a consistent amount,
69or if a context diff contains lines ending in \s-1CRLF\s0
70or is encapsulated one or more times by prepending
71"\fB\- \fP" to lines starting with "\fB\-\fP" as specified by Internet RFC 934,
72this is taken into account.
73After removing indenting or encapsulation,
74lines beginning with
75.B #
76are ignored, as they are considered to be comments.
77.PP
78With context diffs, and to a lesser extent with normal diffs,
79.B patch
80can detect when the line numbers mentioned in the patch are incorrect,
81and attempts to find the correct place to apply each hunk of the patch.
82As a first guess, it takes the line number mentioned for the hunk, plus or
83minus any offset used in applying the previous hunk.
84If that is not the correct place,
85.B patch
86scans both forwards and backwards for a set of lines matching the context
87given in the hunk.
88First
89.B patch
90looks for a place where all lines of the context match.
91If no such place is found, and it's a context diff, and the maximum fuzz factor
92is set to 1 or more, then another scan takes place ignoring the first and last
93line of context.
94If that fails, and the maximum fuzz factor is set to 2 or more,
95the first two and last two lines of context are ignored,
96and another scan is made.
97(The default maximum fuzz factor is 2.)
98If
99.B patch
100cannot find a place to install that hunk of the patch, it puts the
101hunk out to a reject file, which normally is the name of the output file
102plus a
103.B \&.rej
104suffix, or
105.B #
106if
107.B \&.rej
108would generate a file name that is too long
109(if even appending the single character
110.B #
111makes the file name too long, then
112.B #
113replaces the file name's last character).
114(The rejected hunk comes out in ordinary context diff form regardless of
115the input patch's form.
116If the input was a normal diff, many of the contexts are simply null.)
117The line numbers on the hunks in the reject file may be different than
118in the patch file: they reflect the approximate location patch thinks the
119failed hunks belong in the new file rather than the old one.
120.PP
121As each hunk is completed, you are told if the hunk
122failed, and if so which line (in the new file)
123.B patch
124thought the hunk should go on.
125If the hunk is installed at a different line
126from the line number specified in the diff you
127are told the offset.
128A single large offset
129.I may
130indicate that a hunk was installed in the
131wrong place.
132You are also told if a fuzz factor was used to make the match, in which
133case you should also be slightly suspicious.
134If the
135.B \*=verbose
136option is given, you are also told about hunks that match exactly.
137.PP
138If no original file
139.I origfile
140is specified on the command line,
141.B patch
142tries to figure out from the leading garbage what the name of the file
143to edit is, using the following rules.
144.LP
145First,
146.B patch
147takes an ordered list of candidate file names as follows:
148.TP 3
149.B " \(bu"
150If the header is that of a context diff,
151.B patch
152takes the old and new file names in the header.
153A name is ignored if it does not have enough slashes to satisfy the
154.BI \-p num
155or
156.BI \*=strip= num
157option.
158The name
159.B /dev/null
160is also ignored.
161.TP
162.B " \(bu"
163If there is an
164.B Index:\&
165line in the leading garbage
166and if either the old and new names are both absent or if
167.B patch
168is conforming to \s-1POSIX\s0,
169.B patch
170takes the name in the
171.B Index:\&
172line.
173.TP
174.B " \(bu"
175For the purpose of the following rules,
176the candidate file names are considered to be in the order (old, new, index),
177regardless of the order that they appear in the header.
178.LP
179Then
180.B patch
181selects a file name from the candidate list as follows:
182.TP 3
183.B " \(bu"
184If some of the named files exist,
185.B patch
186selects the first name if conforming to \s-1POSIX\s0,
187and the best name otherwise.
188.TP
189.B " \(bu"
190If
191.B patch
192is not ignoring \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0 (see the
193.BI "\-g\ " num
194or
195.BI \*=get= num
196option), and no named files exist
197but an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master is found,
198.B patch
199selects the first named file
200with an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master.
201.TP
202.B " \(bu"
203If no named files exist,
204no \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master was found,
205some names are given,
206.B patch
207is not conforming to \s-1POSIX\s0,
208and the patch appears to create a file,
209.B patch
210selects the best name requiring the creation of the fewest directories.
211.TP
212.B " \(bu"
213If no file name results from the above heuristics, you are asked
214for the name of the file to patch, and
215.B patch
216selects that name.
217.LP
218To determine the
219.I best
220of a nonempty list of file names,
221.B patch
222first takes all the names with the fewest path name components;
223of those, it then takes all the names with the shortest basename;
224of those, it then takes all the shortest names;
225finally, it takes the first remaining name.
226.PP
227Additionally, if the leading garbage contains a
228.B Prereq:\&
229line,
230.B patch
231takes the first word from the prerequisites line (normally a version
232number) and checks the original file to see if that word can be found.
233If not,
234.B patch
235asks for confirmation before proceeding.
236.PP
237The upshot of all this is that you should be able to say, while in a news
238interface, something like the following:
239.Sp
240 \fB| patch \-d /usr/src/local/blurfl\fP
241.Sp
242and patch a file in the
243.B blurfl
244directory directly from the article containing
245the patch.
246.PP
247If the patch file contains more than one patch,
248.B patch
249tries to apply each of them as if they came from separate patch files.
250This means, among other things, that it is assumed that the name of the file
251to patch must be determined for each diff listing,
252and that the garbage before each diff listing
253contains interesting things such as file names and revision level, as
254mentioned previously.
255.SH OPTIONS
256.TP 3
257\fB\-b\fP or \fB\*=backup\fP
258Make backup files.
259That is, when patching a file,
260rename or copy the original instead of removing it.
261When backing up a file that does not exist,
262an empty, unreadable backup file is created
263as a placeholder to represent the nonexistent file.
264See the
265.B \-V
266or
267.B \*=version\-control
268option for details about how backup file names are determined.
269.TP
270.B \*=backup\-if\-mismatch
271Back up a file if the patch does not match the file exactly
272and if backups are not otherwise requested.
273This is the default unless
274.B patch
275is conforming to \s-1POSIX\s0.
276.TP
277.B \*=no\-backup\-if\-mismatch
278Do not back up a file if the patch does not match the file exactly
279and if backups are not otherwise requested.
280This is the default if
281.B patch
282is conforming to \s-1POSIX\s0.
283.TP
284\fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fP
285Prefix
286.I pref
287to a file name when generating its simple backup file name.
288For example, with
289.B "\-B\ /junk/"
290the simple backup file name for
291.B src/patch/util.c
292is
293.BR /junk/src/patch/util.c .
294.TP
295\fB\*=binary\fP
296Read and write all files in binary mode,
297except for standard output and
298.BR /dev/tty .
299This option has no effect on \s-1POSIX\s0-conforming systems.
300On systems like \s-1DOS\s0 where this option makes a difference,
301the patch should be generated by
302.BR "diff\ \-a\ \*=binary" .
303.TP
304\fB\-c\fP or \fB\*=context\fP
305Interpret the patch file as a ordinary context diff.
306.TP
307\fB\-d\fP \fIdir\fP or \fB\*=directory=\fP\fIdir\fP
308Change to the directory
309.I dir
310immediately, before doing
311anything else.
312.TP
313\fB\-D\fP \fIdefine\fP or \fB\*=ifdef=\fP\fIdefine\fP
314Use the
315.BR #ifdef " .\|.\|. " #endif
316construct to mark changes, with
317.I define
318as the differentiating symbol.
319.TP
320.B "\*=dry\-run"
321Print the results of applying the patches without actually changing any files.
322.TP
323\fB\-e\fP or \fB\*=ed\fP
324Interpret the patch file as an
325.B ed
326script.
327.TP
328\fB\-E\fP or \fB\*=remove\-empty\-files\fP
329Remove output files that are empty after the patches have been applied.
330Normally this option is unnecessary, since
331.B patch
332can examine the time stamps on the header to determine whether a file
333should exist after patching.
334However, if the input is not a context diff or if
335.B patch
336is conforming to \s-1POSIX\s0,
337.B patch
338does not remove empty patched files unless this option is given.
339When
340.B patch
341removes a file, it also attempts to remove any empty ancestor directories.
342.TP
343\fB\-f\fP or \fB\*=force\fP
344Assume that the user knows exactly what he or she is doing, and do not
345ask any questions. Skip patches whose headers
346do not say which file is to be patched; patch files even though they have the
347wrong version for the
348.B Prereq:\&
349line in the patch; and assume that
350patches are not reversed even if they look like they are.
351This option does not suppress commentary; use
352.B \-s
353for that.
354.TP
355\fB\-F\fP \fInum\fP or \fB\*=fuzz=\fP\fInum\fP
356Set the maximum fuzz factor.
357This option only applies to diffs that have context, and causes
358.B patch
359to ignore up to that many lines in looking for places to install a hunk.
360Note that a larger fuzz factor increases the odds of a faulty patch.
361The default fuzz factor is 2, and it may not be set to more than
362the number of lines of context in the context diff, ordinarily 3.
363.TP
364\fB\-g\fP \fInum\fP or \fB\*=get=\fP\fInum\fP
365This option controls
366.BR patch 's
367actions when a file is under \s-1RCS\s0 or \s-1SCCS\s0 control,
368and does not exist or is read-only and matches the default version,
369or when a file is under ClearCase or Perforce control and does not exist.
370If
371.I num
372is positive,
373.B patch
374gets (or checks out) the file from the revision control system; if zero,
375.B patch
376ignores \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0
377and does not get the file; and if negative,
378.B patch
379asks the user whether to get the file.
380The default value of this option is given by the value of the
381.B PATCH_GET
382environment variable if it is set; if not, the default value is zero if
383.B patch
384is conforming to \s-1POSIX\s0, negative otherwise.
385.TP
386.B "\*=help"
387Print a summary of options and exit.
388.TP
389\fB\-i\fP \fIpatchfile\fP or \fB\*=input=\fP\fIpatchfile\fP
390Read the patch from
391.IR patchfile .
392If
393.I patchfile
394is
395.BR \- ,
396read from standard input, the default.
397.TP
398\fB\-l\fP or \fB\*=ignore\-whitespace\fP
399Match patterns loosely, in case tabs or spaces
400have been munged in your files.
401Any sequence of one or more blanks in the patch file matches any sequence
402in the original file, and sequences of blanks at the ends of lines are ignored.
403Normal characters must still match exactly.
404Each line of the context must still match a line in the original file.
405.TP
406\fB\-n\fP or \fB\*=normal\fP
407Interpret the patch file as a normal diff.
408.TP
409\fB\-N\fP or \fB\*=forward\fP
410Ignore patches that seem to be reversed or already applied.
411See also
412.BR \-R .
413.TP
414\fB\-o\fP \fIoutfile\fP or \fB\*=output=\fP\fIoutfile\fP
415Send output to
416.I outfile
417instead of patching files in place.
418Do not use this option if
419.I outfile
420is one of the files to be patched.
421.TP
422\fB\-p\fP\fInum\fP or \fB\*=strip\fP\fB=\fP\fInum\fP
423Strip the smallest prefix containing
424.I num
425leading slashes from each file name found in the patch file.
426A sequence of one or more adjacent slashes is counted as a single slash.
427This controls how file names found in the patch file are treated, in case
428you keep your files in a different directory than the person who sent
429out the patch.
430For example, supposing the file name in the patch file was
431.Sp
432 \fB/u/howard/src/blurfl/blurfl.c\fP
433.Sp
434setting
435.B \-p0
436gives the entire file name unmodified,
437.B \-p1
438gives
439.Sp
440 \fBu/howard/src/blurfl/blurfl.c\fP
441.Sp
442without the leading slash,
443.B \-p4
444gives
445.Sp
446 \fBblurfl/blurfl.c\fP
447.Sp
448and not specifying
449.B \-p
450at all just gives you \fBblurfl.c\fP.
451Whatever you end up with is looked for either in the current directory,
452or the directory specified by the
453.B \-d
454option.
455.TP
456.B \*=posix
457Conform more strictly to the \s-1POSIX\s0 standard, as follows.
458.RS
459.TP 3
460.B " \(bu"
461Take the first existing file from the list (old, new, index)
462when intuiting file names from diff headers.
463.TP
464.B " \(bu"
465Do not remove files that are empty after patching.
466.TP
467.B " \(bu"
468Do not ask whether to get files from \s-1RCS\s0, ClearCase, Perforce,
469or \s-1SCCS\s0.
470.TP
471.B " \(bu"
472Require that all options precede the files in the command line.
473.TP
474.B " \(bu"
475Do not backup files when there is a mismatch.
476.RE
477.TP
478.BI \*=quoting\-style= word
479Use style
480.I word
481to quote output names.
482The
483.I word
484should be one of the following:
485.RS
486.TP
487.B literal
488Output names as-is.
489.TP
490.B shell
491Quote names for the shell if they contain shell metacharacters or would
492cause ambiguous output.
493.TP
494.B shell-always
495Quote names for the shell, even if they would normally not require quoting.
496.TP
497.B c
498Quote names as for a C language string.
499.TP
500.B escape
501Quote as with
502.B c
503except omit the surrounding double-quote characters.
504.LP
505You can specify the default value of the
506.B \*=quoting\-style
507option with the environment variable
508.BR QUOTING_STYLE .
509If that environment variable is not set, the default value is
510.BR shell .
511.RE
512.TP
513\fB\-r\fP \fIrejectfile\fP or \fB\*=reject\-file=\fP\fIrejectfile\fP
514Put rejects into
515.I rejectfile
516instead of the default
517.B \&.rej
518file.
519.TP
520\fB\-R\fP or \fB\*=reverse\fP
521Assume that this patch was created with the old and new files swapped.
522(Yes, I'm afraid that does happen occasionally, human nature being what it
523is.)
524.B patch
525attempts to swap each hunk around before applying it.
526Rejects come out in the swapped format.
527The
528.B \-R
529option does not work with
530.B ed
531diff scripts because there is too little
532information to reconstruct the reverse operation.
533.Sp
534If the first hunk of a patch fails,
535.B patch
536reverses the hunk to see if it can be applied that way.
537If it can, you are asked if you want to have the
538.B \-R
539option set.
540If it can't, the patch continues to be applied normally.
541(Note: this method cannot detect a reversed patch if it is a normal diff
542and if the first command is an append (i.e. it should have been a delete)
543since appends always succeed, due to the fact that a null context matches
544anywhere.
545Luckily, most patches add or change lines rather than delete them, so most
546reversed normal diffs begin with a delete, which fails, triggering
547the heuristic.)
548.TP
549\fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fP
550Work silently, unless an error occurs.
551.TP
552\fB\-t\fP or \fB\*=batch\fP
553Suppress questions like
554.BR \-f ,
555but make some different assumptions:
556skip patches whose headers do not contain file names (the same as \fB\-f\fP);
557skip patches for which the file has the wrong version for the
558.B Prereq:\&
559line
560in the patch; and assume that patches are reversed if they look like
561they are.
562.TP
563\fB\-T\fP or \fB\*=set\-time\fP
564Set the modification and access times of patched files from time stamps
565given in context diff headers, assuming that the context diff headers
566use local time. This option is not recommended, because patches using
567local time cannot easily be used by people in other time zones, and
568because local time stamps are ambiguous when local clocks move backwards
569during daylight-saving time adjustments. Instead of using this option,
570generate patches with \s-1UTC\s0 and use the
571.B \-Z
572or
573.B \*=set\-utc
574option instead.
575.TP
576\fB\-u\fP or \fB\*=unified\fP
577Interpret the patch file as a unified context diff.
578.TP
579\fB\-v\fP or \fB\*=version\fP
580Print out
581.BR patch 's
582revision header and patch level, and exit.
583.TP
584\fB\-V\fP \fImethod\fP or \fB\*=version\-control=\fP\fImethod\fP
585Use
586.I method
587to determine
588backup file names. The method can also be given by the
589.B PATCH_VERSION_CONTROL
590(or, if that's not set, the
591.BR VERSION_CONTROL )
592environment variable, which is overridden by this option.
593The method does not affect whether backup files are made;
594it affects only the names of any backup files that are made.
595.Sp
596The value of
597.I method
598is like the \s-1GNU\s0
599Emacs `version-control' variable;
600.B patch
601also recognizes synonyms that
602are more descriptive. The valid values for
603.I method
604are (unique abbreviations are
605accepted):
606.RS
607.TP 3
608\fBexisting\fP or \fBnil\fP
609Make numbered backups of files that already have them,
610otherwise simple backups.
611This is the default.
612.TP
613\fBnumbered\fP or \fBt\fP
614Make numbered backups. The numbered backup file name for
615.I F
616is
617.IB F .~ N ~
618where
619.I N
620is the version number.
621.TP
622\fBsimple\fP or \fBnever\fP
623Make simple backups.
624The
625.B \-B
626or
627.BR \*=prefix ,
628.B \-Y
629or
630.BR \*=basename\-prefix ,
631and
632.B \-z
633or
634.BR \*=suffix
635options specify the simple backup file name.
636If none of these options are given, then a simple backup suffix is used;
637it is the value of the
638.B SIMPLE_BACKUP_SUFFIX
639environment variable if set, and is
640.B \&.orig
641otherwise.
642.PP
643With numbered or simple backups,
644if the backup file name is too long, the backup suffix
645.B ~
646is used instead; if even appending
647.B ~
648would make the name too long, then
649.B ~
650replaces the last character of the file name.
651.RE
652.TP
653\fB\*=verbose\fP
654Output extra information about the work being done.
655.TP
656\fB\-x\fP \fInum\fP or \fB\*=debug=\fP\fInum\fP
657Set internal debugging flags of interest only to
658.B patch
659patchers.
660.TP
661\fB\-Y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fP
662Prefix
663.I pref
664to the basename of a file name when generating its simple backup file name.
665For example, with
666.B "\-Y\ .del/"
667the simple backup file name for
668.B src/patch/util.c
669is
670.BR src/patch/.del/util.c .
671.TP
672\fB\-z\fP \fIsuffix\fP or \fB\*=suffix=\fP\fIsuffix\fP
673Use
674.I suffix
675as the simple backup suffix.
676For example, with
677.B "\-z\ -"
678the simple backup file name for
679.B src/patch/util.c
680is
681.BR src/patch/util.c- .
682The backup suffix may also be specified by the
683.B SIMPLE_BACKUP_SUFFIX
684environment variable, which is overridden by this option.
685.TP
686\fB\-Z\fP or \fB\*=set\-utc\fP
687Set the modification and access times of patched files from time stamps
688given in context diff headers, assuming that the context diff headers
689use Coordinated Universal Time (\s-1UTC\s0, often known as \s-1GMT\s0).
690Also see the
691.B \-T
692or
693.B \*=set\-time
694option.
695.Sp
696The
697.B \-Z
698or
699.B \*=set\-utc
700and
701.B \-T
702or
703.B \*=set\-time
704options normally refrain from setting a file's time if the file's original time
705does not match the time given in the patch header, or if its
706contents do not match the patch exactly. However, if the
707.B \-f
708or
709.B \*=force
710option is given, the file time is set regardless.
711.Sp
712Due to the limitations of
713.B diff
714output format, these options cannot update the times of files whose
715contents have not changed. Also, if you use these options, you should remove
716(e.g. with
717.BR "make\ clean" )
718all files that depend on the patched files, so that later invocations of
719.B make
720do not get confused by the patched files' times.
721.SH ENVIRONMENT
722.TP 3
723.B PATCH_GET
724This specifies whether
725.B patch
726gets missing or read-only files from \s-1RCS\s0, ClearCase, Perforce,
727or \s-1SCCS\s0
728by default; see the
729.B \-g
730or
731.B \*=get
732option.
733.TP
734.B POSIXLY_CORRECT
735If set,
736.B patch
737conforms more strictly to the \s-1POSIX\s0 standard by default:
738see the
739.B \*=posix
740option.
741.TP
742.B QUOTING_STYLE
743Default value of the
744.B \*=quoting\-style
745option.
746.TP
747.B SIMPLE_BACKUP_SUFFIX
748Extension to use for simple backup file names instead of
749.BR \&.orig .
750.TP
751\fBTMPDIR\fP, \fBTMP\fP, \fBTEMP\fP
752Directory to put temporary files in;
753.B patch
754uses the first environment variable in this list that is set.
755If none are set, the default is system-dependent;
756it is normally
757.B /tmp
758on Unix hosts.
759.TP
760\fBVERSION_CONTROL\fP or \fBPATCH_VERSION_CONTROL\fP
761Selects version control style; see the
762.B \-v
763or
764.B \*=version\-control
765option.
766.SH FILES
767.TP 3
768.IB $TMPDIR "/p\(**"
769temporary files
770.TP
771.B /dev/tty
772controlling terminal; used to get answers to questions asked of the user
773.SH "SEE ALSO"
774.BR diff (1),
775.BR ed (1)
776.Sp
777Marshall T. Rose and Einar A. Stefferud,
778Proposed Standard for Message Encapsulation,
779Internet RFC 934 <URL:ftp://ftp.isi.edu/in-notes/rfc934.txt> (1985-01).
780.SH "NOTES FOR PATCH SENDERS"
781There are several things you should bear in mind if you are going to
782be sending out patches.
783.PP
784Create your patch systematically.
785A good method is the command
786.BI "diff\ \-Naur\ " "old\ new"
787where
788.I old
789and
790.I new
791identify the old and new directories.
792The names
793.I old
794and
795.I new
796should not contain any slashes.
797The
798.B diff
799command's headers should have dates
800and times in Universal Time using traditional Unix format,
801so that patch recipients can use the
802.B \-Z
803or
804.B \*=set\-utc
805option.
806Here is an example command, using Bourne shell syntax:
807.Sp
808 \fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP
809.PP
810Tell your recipients how to apply the patch
811by telling them which directory to
812.B cd
813to, and which
814.B patch
815options to use. The option string
816.B "\-Np1"
817is recommended.
818Test your procedure by pretending to be a recipient and applying
819your patch to a copy of the original files.
820.PP
821You can save people a lot of grief by keeping a
822.B patchlevel.h
823file which is patched to increment the patch level
824as the first diff in the patch file you send out.
825If you put a
826.B Prereq:\&
827line in with the patch, it won't let them apply
828patches out of order without some warning.
829.PP
830You can create a file by sending out a diff that compares
831.B /dev/null
832or an empty file dated the Epoch (1970-01-01 00:00:00 \s-1UTC\s0)
833to the file you want to create.
834This only works if the file you want to create doesn't exist already in
835the target directory.
836Conversely, you can remove a file by sending out a context diff that compares
837the file to be deleted with an empty file dated the Epoch.
838The file will be removed unless
839.B patch
840is conforming to \s-1POSIX\s0 and the
841.B \-E
842or
843.B \*=remove\-empty\-files
844option is not given.
845An easy way to generate patches that create and remove files
846is to use \s-1GNU\s0
847.BR diff 's
848.B \-N
849or
850.B \*=new\-file
851option.
852.PP
853If the recipient is supposed to use the
854.BI \-p N
855option, do not send output that looks like this:
856.Sp
857.ft B
858.ne 3
859 diff \-Naur v2.0.29/prog/README prog/README
860.br
861 \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
862.br
863 +\^+\^+ prog/README Mon Mar 17 14:58:22 1997
864.ft
865.Sp
866because the two file names have different numbers of slashes,
867and different versions of
868.B patch
869interpret the file names differently.
870To avoid confusion, send output that looks like this instead:
871.Sp
872.ft B
873.ne 3
874 diff \-Naur v2.0.29/prog/README v2.0.30/prog/README
875.br
876 \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
877.br
878 +\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
879.ft
880.Sp
881.PP
882Avoid sending patches that compare backup file names like
883.BR README.orig ,
884since this might confuse
885.B patch
886into patching a backup file instead of the real file.
887Instead, send patches that compare the same base file names
888in different directories, e.g.\&
889.B old/README
890and
891.BR new/README .
892.PP
893Take care not to send out reversed patches, since it makes people wonder
894whether they already applied the patch.
895.PP
896Try not to have your patch modify derived files
897(e.g. the file
898.B configure
899where there is a line
900.B "configure: configure.in"
901in your makefile), since the recipient should be
902able to regenerate the derived files anyway.
903If you must send diffs of derived files,
904generate the diffs using \s-1UTC\s0,
905have the recipients apply the patch with the
906.B \-Z
907or
908.B \*=set\-utc
909option, and have them remove any unpatched files that depend on patched files
910(e.g. with
911.BR "make\ clean" ).
912.PP
913While you may be able to get away with putting 582 diff listings into
914one file, it may be wiser to group related patches into separate files in
915case something goes haywire.
916.SH DIAGNOSTICS
917Diagnostics generally indicate that
918.B patch
919couldn't parse your patch file.
920.PP
921If the
922.B \*=verbose
923option is given, the message
924.B Hmm.\|.\|.\&
925indicates that there is unprocessed text in
926the patch file and that
927.B patch
928is attempting to intuit whether there is a patch in that text and, if so,
929what kind of patch it is.
930.PP
931.BR patch 's
932exit status is
9330 if all hunks are applied successfully,
9341 if some hunks cannot be applied,
935and 2 if there is more serious trouble.
936When applying a set of patches in a loop it behooves you to check this
937exit status so you don't apply a later patch to a partially patched file.
938.SH CAVEATS
939Context diffs cannot reliably represent the creation or deletion of
940empty files, empty directories, or special files such as symbolic links.
941Nor can they represent changes to file metadata like ownership, permissions,
942or whether one file is a hard link to another.
943If changes like these are also required, separate instructions
944(e.g. a shell script) to accomplish them should accompany the patch.
945.PP
946.B patch
947cannot tell if the line numbers are off in an
948.B ed
949script, and can detect
950bad line numbers in a normal diff only when it finds a change or deletion.
951A context diff using fuzz factor 3 may have the same problem.
952Until a suitable interactive interface is added, you should probably do
953a context diff in these cases to see if the changes made sense.
954Of course, compiling without errors is a pretty good indication that the patch
955worked, but not always.
956.PP
957.B patch
958usually produces the correct results, even when it has to do a lot of
959guessing.
960However, the results are guaranteed to be correct only when the patch is
961applied to exactly the same version of the file that the patch was
962generated from.
963.SH "COMPATIBILITY ISSUES"
964The \s-1POSIX\s0 standard specifies behavior that differs from
965.BR patch 's
966traditional behavior.
967You should be aware of these differences if you must interoperate with
968.B patch
969versions 2.1 and earlier, which do not conform to \s-1POSIX\s0.
970.TP 3
971.B " \(bu"
972In traditional
973.BR patch ,
974the
975.B \-p
976option's operand was optional, and a bare
977.B \-p
978was equivalent to
979.BR \-p0.
980The
981.B \-p
982option now requires an operand, and
983.B "\-p\ 0"
984is now equivalent to
985.BR \-p0 .
986For maximum compatibility, use options like
987.B \-p0
988and
989.BR \-p1 .
990.Sp
991Also,
992traditional
993.B patch
994simply counted slashes when stripping path prefixes;
995.B patch
996now counts pathname components.
997That is, a sequence of one or more adjacent slashes
998now counts as a single slash.
999For maximum portability, avoid sending patches containing
1000.B //
1001in file names.
1002.TP
1003.B " \(bu"
1004In traditional
1005.BR patch ,
1006backups were enabled by default.
1007This behavior is now enabled with the
1008.B \-b
1009or
1010.B \*=backup
1011option.
1012.Sp
1013Conversely, in \s-1POSIX\s0
1014.BR patch ,
1015backups are never made, even when there is a mismatch.
1016In \s-1GNU\s0
1017.BR patch ,
1018this behavior is enabled with the
1019.B \*=no\-backup\-if\-mismatch
1020option, or by conforming to \s-1POSIX\s0 with the
1021.B \*=posix
1022option or by setting the
1023.B POSIXLY_CORRECT
1024environment variable.
1025.Sp
1026The
1027.BI \-b "\ suffix"
1028option
1029of traditional
1030.B patch
1031is equivalent to the
1032.BI "\-b\ \-z" "\ suffix"
1033options of \s-1GNU\s0
1034.BR patch .
1035.TP
1036.B " \(bu"
1037Traditional
1038.B patch
1039used a complicated (and incompletely documented) method
1040to intuit the name of the file to be patched from the patch header.
1041This method did not conform to \s-1POSIX\s0, and had a few gotchas.
1042Now
1043.B patch
1044uses a different, equally complicated (but better documented) method
1045that is optionally \s-1POSIX\s0-conforming; we hope it has
1046fewer gotchas. The two methods are compatible if the
1047file names in the context diff header and the
1048.B Index:\&
1049line are all identical after prefix-stripping.
1050Your patch is normally compatible if each header's file names
1051all contain the same number of slashes.
1052.TP
1053.B " \(bu"
1054When traditional
1055.B patch
1056asked the user a question, it sent the question to standard error
1057and looked for an answer from
1058the first file in the following list that was a terminal:
1059standard error, standard output,
1060.BR /dev/tty ,
1061and standard input.
1062Now
1063.B patch
1064sends questions to standard output and gets answers from
1065.BR /dev/tty .
1066Defaults for some answers have been changed so that
1067.B patch
1068never goes into an infinite loop when using default answers.
1069.TP
1070.B " \(bu"
1071Traditional
1072.B patch
1073exited with a status value that counted the number of bad hunks,
1074or with status 1 if there was real trouble.
1075Now
1076.B patch
1077exits with status 1 if some hunks failed,
1078or with 2 if there was real trouble.
1079.TP
1080.B " \(bu"
1081Limit yourself to the following options when sending instructions
1082meant to be executed by anyone running \s-1GNU\s0
1083.BR patch ,
1084traditional
1085.BR patch ,
1086or a
1087.B patch
1088that conforms to \s-1POSIX\s0.
1089Spaces are significant in the following list, and operands are required.
1090.Sp
1091.nf
1092.in +3
1093.ne 11
1094.B \-c
1095.BI \-d " dir"
1096.BI \-D " define"
1097.B \-e
1098.B \-l
1099.B \-n
1100.B \-N
1101.BI \-o " outfile"
1102.BI \-p num
1103.B \-R
1104.BI \-r " rejectfile"
1105.in
1106.fi
1107.SH BUGS
1108Please report bugs via email to
1109.BR <bug-patch@gnu.org> .
1110.PP
1111.B patch
1112could be smarter about partial matches, excessively deviant offsets and
1113swapped code, but that would take an extra pass.
1114.PP
1115If code has been duplicated (for instance with
1116\fB#ifdef OLDCODE\fP .\|.\|. \fB#else .\|.\|. #endif\fP),
1117.B patch
1118is incapable of patching both versions, and, if it works at all, will likely
1119patch the wrong one, and tell you that it succeeded to boot.
1120.PP
1121If you apply a patch you've already applied,
1122.B patch
1123thinks it is a reversed patch, and offers to un-apply the patch.
1124This could be construed as a feature.
1125.SH COPYING
1126Copyright
1127.ie t \(co
1128.el (C)
11291984, 1985, 1986, 1988 Larry Wall.
1130.br
1131Copyright
1132.ie t \(co
1133.el (C)
11341989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
11352000, 2001, 2002 Free Software Foundation, Inc.
1136.PP
1137Permission is granted to make and distribute verbatim copies of
1138this manual provided the copyright notice and this permission notice
1139are preserved on all copies.
1140.PP
1141Permission is granted to copy and distribute modified versions of this
1142manual under the conditions for verbatim copying, provided that the
1143entire resulting derived work is distributed under the terms of a
1144permission notice identical to this one.
1145.PP
1146Permission is granted to copy and distribute translations of this
1147manual into another language, under the above conditions for modified
1148versions, except that this permission notice may be included in
1149translations approved by the copyright holders instead of in
1150the original English.
1151.SH AUTHORS
1152Larry Wall wrote the original version of
1153.BR patch .
1154Paul Eggert removed
1155.BR patch 's
1156arbitrary limits; added support for binary files,
1157setting file times, and deleting files;
1158and made it conform better to \s-1POSIX\s0.
1159Other contributors include Wayne Davison, who added unidiff support,
1160and David MacKenzie, who added configuration and backup support.
Note: See TracBrowser for help on using the repository browser.