📄 patch.html
字号:
A patchfile may contain patching instructions for more than one file;filenames are determined as specified in<xref href=patchfd><a href="#tag_001_014_1662_002">Filename Determination</a></xref>.When the<b>-b</b>option is specified,for each patched file, the original will be saved in afile of the same name with the suffix<b>.orig</b>appended to it.<p>For each patched file, a reject file may also be created as noted in<xref href=patchapp><a href="#tag_001_014_1662_003">Patch Application</a></xref>.In the absence of a<b>-r</b>option, the name ofthis file will be formed by appending the suffix<b>.rej</b>to the original filename.<h5><a name = "tag_001_014_1662_001"> </a>Patchfile Format</h5>The patch file must contain zero or more lines of header informationfollowed by one or more patches.Each patch must contain zero or morelines of filename identification in the format produced by<i><a href="diff.html">diff</a></i><b>-c</b>,and one or more sets of<i><a href="diff.html">diff</a></i>output, which are customarilycalled hunks.<p>The<i>patch</i>utility recognises the following expression in theheader information:<dl compact><dt><b>Index: </b><i>pathname</i><dd>The file to be patched is named<i>pathname</i>.</dl><p>If all lines (including headers) within a patch begin with thesame leading sequence ofblank characters,the<i>patch</i>utility will remove this sequence before proceeding.Within each patch, if the type of difference is context, the<i>patch</i>utility recognises the following expressions:<dl compact><dt><b>*** </b><i>filename timestamp</i><dd>The patches arose from<i>filename.</i><dt><b>--- </b><i>filename timestamp</i><dd>The patches should be applied to<i>filename.</i></dl><p>Each hunk within a patch must be the<i><a href="diff.html">diff</a></i>output to change a linerange within the original file.The line numbers for successivehunks within a patch must occur in ascending order.<h5><a name = "tag_001_014_1662_002"> </a>Filename Determination</h5><xref type="5" name="patchfd"></xref>If no<i>file</i>operand is specified,<i>patch</i>performs the following steps to obtain a pathname:<ol><p><li>If the patch contains the strings***and---,the<i>patch</i>utility strips components from the beginning of eachpathname (depending on the presence or value of the<b>-p</b>option), then tests for theexistence of both files in the current directory (ordirectory specified with the<b>-d</b>option).If both files exist,<i>patch</i>assumes that no pathname can be obtained from this step.<p><li>If the header information contains a line with the string<b>Index:</b>,<i>patch</i>utility strips components from thebeginning of the pathname (depending on<b>-p</b>),then tests for the existence of this file in the current directory(or directory specified with the<b>-d</b>option).<p><li>If an<b>SCCS</b>directory exists in the current directory,<i>patch</i>will attempt to perform a<i><a href="get.html">get</a></i><b>-e</b>SCCS/s.<i>filename</i>command to retrieve an editable version of the file.<p><li>If no pathname can be obtained by applying the previous steps,or if the pathnames obtained do not exist,<i>patch</i>will write a prompt to standard output andrequest a filename interactively from standard input.<p></ol><h5><a name = "tag_001_014_1662_003"> </a>Patch Application</h5><xref type="5" name="patchapp"></xref>If the<b>-c</b>,<b>-e</b>or<b>-n</b>option is present, the<i>patch</i>utility willinterpret information within each hunk as a context difference, an<i><a href="ed.html">ed</a></i>difference or a normal difference, respectively.In the absence of any ofthese options, the<i>patch</i>utility determines the type of differencebased on the format of information within the hunk.<p>For each hunk, the<i>patch</i>utility begins to search for theplace to apply the patch at the line number at the beginning ofthe hunk, plus or minus any offset used in applying the previous hunk.If lines matching the hunk context arenot found,<i>patch</i>scans both forwards and backwards at least1000 bytes for a set of lines that match the hunk context.<p>If no such place is found and it is a context difference, then anotherscan will take place, ignoring the first and last line of context.If that fails, the first two and last two lines of context will be ignoredand another scan will be made.Implementations may search more extensively for installation locations.<p>If no location can be found, the<i>patch</i>utility will append thehunk to the reject file.The rejected hunk will be written incontext-difference format regardless of the format of the patch file.If the input was a normal or<i><a href="ed.html">ed</a></i>-styledifference, the reject file may contain differenceswith zero lines of context.The line numbers on the hunks in thereject file may be different from the line numbers in the patchfile since they will reflect the approximate locations for thefailed hunks in the new file rather than the old one.<p>If the type of patch is an<i><a href="ed.html">ed</a></i>diff,the implementation may accomplish the patching by invoking the<i><a href="ed.html">ed</a></i>utility.</blockquote><h4><a name = "tag_001_014_1663"> </a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion.<dt>1<dd>One or more lines were written to a reject file.<dt>>1<dd>An error occurred.</dl></blockquote><h4><a name = "tag_001_014_1664"> </a>CONSEQUENCES OF ERRORS</h4><blockquote>Patches that cannot be correctly placed in the filewill be written to a reject file.<br></blockquote><h4><a name = "tag_001_014_1665"> </a>APPLICATION USAGE</h4><blockquote>The<b>-R</b>option will not work with<i><a href="ed.html">ed</a></i>scripts because there is too little information to reconstructthe reverse operation.<p>The<b>-p</b>option makes it possible to customise a patchfile to localuser directory structures without manually editing the patchfile.For example, if the filename in the patch file was:<pre><code>/curds/whey/src/blurfl/blurfl.c</code></pre><p>Setting<b>-p 0</b>gives the entire pathname unmodified;<b>-p 1</b>gives:<pre><code>curds/whey/src/blurfl/blurfl.c</code></pre><p>without the leading slash,<b>-p 4</b>gives:<pre><code>blurfl/blurfl.c</code></pre><p>and not specifying<b>-p</b>at all gives:<pre><code>blurfl.c .</code></pre><p>When using<b>-b</b>in some file system implementations, the saving of a<b>.orig</b>file may produce unwanted results.In the case of 12, 13 or 14-character filenames,on file systems supporting 14-character maximum filenames, the<b>.orig</b>file will overwrite the new file.</blockquote><h4><a name = "tag_001_014_1666"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_1667"> </a>FUTURE DIRECTIONS</h4><blockquote>The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns aboutparts of this interface definition to the IEEE PASC Shell and Utilities Working Groupwhich is identifying the corrections.A future revision of this specification will align withIEEE Std. 1003.2b when finalised.</blockquote><h4><a name = "tag_001_014_1668"> </a>SEE ALSO</h4><blockquote><i><a href="ed.html">ed</a></i>,<i><a href="diff.html">diff</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -