解决方案

打补丁patch 命令使用

seo靠我 2023-09-24 09:19:42

patch 命令用于打补丁,补丁文件是使用diff产生的

patch 命令语法

patch [  -b [ -B Prefix ] ] [  -f ] [ -l ] [ -N ] [ -R ] [  -sSEO靠我 ] [  -v ] [  -c | -e | -n ] [  -d Directory ] [  -D Define ] [  -F Number ] [  -i PatchFile ] [  -oSEO靠我 OutFile ] [  -p Number ] [  -r RejectFile ] [  -x Number ] [ File ]

patch 命令失败或拒绝接受补丁时,会产生一个和原文件同名,以SEO靠我".rej"为后缀的差异文件。

   当知道 -b 时,会产生一个和原文件同名,以".orig"为后缀的备份文件。

常使用的 patch 参数:

 -p 指定目录级别(从路径全称中除去几层目录)

如,如果补丁文件包含SEO靠我路径名称 /curds/whey/src/blurfl/blurfl.c,那么:

  -p 0 使用完整路径名

  -p 1 除去前导斜杠,留下 curds/whey/src/blurfl/blurfl.c。

-pSEO靠我 4 除去前导斜杠和前三个目录,留下 blurfl/blurfl.c。

    -d Directory 打补丁前,更改当前目录到指定目录

 -i PatchFile 从指定文件,而不是从标准输入中读取补丁信息

-RSEO靠我 逆向补丁,这个选项在防止打错补丁很有用处

补丁的产生一般用

diff -Nrua   a  b > c.patch

如:

#diff -Nrua linux-2.6.14/Makefile  linux-2SEO靠我.6.26/Makefile >c.patch

#cat c.patch

--- linux-2.6.14/Makefile 2008-07-30 16:54:20.000000000 +0800

+++ SEO靠我linux-2.6.26/Makefile 2008-07-14 05:51:29.000000000 +0800

@@ -1,8 +1,8 @@

 VERSION = 2

 PATCHLEVEL = 6

-SUSEO靠我BLEVEL = 14

+SUBLEVEL = 26

 EXTRAVERSION =

-NAME=Affluent Albatross

+NAME = Rotary Wombat

# *DOCUMENTATIONSEO靠我*

 # To see a list of typical targets execute "make help"

--- 的文件表示将被打补丁的文件 如:linux-2.6.14/Makefile

+++ SEO靠我的文件表示补丁来源文件   如:linux-2.6.26/Makefile

应用 patch

 #ls

 c.patch  linux-2.6.14  linux-2.6.26

 #cd linux-2.6.14

#SEO靠我patch -p1 <../c.patch

如果有多个补丁要打,则应该注意打补丁的顺序!

Patch

Patch多指 补丁的意思比如内存补丁、文件补丁等, 也是电脑命令程序的一种。

目 录

1命令应用

1.1 用SEO靠我途1.2 语法1.3 描述

2文件名

3应用程序

4准备补丁

4.1 原则4.2 标志4.3 示例4.4 文件

1 命令应用

用途

对文件应用更改。

语法

patch [ -b [ -B Prefix ] ] [ -fSEO靠我 ] [ -l ] [ -N ] [ -R ] [ -s ] [ -v ] [ -c | -e | -n ] [ -d Directory ] [ -D Define ] [ -F Number ] SEO靠我[ -i PatchFile ] [ -o OutFile ] [ -p Number ] [ -r RejectFile ] [ -x Number ] [ File ]

描述

patch 命令读取如何SEO靠我更改文件的源文件指示信息,然后应用这些更改。源文件包含由 diff 命令产生的差别列表(或者 diff 列表)。差异列表是比较两个文件和构建关于如何纠正差别的指示信息的结果。缺省情况下,patch 命SEO靠我令使用从标准输入读入的源文件,但是使用 -i 标志和 PatchFile 变量可以覆盖此设置。 差异列表有三种格式:正常、上下文或者是 ed 编辑器风格。patch 命令确定差异列表SEO靠我格式,除非被 -c、-e 或 -n 标志否决。 缺省情况下,文件的打过 补丁的版本替换原始版本。指定 -b 标志时,每个 补丁文件的原文件保存在同名的文件中,只是在文件名后附加了后缀SEO靠我 .orig。使用 -o 标志也可以指定输出的目的地。 -p 标志使得无需手工编辑 补丁文件就可以定制补丁文件到 本地用户目录结构中。通过指定从路径全称除去多少部分可以做到这一点。例SEO靠我如,如果 补丁文件包含路径名称 /curds/whey/src/blurfl/blurfl.c,那么: * -p 0 导致使用完整 路径名。 * -p 1 除去前导SEO靠我斜杠,留下 curds/whey/src/blurfl/blurfl.c。 * -p 4 除去前导 斜杠和前三个目录,留下 blurfl/blurfl.c。 不指定SEO靠我 -p 标志使得 patch 命令使用基本名称。在上面的示例中,此文件为 blurfl.c。 补丁 文件格式 补丁文件必须包含单行或多行头信息,后跟单个或多个补丁。SEO靠我每个 补丁必须包含一行或多行文件名标识,其格式由 diff -c 命令和单个或多个 diff 命令输出集产生,通常称为 hunks。 patch 命令跳过 补丁文件中的任何前导文本,SEO靠我然后应用实际的差异列表,并且跳过任何后续文本。因而,可以将包含差异列表的文件或消息当成 补丁文件使用,此时 patch 命令仍然有效。在这种情况下,如果整个差异列表使用一致的数量 缩进,patch 命SEO靠我令也会调整其间距。 要更改原始文件中的行范围,每一 补丁中的块(hunk)必须为单独的差异列表。 补丁内连续块(hunk)的行号必须以升序方式出现。

2 文件名

如果没有指定 File SEO靠我参数,要获得供编辑的文件名,patch 命令会执行下面的步骤: 1. 在上下文差异列表的头部分,文件名由以 ***(三个星号)或者 ---(三个破折号)开头的行确定。以 *** 开头SEO靠我的行表示获取 补丁的文件,然而以 --- 开头的行表示应该应用补丁的文件名。选择存在文件的最短名称。 2. 如果在前导文本中有 Index: 行,patch 命令尝试使用来自于那一行SEO靠我中的文件名。 3. 上下文差异 文件头优先于 Index: 行。 4. 如果从前导文本中不能确定文件名,patch 命令提示输入需要打 补丁的文件名。 SEO靠我 5. 如果不能找到原始文件,但是有适合的 SCCS 或 RCS 文件可用,patch 命令尝试获取或检出文件。 6. 如果前导文本包含 Prereq: 行,patch 命令从先SEO靠我决条件行中获取第一个词(通常是版本号)并且检查输入文件看是否能找到那个词。如果找不到,patch 命令在继续运行前会提示确认。

3 应用程序

如果 补丁文件包含不止一个补丁,patch 命令尝试应用每个差SEO靠我异列表,就好像它来自于单独的补丁文件。在这种情况下,为每个差异列表确定需要打 补丁的文件名,并且审查每个差异列表前的头文本以获得如文件名和修订版级别的信息。 如果指定 -c、 -e SEO靠我或 -n 标志,patch 命令将每块(hunk)内的信息分别解释成上下文差别、ed 编辑器差别或者正常差别。否则,patch 命令确定基于块(hunk)内信息格式的差别类型。 paSEO靠我tch 命令通过获取块(hunk)的首行序号和添加或减去由于应用前一块(hunk)而产生的任何行偏移来搜索位置以应用每一块(hunk)。如果在这一行位置不可能有精确匹配,patch 命令前后搜索以获取SEO靠我与块(hunk)的内容精确匹配的行集合。 如果找不到这些位置,且如果 patch 命令正在应用上下文差异列表,patch 命令能进行非精确搜索。fuzz factor 指定了非精确匹SEO靠我配的行数目。如果模糊因子设置成 1 或者更大,patch 命令执行第二次扫描,这一次忽略上下文的第一行和最后一行。如果没有匹配结果,且最大模糊因子设置成 2 或者更大, patch 命令执行第三次扫描SEO靠我,这一次会忽略上下文的前两行和最后两行。(缺省模糊因子最大值为 2)。如果找不到匹配的位置,patch 命令在拒绝文件中放置块(hunk)。创建拒绝文件时,其名称和输出文件一样,只是在文件名有后缀 .SEO靠我rej。使用 -r 标志可以覆盖此 命名约定。 以上下文差异列表格式写拒绝块(hunk),而不管 补丁文件的格式如何。如果输入是正常差别或 ed 编辑器样式差别,拒绝文件可能包含上下SEO靠我文格式零行差别。拒绝文件中块(hunk)的行编号可能与 补丁文件中的行编号不同。这是因为拒绝文件的行编号反映了新文件而不是老文件中故障块(hunk)的大约位置。 当完成每块(hunkSEO靠我)后,patch 命令会告诉您该块(hunk)是成功还是失败。也可以获知为每块(hunk)假定的新行编号。如果这与差异列表中指定的行编号不同,就会报告偏移量。patch 命令也说明是否使用模糊因子来进SEO靠我行匹配。 注:单一的大偏移可能表示块(hunk)安装位置不正确。模糊因子的使用可能表示布局不正确。

4  准备补丁

原则

准备将 补丁装载给其它用户的程序员应该考虑下面的附加原则: SEO靠我 * 如果想两次应用同一 补丁,patch 命令假定第二个 应用程序应该是逆向补丁,并且提示确认此逆向。因此,避免发送出这些逆向 补丁,因为它使用户疑惑他们是否已经应用了此补丁。 SEO靠我 * 建议保留使用最新 补丁级别更新的 patchlevel.h 文件。 补丁级别可以用作所发送的补丁文件中的第一个差异列表。如果 补丁中包含 Prereq: 行,用户不能应用顺序混乱的补丁,同SEO靠我时不收到警告。 * 在上下文差异列表的头中或者使用 Index: 行以确保正确指定了文件名。如果正在子目录中打某些 补丁,请确保通知补丁用户在需要时指定 -p 标志。 SEO靠我 * 可以通过发送差异列表创建文件,此列表比较一个空文件和想要创建的文件。然而,这个方法只有在想要创建的文件的确不存在于目标目录时才有效。 * 虽然可以将许多差分列表放置到一个文件SEO靠我中,但是将相关 补丁分组到单独的文件中会更好。 * patch 命令不能说明 ed 脚本中的行编号是否正确,只能在当它找到更改或删除命令时才能检测正常差异列表中不正确的行编号。使用模SEO靠我糊因子为 3 的上下文差异列表可能有同样的行编号问题。除非添加了一个适当的交互式接口,在这种情形下才使用上下文差异列表来检测更改的正确性。编译无误通常表示 补丁工作正常,但是它并不表示没有错误。 SEO靠我 * 只有当 补丁应用到与生成补丁的完全同一版本的文件中,才保证 patch 命令的结果。 * 如果代码重复,例如: #ifdef .SEO靠我.. NEWCODE #else ... OLDCODE # endif patch 命令不能为两个版本都打 补丁。如果 patSEO靠我ch 命令成功,它可能 补丁了错误版本但是返回了一个成功的退出状态。

标志

-b 在应用差别前保存每个修改后文件的副本。复制的原始文件归档时与原文件同名且添加了后缀 .orig。如果使用那个名称的文件已经SEO靠我存在,它就被覆盖。如果对同一文件应用多个 补丁,原始文件只生成一个副本(在第一次补丁时)。如果也指定 -o OutFile 标志,就不会创建 .orig 文件。但是如果指定文件已经存在,就创建 OutSEO靠我File.orig。 -B Prefix 指定备份文件名称的前缀。此标志只有在和 -b 标志连接使用时才有效。 -c 将 补丁文件解释成上下文差异列表(diff -SEO靠我c 或 diff -C 命令的输出)。此标志不能和 -e 或 -n 标志一起使用。 -d Directory 在处理前,更改 当前目录到指定目录。 -D DefinSEO靠我e 使用下面的 C 预处理器构造标记更改: #ifdef Define ... (NEWCODE) #else ... (OLDSEO靠我CODE) #endif /* Define */ Define 变量用作差分符号。此标志只有当正常或上下文格式差异列表用作 补丁文件时才有效。 SEO靠我-e 将 补丁文件解释成 ed 编辑器 脚本。此标志不能和 -c 或 -n 标志一起使用。 -f 禁止查询用户。要禁止注释,使用 -s 标志。 -F Number SEO靠我设置最大模糊因子。此标志只应用于上下文差异列表,它使 patch 命令在确定块(hunk)的安装位置时忽略指定行编号。如果没有指定 -F 标志,缺省模糊因子为 2。此因子不可以设置成大于上下文差异列表SEO靠我中内容的行的数目(通常为 3)。 注:较大的模糊因子会增加错误 补丁的可能性。 -i PatchFile 从指定文件,而不是从标准输入中读取 补丁信息。 SEO靠我 -l (L 的小写)使差异列表 脚本中的任何空格字符序列匹配输入文件中的任何空格字符序列。精确匹配其它字符。 -n 将 脚本解释成正常差异列表。此标志不能和 -c 或 -e SEO靠我标志一起使用。 -N 忽略差别已经向文件应用了的 补丁。缺省情况下,会拒绝已经应用的 补丁。 -o OutFile 复制要打 补丁的文件,然后应用更改,接着将修改版SEO靠我本写到指定的输出文件。单个文件的多个 补丁应用于以前补丁所创建的文件的中间版本。因此,多 补丁会生成输出文件的多个连接版本。 -p Number 设置路径名的剥离数目,它控制如何处理SEO靠我在 补丁文件中找到的路径名称。如果将文件保留在与指定路径不同的目录中,此标志就有用。剥离数目指定了从路径名前去除多少个 斜杠。也去除所有中间的目录名。例如,假定 补丁文件指定 /u/leon/src/SEO靠我blurf1/blurf1.c: * -p 0 留下未修改的完整路径名。 * -p 1 除去前导斜杠,留下 u/leon/src/blurf1/blurf1.c。 SEO靠我 * -p 4 卸下四个斜杠和三个目录,留下 blurf1/blurf1.c。 如果没有指定 -p 标志,只使用基本名称(最后的路径名称组件)。此标志只有在没有指定 SEO靠我File 参数时才起作用。 -r RejectFile 覆盖缺省拒绝文件名。通过附加后缀 .rej 到原始文件名中,就形成了缺省拒绝文件名。 -R 逆向 补丁 脚本SEO靠我理解。例如,如果从新版本到旧版本创建差异列表,使用 -R 标志使 patch 命令在应用前逆向 脚本的每个部分。以交换格式保存拒绝差别。 -R 标志不能和 ed 脚本一起使用,因为其中只有很少的信息可SEO靠我以重新构造逆向操作。如果没有指定 -R 标志,patch 命令尝试以逆向理解和正常理解应用每个部分,直到成功应用 补丁文件的每一部分。如果尝试成功,提示用户确定是否应该设置 -R 标志。 SEO靠我 注:如果此方法和第一个命令是附加命令(就是说,逆序是删除)的正常差异列表一起使用,它就不能检测逆向 补丁。因为空上下文无论在何处都匹配,所以附加总是成功的。幸运的是,大多数 补丁是添加或更改行而SEO靠我不是删除行。因此大多数逆序的正常差异列表以一个删除开始,它导致故障,并且引起启发(heuristic)。 -s 静默地进行 补丁,直到发生错误。 -v 打印修订版头SEO靠我和 补丁级别。如果 -v 标志和其它标志一起使用,就忽略其它标志。 -x Number 设置内部调试标志。此标志只适用于 patch 命令开发者。 退出状态 SEO靠我 返回下面的出口值: 0 成功完成。 1 产生错误。

示例

1. 要将 difflisting 文件中的差异列表应用到 prog.c 文件,请输入: SEO靠我 patch -i difflisting prog.c 2. 要保存 prog.c 文件的原始版本,请输入: patch -b -i difflistinSEO靠我g prog.c 它将更改应用到 prog.c 并且在 prog.c.orig 文件中保存 prog.c 的原始内容。 3. 要打 补丁到 prog.c 文件而不改SEO靠我变原始版本,请输入: patch -i difflisting -o prog.new prog.c 它将 prog.c 当成 源文件使用,但是更改后的版本写到名为SEO靠我 prog.new 的文件中。

文件

/usr/bin/patch 包含 patch 命令。

AIX Version 4.3 Commands Reference, Volume 4

patch CommanSEO靠我d

Purpose

Applies changes to files.

Syntax

patch-b [ -B Prefix ] ] [ -f ] [ -l ] [ -N ] [ -R ] [ -s ] [ -v ] [ -c | -e | -nSEO靠我] [ -d Directory ] [ -D Define ] [ -F Number ] [ -i PatchFile ] [ -o OutFile ] [ -p Number ] [ -r RejectFile ] [ -xSEO靠我Number ] [ File ]

Description

The patchcommand reads a source files instructions on how to change a filSEO靠我e, then applies the changes. The source file contains difference listings (or diff listings) produceSEO靠我d by thediffcommand. The diff listings are the result of comparing two files and building instructioSEO靠我ns about how to reconcile the differences. By default, thepatchcommand uses the source file read froSEO靠我m standard input, but this can be overridden using the-i flag and the PatchFile variable.

Diff listingSEO靠我s come in three formats: normal, context, or in the style of the ed editor. Thepatchcommand determinSEO靠我es the diff listing format, unless overruled by the-c, -e, or -n flags.

By default, the patched version SEO靠我of a file replaces the original version. When the-bflag is specified, the original of each patched fSEO靠我ile is saved in a file of the same name with the suffix.origappended to it. You may also specify wheSEO靠我re you want the output to go with the-o flag.

The -pflag makes it possible to customize a patch file toSEO靠我 local user directory structures without manually editing the patch file. This is done by specifyingSEO靠我 how many components to remove from the full path name. For example, if the patch file contained theSEO靠我 path name /curds/whey/src/blurfl/blurfl.c, then:

-p 0 causes the entire path name to be used.-p 1remoSEO靠我ves the leading slash, leaving curds/whey/src/blurfl/blurfl.c.-p 4removes leading slashes and the fiSEO靠我rst three directories, leaving blurfl/blurfl.c.

Not specifying the -p flag causes the patchcommand to usSEO靠我e the base name. In the above example, that would be blurfl.c.

Patch File Format

The patch file must cSEO靠我ontain one or more lines of header information followed by one or more patches. Each patch must contSEO靠我ain one or more lines of file name identification in the format produced by thediff -ccommand, and onSEO靠我e or more sets of diff command output, customarily called hunks.

The patchcommand skips any leading textSEO靠我 in a patch file, applies the actual diff listing, and skips any trailing text. Thus, you could use SEO靠我as a patch file an article or message that includes a diff listing, and thepatchcommand would still SEO靠我work. In such a case, if the entire diff listing is indented by a consistent amount, thepatchcommandSEO靠我 will also adjust for that spacing.

To change a line range within the original file, each hunk withinSEO靠我 a patch must be a separate diff listing. The line numbers for successive hunks within a patch must SEO靠我occur in ascending order.

File Name Determination

If no File parameter is specified, the patchcommand pSEO靠我erforms the following steps to obtain the name of the file to edit:

In the header of a context diff lSEO靠我isting, the file name is determined from lines beginning with *** (three asterisks) or --- (three daSEO靠我shes). A line beginning with *** indicates the name of the file from which the patches were taken, wSEO靠我hile a line beginning with --- indicates the name of the file to which the patches should be appliedSEO靠我. The shortest name of an existing file is selected.If there is an Index: line in the leading text, SEO靠我thepatchcommand tries to use the file name from that line.A context diff header takes precedence oveSEO靠我r an Index: line.If no file name can be determined from the leading text, thepatchcommand prompts yoSEO靠我u for the name of the file to patch.If the original file cannot be found, but a suitable SCCS or RCSSEO靠我 file is available, thepatchcommand attempts to get or check out the file.If the leading text contaiSEO靠我ns a Prereq: line, thepatchcommand takes the first word from the prerequisites line (normally a versSEO靠我ion number) and checks the input file to see if that word can be found. If not, thepatchcommand promSEO靠我pts you for confirmation before proceeding. Patch Application

If the patch file contains moreSEO靠我 than one patch, thepatchcommand tries to apply each diff listing as if it came from a separate patcSEO靠我h file. In this case, the name of the file to patch is determined for each diff listing, and the heaSEO靠我der text before each diff listing is examined for information such as file name and revision level.

ISEO靠我f you specify the-c, -e, or -n flag, the patchcommand interprets information within each hunk as a conteSEO靠我xt difference, an ed editor difference, or a normal difference, respectively. Otherwise, thepatchcomSEO靠我mand determines the type of difference based on the format of the information within the hunk.

The patSEO靠我chcommand searches for the place to apply each hunk by taking the first line number of the hunk and SEO靠我adding or subtracting any line offset caused by applying the previous hunk. If an exact match is notSEO靠我 possible at this line location, thepatchcommand scans both forward and backward for a set of lines SEO靠我matching the hunks content exactly.

If no such place is found, and if the patchcommand is applying a cSEO靠我ontext diff listing, thepatchcommand can search for a less exact match. A fuzz factor specifies how SEO靠我many lines can be inexactly matched. If the fuzz factor is set to 1 or more, thepatchcommand performSEO靠我s a second scan, this time ignoring the first and last line of context. If no match results, and theSEO靠我 maximum fuzz factor is set to 2 or more, thepatchcommand performs a third scan, this time ignoring SEO靠我the first two lines and the last two lines of the context. (The default maximum fuzz factor is 2.) ISEO靠我f no match is found, thepatchcommand places the hunk in a reject file. The reject file is created wiSEO靠我th the same name as the output file and the suffix.rej. This naming convention can be overridden by SEO靠我using the -r flag.

The rejected hunk is written in context diff listing form, regardless of the format SEO靠我of the patch file. If the input was a normal or ed editor style difference, the reject file may contSEO靠我ain differences with zero lines of context format. The line numbers on the hunks in the reject file SEO靠我may be different from the line numbers in the patch file. This is because the reject file line numbeSEO靠我rs reflect the approximate locations for the failed hunks in the new file rather than the old one.

AsSEO靠我 each hunk is completed, thepatchcommand tells you whether the hunk succeeded or failed. You are alsSEO靠我o informed of the new line number assumed for each hunk. If this is different from the line number sSEO靠我pecified in the diff listing, you are notified of the offset. Thepatchcommand also tells you if a fuSEO靠我zz factor was used to make the match.

Note: A single large offset may be an indication that a hunk wasSEO靠我 installed in the wrong place. Use of a fuzz factor may also indicate bad placement. PreparSEO靠我ing Patches for Other Users

Programmers preparing patches that will be shipped to other users should SEO靠我consider the following additional guidelines:

If you try to apply the same patch twice, the patchcommaSEO靠我nd assumes the second application should be a reverse patch and prompts you for confirmation of thisSEO靠我 reversal. Therefore, avoid sending out reversed patches, since this makes users wonder whether theySEO靠我 already applied the patch.It is recommended that you keep apatchlevel.hfile that is updated with thSEO靠我e latest patch level. The patch level can then be used as the first diff listing in the patch file ySEO靠我ou send out. If your patch includes a Prereq: line, users cannot apply patches out of order without SEO靠我receiving a warning.Make sure you specify the file names correctly, either in a context diff listingSEO靠我 header or with an Index: line. If you are patching something in a subdirectory, be sure to tell theSEO靠我 patch user to specify a-pflag as needed.You can create a file by sending out a diff listing that coSEO靠我mpares a null file to the file you want to create. However, this only works if the file you want to SEO靠我create does not already exist in the target directory.While you may be able to put many diff listingSEO靠我s into one file, it is advisable to group related patches into separate files.Thepatchcommand cannotSEO靠我 tell if the line numbers are incorrect in an ed script, and can only detect bad line numbers in a nSEO靠我ormal diff listing when it finds a change or a delete command. A context diff listing using a fuzz fSEO靠我actor of 3 may have the same line-number problem. Until a suitable interactive interface is added, uSEO靠我se a context diff listing in such cases to check the changes for accuracy. Compilation without errorSEO靠我s usually means that the patch worked, but it is not an infallible indicator.The results of thepatchSEO靠我command are guaranteed only when the patch is applied to exactly the same version of the file from wSEO靠我hich the patch was generated.If the code has been duplicated, for example: #ifdef ... NEWCODSEO靠我E #else ... OLDCODE # endif thepatchcommand is incapable of patching both veSEO靠我rsions. If thepatchcommand succeeds, it may have patched the wrong version and return a successful eSEO靠我xit status.

Flags

-bSaves a copy of each modified file before the differences are applied. The copied SEO靠我original is filed with the same name and the suffix.orig. If a file by that name already exists, it SEO靠我is overwritten. If multiple patches are applied to the same file, only one copy is made of the origiSEO靠我nal file at the time of the first patch. If the-o OutFile flag is also specified, the .origfile is notSEO靠我 created. But if the specified out file already exists, OutFile.orig is created.-BPrefixSpecifies a pSEO靠我refix to the backup file name. This flag only works in conjunction with the-b flag.-cInterprets the pSEO靠我atch file as a context diff listing (the output of the diff -c or diff -Ccommand). This flag cannot be SEO靠我used with the-e or -n flag.-dDirectoryChanges the current directory to the specified directory before pSEO靠我rocessing.-DDefineMarks changes with the following C preprocessor construct: #ifdef Define .SEO靠我.. (NEWCODE) #else ... (OLDCODE) #endif /* Define */

The Define variable is uSEO靠我sed as the differentiating symbol. This flag only works when the normal or context form of diff listSEO靠我ing is used as a patch file.

-eInterprets the patch file as an ed editor script. This flag cannot be SEO靠我used with the-c or -n flag.-fSuppresses queries to the user. To suppress commentary, use the -s flag.-FNuSEO靠我mberSets the maximum fuzz factor. This flag applies to context diff listings only and causes thepatcSEO靠我h command to ignore the specified number of lines when determining where to install a hunk. If the -FfSEO靠我lag is not specified, the default fuzz factor is 2. The factor may not be set to more than the numbeSEO靠我r of lines of content in the context diff listing (ordinarily 3).Note: A larger fuzz factor increasesSEO靠我 the odds of a faulty patch.-iPatchFileReads the patch information from the specified file, rather tSEO靠我han from standard input.-l(lowercase L) Causes any sequence of blank characters in the diff listing SEO靠我script to match any sequence of blank characters in the input file. Other characters are matched exaSEO靠我ctly.-nInterprets the script as a normal diff listing. This flag cannot be used with the -c or -e flag.-SEO靠我NIgnores patches where the differences have already been applied to the file. By default, already-apSEO靠我plied patches are rejected.-oOutFileCopies the files to be patched, applies the changes, then writesSEO靠我 the modified version to the specified output file. Multiple patches for a single file are applied tSEO靠我o the intermediate versions of the file created by any previous patches. Therefore, multiple patchesSEO靠我 result in multiple, concatenated versions of the output file.-pNumberSets the path name strip countSEO靠我, which controls how path names found in the patch file are treated. This flag is useful if you keepSEO靠我 your files in a directory different from the specified path. The strip count specifies how many slaSEO靠我shes are stripped from the front of the path name. Any intervening directory names are also strippedSEO靠我. For example, assume a patch file specified /u/leon/src/blurf1/blurf1.c:-p 0leaves the entire path SEO靠我name unmodified.-p 1 removes the leading slash, leaving u/leon/src/blurf1/blurf1.c.-p 4removes four sSEO靠我lashes and three directories, leaving blurf1/blurf1.c.

If the -pflag is not specified, only the base nSEO靠我ame (the final path name component) is used. This flag works only when the File parameter is not speSEO靠我cified.

-rRejectFileOverrides the default reject file name. The default reject file name is formed bySEO靠我 appending the suffix.rej to the original file name.-RReverses the sense of the patch script. For exaSEO靠我mple, if the diff listing was created from new version to old version, using the-R flag causes the patSEO靠我chcommand to reverse each portion of the script before applying it. Rejected differences are saved iSEO靠我n swapped format. The-Rflag cannot be used with ed scripts, because there is too little information SEO靠我to reconstruct the reverse operation. If the-R flag is not specified, the patchcommand attempts to appSEO靠我ly each portion in its reversed sense as well as in its normal sense, until a portion of the patch fSEO靠我ile is successfully applied. If the attempt is successful, the user is prompted to determine if the-SEO靠我R flag should be set. Note: This method cannot detect a reversed patch if used with a normal diff listiSEO靠我ng where the first command is an append (that is, would have been a delete). Appends always succeed SEO靠我because a null context matches anywhere. Fortunately, most patches add or change lines rather than dSEO靠我elete lines. Therefore most reversed normal diff listings begin with a delete, causing a failure andSEO靠我 triggering heuristics.-sPatches silently unless an error occurs.-vPrints the revision header and paSEO靠我tch level. If the-v flag is used with other flags, the other flags are ignored.-xNumberSets internal SEO靠我debugging flags. This flag is only forpatch command developers.

Exit Status

The following exit values aSEO靠我re returned:

0Successful completion.1An error occurred.

Examples

To apply diff listings in the difflistSEO靠我ing file to the prog.c file, enter: patch -i difflisting prog.c To save the original version of the SEO靠我prog.c file, enter: patch -b -i difflisting prog.c This applies changes to prog.c and saves the origSEO靠我inal contents of prog.c in the file prog.c.orig.To patch the prog.c file without altering the originSEO靠我al version, enter: patch -i difflisting -o prog.new prog.c This uses prog.c as a source file, but thSEO靠我e changed version is written to a file named prog.new.

Files

/usr/bin/patchContains the patch command.

ReSEO靠我lated Information

The diff command, ed command.

“SEO靠我”的新闻页面文章、图片、音频、视频等稿件均为自媒体人、第三方机构发布或转载。如稿件涉及版权等问题,请与 我们联系删除或处理,客服邮箱:html5sh@163.com,稿件内容仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同 其观点或证实其内容的真实性。

网站备案号:浙ICP备17034767号-2