📄 patch.1
字号:
.\" patch man page.de Id.ds Dt \\$4...Id $Id: patch.man,v 1.23 1997/07/16 12:26:36 eggert Exp $.ds = \-\^\-.de Sp.if t .sp .3.if n .sp...TH PATCH 1 \*(Dt GNU.ta 3n.SH NAMEpatch \- apply a diff file to an original.SH SYNOPSIS.B patch.RI [ options ].RI [ originalfile.RI [ patchfile ]].Spbut usually just.Sp.BI "patch \-p" "num".BI < patchfile.SH DESCRIPTION.B patchtakes a patch file.I patchfilecontaining a difference listing produced by the.B diffprogram and applies those differences to one or more original files,producing patched versions.Normally the patched versions are put in place of the originals.Backups can be made; see the.B \-bor.B \*=backupoption.The names of the files to be patched are usually taken from the patch file,but if there's just one file to be patched it can specified on thecommand line as.IR originalfile ..PPUpon startup, patch attempts to determine the type of the diff listing,unless overruled by a\fB\-c\fP (\fB\*=context\fP),\fB\-e\fP (\fB\*=ed\fP),\fB\-n\fP (\fB\*=normal\fP),or\fB\-u\fP (\fB\*=unified\fP)option.Context diffs (old-style, new-style, and unified) andnormal diffs are applied by the.B patchprogram itself, while.B eddiffs are simply fed to the.BR ed (1)editor via a pipe..PP.B patchtries to skip any leading garbage, apply the diff,and then skip any trailing garbage.Thus you could feed an article or message containing adiff listing to.BR patch ,and it should work.If the entire diff is indented by a consistent amount,or if a context diff is encapsulated one or more times by prepending"\fB\- \fP" to lines starting with "\fB\-\fP" as specified by Internet RFC 934,this is taken into account..PPWith context diffs, and to a lesser extent with normal diffs,.B patchcan detect when the line numbers mentioned in the patch are incorrect,and attempts to find the correct place to apply each hunk of the patch.As a first guess, it takes the line number mentioned for the hunk, plus orminus any offset used in applying the previous hunk.If that is not the correct place,.B patchscans both forwards and backwards for a set of lines matching the contextgiven in the hunk.First.B patchlooks for a place where all lines of the context match.If no such place is found, and it's a context diff, and the maximum fuzz factoris set to 1 or more, then another scan takes place ignoring the first and lastline of context.If that fails, and the maximum fuzz factor is set to 2 or more,the first two and last two lines of context are ignored,and another scan is made.(The default maximum fuzz factor is 2.)If.B patchcannot find a place to install that hunk of the patch, it puts thehunk out to a reject file, which normally is the name of the output fileplus a.B \&.rejsuffix, or.B #if.B \&.rejwould generate a file name that is too long(if even appending the single character.B #makes the file name too long, then.B #replaces the file name's last character).(The rejected hunk comes out in ordinary context diff form regardless ofthe input patch's form.If the input was a normal diff, many of the contexts are simply null.)The line numbers on the hunks in the reject file may be different thanin the patch file: they reflect the approximate location patch thinks thefailed hunks belong in the new file rather than the old one..PPAs each hunk is completed, you are told if the hunkfailed, and if so which line (in the new file).B patchthought the hunk should go on.If the hunk is installed at a different linefrom the line number specified in the diff youare told the offset.A single large offset.I mayindicate that a hunk was installed in thewrong place.You are also told if a fuzz factor was used to make the match, in whichcase you should also be slightly suspicious.If the.B \*=verboseoption is given, you are also told about hunks that match exactly..PPIf no original file.I origfileis specified on the command line,.B patchtries to figure out from the leading garbage what the name of the fileto edit is, using the following rules..TP 3.B " \(bu"If the header is that of a context diff,.B patchtakes the old and new file names in the header.Any.B /dev/nullnames are ignored..TP.B " \(bu"If there is an.B Index:\&line in the leading garbageand if either the old and new names are both absent or the.B POSIXLY_CORRECTenvironment variable is set,.B patchtakes the name in the.B Index:\&line..TP.B " \(bu"For the purpose of the following rules,the names are considered to be in the order (old, new, index),regardless of the order that they appear in the header..TP.B " \(bu"If some of the named files exist,.B patchuses the first name if the.B POSIXLY_CORRECTenvironment variable is set, and the best name otherwise..TP.B " \(bu"If.B patchis not ignoring \s-1RCS\s0 and \s-1SCCS\s0 (see the.BI "\-g\ " numor.BI \*=get= numoption), and no named files existbut an \s-1RCS\s0 or \s-1SCCS\s0 master is found,.B patchuses the first named file with an \s-1RCS\s0 or \s-1SCCS\s0 master..TP.B " \(bu"If no named files exist, no \s-1RCS\s0 or \s-1SCCS\s0 master was found,some names are given,.B POSIXLY_CORRECTis not set, and the patch appears to create a file,.B patchuses the best name requiring the creation of the fewest directories..TP.B " \(bu"If no file name results from the above heuristics, you are askedfor the name of the file to patch..LPTo determine the.I bestof a nonempty list of file names,.B patchfirst takes all the names with the fewest path name components;of those, it then takes all the names with the shortest basename;of those, it then takes all the shortest names;finally, it takes the first remaining name..PPAdditionally, if the leading garbage contains a.B Prereq:\&line,.B patchtakes the first word from the prerequisites line (normally a versionnumber) and checks the original file to see if that word can be found.If not,.B patchasks for confirmation before proceeding..PPThe upshot of all this is that you should be able to say, while in a newsinterface, something like the following:.Sp \fB| patch \-d /usr/src/local/blurfl\fP.Spand patch a file in the.B blurfldirectory directly from the article containingthe patch..PPIf the patch file contains more than one patch,.B patchtries to apply each of them as if they came from separate patch files.This means, among other things, that it is assumed that the name of the fileto patch must be determined for each diff listing,and that the garbage before each diff listingcontains interesting things such as file names and revision level, asmentioned previously..SH OPTIONS.TP 3\fB\-b\fP or \fB\*=backup\fPMake backup files.That is, when patching a file,rename or copy the original instead of removing it.When backing up a file that does not exist,an empty, unreadable backup file is createdas a placeholder to represent the nonexistent file.See the.B \-Vor.B \*=version\-controloption for details about how backup file names are determined..TP.B \*=backup\-if\-mismatchBack up a file if the patch does not match the file exactlyand if backups are not otherwise requested.This is the default unless the.B POSIXLY_CORRECTenvironment variable is set..TP.B \*=no\-backup\-if\-mismatchDo not back up a file if the patch does not match the file exactlyand if backups are not otherwise requested.This is the default if the.B POSIXLY_CORRECTenvironment variable is set..TP\fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fPPrefix.I prefto a file name when generating its simple backup file name.For example, with.B "\-B\ /junk/"the simple backup file name for.B src/patch/util.cis.BR /junk/src/patch/util.c ..TP\fB\*=binary\fPRead and write all files in binary mode,except for standard output and.BR /dev/tty .This option has no effect on \s-1POSIX\s0-compliant systems.On systems like \s-1DOS\s0 where this option makes a difference,the patch should be generated by.BR "diff\ \-a\ \*=binary" ..TP\fB\-c\fP or \fB\*=context\fPInterpret the patch file as a ordinary context diff..TP\fB\-d\fP \fIdir\fP or \fB\*=directory=\fP\fIdir\fPChange to the directory.I dirimmediately, before doinganything else..TP\fB\-D\fP \fIdefine\fP or \fB\*=ifdef=\fP\fIdefine\fPUse the.BR #ifdef " .\|.\|. " #endifconstruct to mark changes, with.I defineas the differentiating symbol..TP.B "\*=dry\-run"Print the results of applying the patches without actually changing any files..TP\fB\-e\fP or \fB\*=ed\fPInterpret the patch file as an.B edscript..TP\fB\-E\fP or \fB\*=remove\-empty\-files\fPRemove output files that are empty after the patches have been applied.Normally this option is unnecessary, since.B patchcan examine the time stamps on the header to determine whether a fileshould exist after patching.However, if the input is not a context diff or if the.B POSIXLY_CORRECTenvironment variable is set,.B patchdoes not remove empty patched files unless this option is given.When.B patchremoves a file, it also attempts to remove any empty ancestor directories..TP\fB\-f\fP or \fB\*=force\fPAssume that the user knows exactly what he or she is doing, and do notask any questions. Skip patches whose headersdo not say which file is to be patched; patch files even though they have thewrong version for the.B Prereq:\&line in the patch; and assume thatpatches are not reversed even if they look like they are.This option does not suppress commentary; use.B \-sfor that..TP\fB\-F\fP \fInum\fP or \fB\*=fuzz=\fP\fInum\fPSet the maximum fuzz factor.This option only applies to diffs that have context, and causes.B patchto ignore up to that many lines in looking for places to install a hunk.Note that a larger fuzz factor increases the odds of a faulty patch.The default fuzz factor is 2, and it may not be set to more thanthe number of lines of context in the context diff, ordinarily 3..TP\fB\-g\fP \fInum\fP or \fB\*=get=\fP\fInum\fPThis option controls.BR patch 'sactions when a file is under \s-1RCS\s0 or \s-1SCCS\s0 control,and does not exist or is read-only and matches the default version.If.I numis positive,.B patchgets (or checks out) the file from the revision control system; if zero,.B patchignores \s-1RCS\s0 and \s-1SCCS\s0 and does not get the file; and if negative,.B patchasks the user whether to get the file.The default value of this option is given by the value of the.B PATCH_GETenvironment variable if it is set; if not, the default value is zero if .B POSIXLY_CORRECTis set, negative otherwise..TP.B "\*=help"Print a summary of options and exit..TP\fB\-i\fP \fIpatchfile\fP or \fB\*=input=\fP\fIpatchfile\fPRead the patch from.IR patchfile .If.I patchfileis.BR \- ,read from standard input, the default..TP\fB\-l\fP or \fB\*=ignore\-whitespace\fPMatch patterns loosely, in case tabs or spaceshave been munged in your files.Any sequence of one or more blanks in the patch file matches any sequencein the original file, and sequences of blanks at the ends of lines are ignored.Normal characters must still match exactly.Each line of the context must still match a line in the original file..TP\fB\-n\fP or \fB\*=normal\fPInterpret the patch file as a normal diff..TP\fB\-N\fP or \fB\*=forward\fPIgnore patches that seem to be reversed or already applied.See also.BR \-R ..TP\fB\-o\fP \fIoutfile\fP or \fB\*=output=\fP\fIoutfile\fPSend output to.I outfileinstead of patching files in place..TP\fB\-p\fP\fInum\fP or \fB\*=strip\fP\fB=\fP\fInum\fPStrip the smallest prefix containing.I numleading slashes from each file name found in the patch file.A sequence of one or more adjacent slashes is counted as a single slash.This controls how file names found in the patch file are treated, in caseyou keep your files in a different directory than the person who sentout the patch.For example, supposing the file name in the patch file was.Sp \fB/u/howard/src/blurfl/blurfl.c\fP.Spsetting.B \-p0gives the entire file name unmodified,.B \-p1gives.Sp \fBu/howard/src/blurfl/blurfl.c\fP.Spwithout the leading slash,.B \-p4gives.Sp \fBblurfl/blurfl.c\fP.Spand not specifying.B \-pat all just gives you \fBblurfl.c\fP.Whatever you end up with is looked for either in the current directory,or the directory specified by the.B \-doption..TP\fB\-r\fP \fIrejectfile\fP or \fB\*=reject\-file=\fP\fIrejectfile\fPPut rejects into.I rejectfileinstead of the default.B \&.rejfile..TP\fB\-R\fP or \fB\*=reverse\fPAssume that this patch was created with the old and new files swapped.(Yes, I'm afraid that does happen occasionally, human nature being what itis.).B patchattempts to swap each hunk around before applying it.Rejects come out in the swapped format.The.B \-Roption does not work with.B eddiff scripts because there is too littleinformation to reconstruct the reverse operation..SpIf the first hunk of a patch fails,.B patchreverses the hunk to see if it can be applied that way.If it can, you are asked if you want to have the.B \-Roption set.If it can't, the patch continues to be applied normally.(Note: this method cannot detect a reversed patch if it is a normal diffand if the first command is an append (i.e. it should have been a delete)since appends always succeed, due to the fact that a null context matchesanywhere.Luckily, most patches add or change lines rather than delete them, so mostreversed normal diffs begin with a delete, which fails, triggeringthe heuristic.).TP\fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fPWork silently, unless an error occurs..TP\fB\-t\fP or \fB\*=batch\fPSuppress questions like.BR \-f ,but make some different assumptions:skip patches whose headers do not contain file names (the same as \fB\-f\fP);skip patches for which the file has the wrong version for the.B Prereq:\&linein the patch; and assume that patches are reversed if they look likethey are..TP\fB\-T\fP or \fB\*=set\-time\fPSet the modification and access times of patched files from time stampsgiven in context diff headers, assuming that the context diff headersuse local time. This option is not recommended, because patches usinglocal time cannot easily be used by people in other time zones, andbecause local time stamps are ambiguous when local clocks move backwardsduring daylight-saving time adjustments. Instead of using this option,generate patches with \s-1UTC\s0 and use the.B \-Zor.B \*=set\-utcoption instead..TP\fB\-u\fP or \fB\*=unified\fPInterpret the patch file as a unified context diff..TP\fB\-v\fP or \fB\*=version\fPPrint out.BR patch 'srevision header and patch level, and exit..TP\fB\-V\fP \fImethod\fP or \fB\*=version\-control=\fP\fImethod\fPUse.I methodto determinebackup file names. The method can also be given by the.B PATCH_VERSION_CONTROL(or, if that's not set, the.BR VERSION_CONTROL )environment variable, which is overridden by this option.The method does not affect whether backup files are made;it affects only the names of any backup files that are made..SpThe value of.I methodis like the \s-1GNU\s0Emacs `version-control' variable;.B patchalso recognizes synonyms thatare more descriptive. The valid values for.I methodare (unique abbreviations areaccepted):.RS.TP 3\fBexisting\fP or \fBnil\fPMake numbered backups of files that already have them,otherwise simple backups.This is the default..TP\fBnumbered\fP or \fBt\fPMake numbered backups. The numbered backup file name for.I Fis.IB F .~ N ~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -