📄 patch.man
字号:
.\" patch man page.de Id.ds Dt \\$4...Id $Id: patch.man,v 1.31 2002/05/25 10:36:44 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 contains lines ending in \s-1CRLF\s0or 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.After removing indenting or encapsulation,lines beginning with.B #are ignored, as they are considered to be comments..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..LPFirst,.B patchtakes an ordered list of candidate file names as follows:.TP 3.B " \(bu"If the header is that of a context diff,.B patchtakes the old and new file names in the header.A name is ignored if it does not have enough slashes to satisfy the.BI \-p numor.BI \*=strip= numoption.The name.B /dev/nullis also 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 if.B patchis conforming to \s-1POSIX\s0,.B patchtakes the name in the.B Index:\&line..TP.B " \(bu"For the purpose of the following rules,the candidate file names are considered to be in the order (old, new, index),regardless of the order that they appear in the header..LPThen.B patchselects a file name from the candidate list as follows:.TP 3.B " \(bu"If some of the named files exist,.B patchselects the first name if conforming to \s-1POSIX\s0,and the best name otherwise..TP.B " \(bu"If.B patchis not ignoring \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0 (see the.BI "\-g\ " numor.BI \*=get= numoption), and no named files existbut an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master is found,.B patchselects the first named filewith an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master..TP.B " \(bu"If no named files exist,no \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master was found,some names are given,.B patchis not conforming to \s-1POSIX\s0,and the patch appears to create a file,.B patchselects 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, and.B patchselects that name..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.B patchis conforming to \s-1POSIX\s0..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.B patchis conforming to \s-1POSIX\s0..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-conforming 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.B patchis conforming to \s-1POSIX\s0,.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,or when a file is under ClearCase or Perforce control and does not exist.If.I numis positive,.B patchgets (or checks out) the file from the revision control system; if zero,.B patchignores \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0and 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 patchis conforming to \s-1POSIX\s0, negative otherwise..TP.B "\*=help"Print a summary of options and exit.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -