📄 patch.1
字号:
where.I Nis the version number..TP\fBsimple\fP or \fBnever\fPMake simple backups.The.B \-Bor.BR \*=prefix ,.B \-Yor.BR \*=basename\-prefix ,and.B \-zor.BR \*=suffixoptions specify the simple backup file name.If none of these options are given, then a simple backup suffix is used;it is the value of the.B SIMPLE_BACKUP_SUFFIXenvironment variable if set, and is.B \&.origotherwise..PPWith numbered or simple backups,if the backup file name is too long, the backup suffix.B ~is used instead; if even appending.B ~would make the name too long, then.B ~replaces the last character of the file name..RE.TP\fB\*=verbose\fPOutput extra information about the work being done..TP\fB\-x\fP \fInum\fP or \fB\*=debug=\fP\fInum\fPSet internal debugging flags of interest only to.B patchpatchers..TP\fB\-Y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fPPrefix.I prefto the basename of a file name when generating its simple backup file name.For example, with.B "\-Y\ .del/"the simple backup file name for.B src/patch/util.cis.BR src/patch/.del/util.c ..TP\fB\-z\fP \fIsuffix\fP or \fB\*=suffix=\fP\fIsuffix\fPUse.I suffixas the simple backup suffix.For example, with.B "\-z\ -"the simple backup file name for.B src/patch/util.cis.BR src/patch/util.c- .The backup suffix may also be specified by the.B SIMPLE_BACKUP_SUFFIXenvironment variable, which is overridden by this option..TP\fB\-Z\fP or \fB\*=set\-utc\fPSet the modification and access times of patched files from time stampsgiven in context diff headers, assuming that the context diff headersuse Coordinated Universal Time (\s-1UTC\s0, often known as \s-1GMT\s0).Also see the.B \-Tor.B \*=set\-timeoption..SpThe.B \-Zor.B \*=set\-utcand.B \-Tor.B \*=set\-timeoptions normally refrain from setting a file's time if the file's original timedoes not match the time given in the patch header, or if itscontents do not match the patch exactly. However, if the.B \-for.B \*=forceoption is given, the file time is set regardless..SpDue to the limitations of.B diffoutput format, these options cannot update the times of files whosecontents have not changed. Also, if you use these options, you should remove(e.g. with.BR "make\ clean" )all files that depend on the patched files, so that later invocations of.B makedo not get confused by the patched files' times..SH ENVIRONMENT.TP 3\fBPATCH_GET\fPThis specifies whether.B patchgets missing or read-only files from \s-1RCS\s0 or \s-1SCCS\s0by default; see the.B \-gor.B \*=getoption..TP.B POSIXLY_CORRECTIf set,.B patchconforms more strictly to the \s-1POSIX\s0 standard:it takes the first existing file from the list (old, new, index)when intuiting file names from diff headers,it does not remove files that are empty after patching,it does not ask whether to get files from \s-1RCS\s0 or \s-1SCCS\s0,it requires that all options precede the files in the command line,and it does not backup files when there is a mismatch..TP.B SIMPLE_BACKUP_SUFFIXExtension to use for simple backup file names instead of.BR \&.orig ..TP\fBTMPDIR\fP, \fBTMP\fP, \fBTEMP\fPDirectory to put temporary files in;.B patchuses the first environment variable in this list that is set.If none are set, the default is system-dependent;it is normally.B /tmpon Unix hosts..TP\fBVERSION_CONTROL\fP or \fBPATCH_VERSION_CONTROL\fPSelects version control style; see the.B \-vor.B \*=version\-controloption..SH FILES.TP 3.IB $TMPDIR "/p\(**"temporary files.TP.B /dev/ttycontrolling terminal; used to get answers to questions asked of the user.SH "SEE ALSO".BR diff (1),.BR ed (1).SpMarshall T. Rose and Einar A. Stefferud,Proposed Standard for Message Encapsulation,Internet RFC 934 <URL:ftp://ftp.isi.edu/in-notes/rfc934.txt> (1985-01)..SH "NOTES FOR PATCH SENDERS"There are several things you should bear in mind if you are going tobe sending out patches..PPCreate your patch systematically.A good method is the command.BI "diff\ \-Naur\ " "old\ new"where.I oldand.I newidentify the old and new directories.The names.I oldand.I newshould not contain any slashes.The.B diffcommand's headers should have datesand times in Universal Time using traditional Unix format,so that patch recipients can use the.B \-Zor.B \*=set\-utcoption.Here is an example command, using Bourne shell syntax:.Sp \fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP.PPTell your recipients how to apply the patchby telling them which directory to.B cdto, and which.B patchoptions to use. The option string.B "\-Np1"is recommended.Test your procedure by pretending to be a recipient and applyingyour patch to a copy of the original files..PPYou can save people a lot of grief by keeping a.B patchlevel.hfile which is patched to increment the patch levelas the first diff in the patch file you send out.If you put a.B Prereq:\&line in with the patch, it won't let them applypatches out of order without some warning..PPYou can create a file by sending out a diff that compares.B /dev/nullor an empty file dated the Epoch (1970-01-01 00:00:00 \s-1UTC\s0)to the file you want to create.This only works if the file you want to create doesn't exist already inthe target directory.Conversely, you can remove a file by sending out a context diff that comparesthe file to be deleted with an empty file dated the Epoch.The file will be removed unless the.B POSIXLY_CORRECTenvironment variable is set and the.B \-Eor.B \*=remove\-empty\-filesoption is not given.An easy way to generate patches that create and remove filesis to use \s-1GNU\s0.BR diff 's.B \-Nor.B \*=new\-fileoption..PPIf the recipient is supposed to use the.BI \-p Noption, do not send output that looks like this:.Sp.ft B.ne 3 diff \-Naur v2.0.29/prog/README prog/README.br \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997.br +\^+\^+ prog/README Mon Mar 17 14:58:22 1997.ft.Spbecause the two file names have different numbers of slashes,and different versions of.B patchinterpret the file names differently.To avoid confusion, send output that looks like this instead:.Sp.ft B.ne 3 diff \-Naur v2.0.29/prog/README v2.0.30/prog/README.br \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997.br +\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997.ft.Sp.PPAvoid sending patches that compare backup file names like.BR README.orig ,since this might confuse.B patchinto patching a backup file instead of the real file.Instead, send patches that compare the same base file namesin different directories, e.g.\&.B old/READMEand.BR new/README ..PPTake care not to send out reversed patches, since it makes people wonderwhether they already applied the patch..PPTry not to have your patch modify derived files(e.g. the file.B configurewhere there is a line.B "configure: configure.in"in your makefile), since the recipient should beable to regenerate the derived files anyway.If you must send diffs of derived files,generate the diffs using \s-1UTC\s0,have the recipients apply the patch with the.B \-Zor.B \*=set\-utcoption, and have them remove any unpatched files that depend on patched files(e.g. with.BR "make\ clean" )..PPWhile you may be able to get away with putting 582 diff listings intoone file, it may be wiser to group related patches into separate files incase something goes haywire..SH DIAGNOSTICSDiagnostics generally indicate that.B patchcouldn't parse your patch file..PPIf the.B \*=verboseoption is given, the message.B Hmm.\|.\|.\&indicates that there is unprocessed text inthe patch file and that.B patchis attempting to intuit whether there is a patch in that text and, if so,what kind of patch it is..PP.BR patch 'sexit status is0 if all hunks are applied successfully,1 if some hunks cannot be applied,and 2 if there is more serious trouble.When applying a set of patches in a loop it behooves you to check thisexit status so you don't apply a later patch to a partially patched file..SH CAVEATSContext diffs cannot reliably represent the creation or deletion ofempty files, empty directories, or special files such as symbolic links.Nor can they represent changes to file metadata like ownership, permissions,or whether one file is a hard link to another.If changes like these are also required, separate instructions(e.g. a shell script) to accomplish them should accompany the patch..PP.B patchcannot tell if the line numbers are off in an.B edscript, and can detectbad line numbers in a normal diff only when it finds a change or deletion.A context diff using fuzz factor 3 may have the same problem.Until a suitable interactive interface is added, you should probably doa context diff in these cases to see if the changes made sense.Of course, compiling without errors is a pretty good indication that the patchworked, but not always..PP.B patchusually produces the correct results, even when it has to do a lot ofguessing.However, the results are guaranteed to be correct only when the patch isapplied to exactly the same version of the file that the patch wasgenerated from..SH "COMPATIBILITY ISSUES"The \s-1POSIX\s0 standard specifies behavior that differs from.BR patch 'straditional behavior.You should be aware of these differences if you must interoperate with.B patchversions 2.1 and earlier, which are not \s-1POSIX\s0-compliant..TP 3.B " \(bu"In traditional.BR patch ,the.B \-poption's operand was optional, and a bare.B \-pwas equivalent to.BR \-p0.The.B \-poption now requires an operand, and.B "\-p\ 0"is now equivalent to.BR \-p0 .For maximum compatibility, use options like.B \-p0and.BR \-p1 ..SpAlso,traditional.B patchsimply counted slashes when stripping path prefixes;.B patchnow counts pathname components.That is, a sequence of one or more adjacent slashesnow counts as a single slash.For maximum portability, avoid sending patches containing.B //in file names..TP.B " \(bu"In traditional.BR patch ,backups were enabled by default.This behavior is now enabled with the.B \-bor.B \*=backupoption..SpConversely, in \s-1POSIX\s0.BR patch ,backups are never made, even when there is a mismatch.In \s-1GNU\s0.BR patch ,this behavior is enabled with the.B \*=no\-backup\-if\-mismatchoption or by setting the.B POSIXLY_CORRECTenvironment variable..SpThe.BI \-b "\ suffix"optionof traditional.B patchis equivalent to the.BI "\-b\ \-z" "\ suffix"options of \s-1GNU\s0.BR patch ..TP.B " \(bu"Traditional.B patchused a complicated (and incompletely documented) methodto intuit the name of the file to be patched from the patch header.This method was not \s-1POSIX\s0-compliant, and had a few gotchas.Now.B patchuses a different, equally complicated (but better documented) methodthat is optionally \s-1POSIX\s0-compliant; we hope it hasfewer gotchas. The two methods are compatible if thefile names in the context diff header and the.B Index:\&line are all identical after prefix-stripping.Your patch is normally compatible if each header's file namesall contain the same number of slashes..TP.B " \(bu"When traditional.B patchasked the user a question, it sent the question to standard errorand looked for an answer fromthe first file in the following list that was a terminal:standard error, standard output,.BR /dev/tty ,and standard input.Now.B patchsends questions to standard output and gets answers from.BR /dev/tty .Defaults for some answers have been changed so that.B patchnever goes into an infinite loop when using default answers..TP.B " \(bu"Traditional.B patchexited with a status value that counted the number of bad hunks,or with status 1 if there was real trouble.Now.B patchexits with status 1 if some hunks failed,or with 2 if there was real trouble..TP.B " \(bu"Limit yourself to the following options when sending instructionsmeant to be executed by anyone running \s-1GNU\s0.BR patch ,traditional.BR patch ,or a \s-1POSIX\s0-compliant.BR patch .Spaces are significant in the following list, and operands are required..Sp.nf.in +3.ne 11.B \-c.BI \-d " dir".BI \-D " define".B \-e.B \-l.B \-n.B \-N.BI \-o " outfile".BI \-p num.B \-R.BI \-r " rejectfile".in.fi.SH BUGS.B patchcould be smarter about partial matches, excessively deviant offsets andswapped code, but that would take an extra pass..PPIf code has been duplicated (for instance with\fB#ifdef OLDCODE\fP .\|.\|. \fB#else .\|.\|. #endif\fP),.B patchis incapable of patching both versions, and, if it works at all, will likelypatch the wrong one, and tell you that it succeeded to boot..PPIf you apply a patch you've already applied,.B patchthinks it is a reversed patch, and offers to un-apply the patch.This could be construed as a feature..SH COPYINGCopyright.if t \(co1984, 1985, 1986, 1988 Larry Wall..brCopyright.if t \(co1997 Free Software Foundation, Inc..PPPermission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies..PPPermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that theentire resulting derived work is distributed under the terms of apermission notice identical to this one..PPPermission is granted to copy and distribute translations of thismanual into another language, under the above conditions for modifiedversions, except that this permission notice may be included intranslations approved by the copyright holders instead of inthe original English..SH AUTHORSLarry Wall wrote the original version of.BR patch .Paul Eggert removed.BR patch 'sarbitrary limits; added support for binary files,setting file times, and deleting files;and made it conform better to \s-1POSIX\s0.Other contributors include Wayne Davison, who added unidiff support,and David MacKenzie, who added configuration and backup support.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -