patchのヘルプ・マニュアル
日本語 英語
patch --help
Usage: patch [OPTION]... [ORIGFILE [PATCHFILE]]
Input options:
-p NUM --strip=NUM Strip NUM leading components from file names.
-F LINES --fuzz LINES Set the fuzz factor to LINES for inexact matching.
-l --ignore-whitespace Ignore white space changes between patch and input.
-c --context Interpret the patch as a context difference.
-e --ed Interpret the patch as an ed script.
-n --normal Interpret the patch as a normal difference.
-u --unified Interpret the patch as a unified difference.
-N --forward Ignore patches that appear to be reversed or already applied.
-R --reverse Assume patches were created with old and new files swapped.
-i PATCHFILE --input=PATCHFILE Read patch from PATCHFILE instead of stdin.
Output options:
-o FILE --output=FILE Output patched files to FILE.
-r FILE --reject-file=FILE Output rejects to FILE.
-D NAME --ifdef=NAME Make merged if-then-else output using NAME.
-m --merge Merge using conflict markers instead of creating reject files.
-E --remove-empty-files Remove output files that are empty after patching.
-Z --set-utc Set times of patched files, assuming diff uses UTC (GMT).
-T --set-time Likewise, assuming local time.
--quoting-style=WORD output file names using quoting style WORD.
Valid WORDs are: literal, shell, shell-always, c, escape.
Default is taken from QUOTING_STYLE env variable, or 'shell' if unset.
Backup and version control options:
-b --backup Back up the original contents of each file.
--backup-if-mismatch Back up if the patch does not match exactly.
--no-backup-if-mismatch Back up mismatches only if otherwise requested.
-V STYLE --version-control=STYLE Use STYLE version control.
STYLE is either 'simple', 'numbered', or 'existing'.
-B PREFIX --prefix=PREFIX Prepend PREFIX to backup file names.
-Y PREFIX --basename-prefix=PREFIX Prepend PREFIX to backup file basenames.
-z SUFFIX --suffix=SUFFIX Append SUFFIX to backup file names.
-g NUM --get=NUM Get files from RCS etc. if positive; ask if negative.
Miscellaneous options:
-t --batch Ask no questions; skip bad-Prereq patches; assume reversed.
-f --force Like -t, but ignore bad-Prereq patches, and assume unreversed.
-s --quiet --silent Work silently unless an error occurs.
--verbose Output extra information about the work being done.
--dry-run Do not actually change any files; just print what would happen.
--posix Conform to the POSIX standard.
-d DIR --directory=DIR Change the working directory to DIR first.
--reject-format=FORMAT Create 'context' or 'unified' rejects.
--binary Read and write data in binary mode.
-v --version Output version info.
--help Output this help.
Report bugs to .
Usage: patch [OPTION]... [ORIGFILE [PATCHFILE]]
Input options:
-p NUM --strip=NUM Strip NUM leading components from file names.
-F LINES --fuzz LINES Set the fuzz factor to LINES for inexact matching.
-l --ignore-whitespace Ignore white space changes between patch and input.
-c --context Interpret the patch as a context difference.
-e --ed Interpret the patch as an ed script.
-n --normal Interpret the patch as a normal difference.
-u --unified Interpret the patch as a unified difference.
-N --forward Ignore patches that appear to be reversed or already applied.
-R --reverse Assume patches were created with old and new files swapped.
-i PATCHFILE --input=PATCHFILE Read patch from PATCHFILE instead of stdin.
Output options:
-o FILE --output=FILE Output patched files to FILE.
-r FILE --reject-file=FILE Output rejects to FILE.
-D NAME --ifdef=NAME Make merged if-then-else output using NAME.
-m --merge Merge using conflict markers instead of creating reject files.
-E --remove-empty-files Remove output files that are empty after patching.
-Z --set-utc Set times of patched files, assuming diff uses UTC (GMT).
-T --set-time Likewise, assuming local time.
--quoting-style=WORD output file names using quoting style WORD.
Valid WORDs are: literal, shell, shell-always, c, escape.
Default is taken from QUOTING_STYLE env variable, or 'shell' if unset.
Backup and version control options:
-b --backup Back up the original contents of each file.
--backup-if-mismatch Back up if the patch does not match exactly.
--no-backup-if-mismatch Back up mismatches only if otherwise requested.
-V STYLE --version-control=STYLE Use STYLE version control.
STYLE is either 'simple', 'numbered', or 'existing'.
-B PREFIX --prefix=PREFIX Prepend PREFIX to backup file names.
-Y PREFIX --basename-prefix=PREFIX Prepend PREFIX to backup file basenames.
-z SUFFIX --suffix=SUFFIX Append SUFFIX to backup file names.
-g NUM --get=NUM Get files from RCS etc. if positive; ask if negative.
Miscellaneous options:
-t --batch Ask no questions; skip bad-Prereq patches; assume reversed.
-f --force Like -t, but ignore bad-Prereq patches, and assume unreversed.
-s --quiet --silent Work silently unless an error occurs.
--verbose Output extra information about the work being done.
--dry-run Do not actually change any files; just print what would happen.
--posix Conform to the POSIX standard.
-d DIR --directory=DIR Change the working directory to DIR first.
--reject-format=FORMAT Create 'context' or 'unified' rejects.
--binary Read and write data in binary mode.
-v --version Output version info.
--help Output this help.
Report bugs to .
man patch
PATCH(1) PATCH(1)
名前
patch - オリジナルファイルに差分ファイルを適用する
書式
patch [options] [originalfile [patchfile]]
通常はもっと簡単に
patch -pnum (1985-01).
パッチを送る人への注意
パ ッチを送ろうとする場合に心に留めておかなければならない点がいくつかあ
る。
パッチを機械的に作ること。よい方法は diff -Naur old new のようなコマ ン
ド を 使 うことである。 new と old はそれぞれ新旧のディレクトリである。
old と new には 1 個もスラッシュがあってはいけない。 diff コマンドの ヘ
ッ ダに含まれる日時は伝統的な Unix 形式を使って協定世界時で書かれていな
ければならない。そうすればパッチを受け取った人が -Z または --set-utc オ
プ ションを使うことができる。次のものは Bourne シェル形式を使ったコマン
ド例である:
LC_ALL=C TZ=UTC0 diff -Naur gcc-2.7 gcc-2.8
受け取る人にはパッチの当て方を伝える。つまり、どのディレクトリに cd す
ればよいかとどの patch オプションを使えばよいかを伝える。オプション文字
列は -Np1 が推奨される。受け取った人になったつもりで手順を試し、オリ ジ
ナルファイルのコピーを取って、作ったパッチを当ててみる。
送 り出すパッチファイルの最初の diff として、パッチレベルをインクリメン
トしていく patchlevel.h ファイルを入れておくと、多くの人の面倒を軽減 で
きる。パッチに Prereq: 行を加えておけば、順番を間違えて警告を食らうのを
防ぐことができる。
/dev/null や日時が Epoch (1970-01-01 00:00:00 UTC) の空のファイルと作成
し たいファイルを比較した diff を送ることで、ファイルを作成することがで
きる。この方法はターゲットのディレクトリに作成したいファイルがまだ存 在
しない場合に限って動作する。反対に、削除したいファイルと日時が Epoch の
空のファイルを比較したコンテキスト diff を送ることで、ファイルを削除 す
る こ と が で き る 。ファイルは patch が POSIX 準拠でなく、 -E または
--remove-empty-files オプションが指定されない場合に削除される。ファイル
を作成したり削除したりするパッチを生成する簡単な方法は、 GNU diff の -N
または --new-file オプションを使うことである。
受け取った人が -pN オプションを使うことが想定される場合、次のようなパッ
チを送らないこと:
diff -Naur v2.0.29/prog/README prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ prog/README Mon Mar 17 14:58:22 1997
なぜなら二つのファイル名は異なる数のスラッシュを含んでおり、 patch のバ
ージョンによってファイル名を異なるように解釈するからである。混乱を避 け
るために、代わりに次のようなパッチを送ること:
diff -Naur v2.0.29/prog/README v2.0.30/prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
バックアップファイルと名前が同じファイル、例えば README.orig と比較した
パッチを送らないこと。この方法では patch が混乱して、正しいファイルでは
な くバックアップファイルにパッチを当ててしまうかもしれないからである。
そうではなく、ファイル名が同じで別のディレクトリにあるファイルどうし 、
例えば old/README と new/README を比較したパッチを送ること。
反 転したパッチを送らないように注意すること。もうパッチを当てたのかと思
ってしまうからである。
自動生成されるファイル ( 例えば、 makefile に configure: configure.in
と いう行がある場合の configure というファイル ) を変更するパッチを作ら
ないようにすること。受け取った人は自動生成されるファイルを再生成する こ
と ができるからである。自動生成されるファイルの diff を送らなければなら
ない場合、 UTC を用いて diff を作り、受け取った人に -Z または --set-utc
オ プションを使ってパッチを当ててもらい、パッチの当たったファイルに依存
する、パッチの当たっていないファイルを削除 し て も ら う ( 例 え ば
make clean で ) 。
582 もの差分リストを 1 個のファイルに入れなくても済むのであれば、ぐちゃ
ぐちゃになってしまった場合に備えて関連するパッチを別々のファイルにま と
めておくのが賢明である。
エラーと終了ステータス
エラーは一般に、 patch がパッチファイルを解析できなかったことを示してい
る。
--verbose オプションを指定した場合、 Hmm... はパッチファイルの中に処 理
されなかったテキストがあり、 patch がテキストの中にパッチがあるかどうか
を必死に探そうとしていることを表している。パッチが見つかると、そのパ ッ
チがどんな種類のものかを示す。
patch の終了ステータスは、すべての hunk の適用に成功した場合に 0 、一部
の hunk が適用できなかった場合に 1 、もっと深刻な問題に見舞われた場合に
2 となる。バッチ処理で複数のパッチを適用する場合、終了ステータスをチェ
ックして、部分的にしかパッチの当たっていないファイルに以降のパッチを 当
てないようにすることが必要である。
警告
コ ンテキスト diff は空のファイルや空のディレクトリ、シンボリックリンク
などのスペシャルファイルの作成や削除を確実に表すことはできない。所有 者
や アクセス権限、あるファイルが別のファイルのハードリンクであることとい
ったファイルメタデータの変更を表すこともできない。もしそのような変更 も
必 要であれば、別に手順書 ( 例えば、シェルスクリプト ) を用意して、パッ
チに添付しなければならない。
patch は、 ed スクリプト中の行番号がはみ出しているかどうかは分からな い
し 、ノーマル diff の行番号の間違いは変更や削除を見つけた場合に限って検
出できる。 fuzz factor が 3 のコンテキスト diff も同じ問題に遭遇する か
も しれない。適当な対話式のインタフェースが導入されるまでは、このような
場合はコンテキスト diff を作って変更が妥当かどうかを確認しなければな ら
な い。もちろん、エラーなくコンパイルできたことはパッチがうまく当たった
よい証拠になるが、必ずしもそうとはいえない。
patch は多数の推測が必要な場合であっても、通常は正しい結果を出す。し か
し 、結果が正しいことが保証されるのは、そのパッチが生成されたファイルと
全く同一のバージョンのファイルに適用された場合だけである。
互換性の問題
POSIX 標準は patch の古典的な振る舞いと異なる振る舞いを規定してい る 。
patch のバージョン 2.1 およびそれ以前 ( これらは POSIX に準拠していない
) と相互に運用しなければならない場合、これらの違いを知っておく必要が あ
る。
· 古典的な patch では、 -p オプションの引数は省略可能であり、単独の -p
は -p0 と同等であった。今日の patch では -p オプションに引数が必須で
、 -p 0 が -p0 と同等である。互換性を最大限に保つために、 -p0 や -p1
といったオプションを使う。
また、古典的な patch はパスプレフィクスを取り除く際、スラッシュの 数
を 単純に数えていた。今日の patch はパス名の要素を数える。つまり、 1
個または複数の隣接するスラッシュの列は 1 個のスラッシュとして数え ら
れる。互換性を最大限に保つために、ファイル名に // を含むパッチは送ら
ないようにすること。
· 古典的な patch では、デフォルトでバックアップが有効であった。今日 の
patch では -b または --backup オプションで有効になる。
反 対に、 POSIX patch では、不整合があってもバックアップは一切作られ
ない。 GNU patch では、この振る舞いは --no-backup-if-mismatch オプシ
ョ ン か、 --posix オプションまたは POSIXLY_CORRECT 環境変数で POSIX
準拠にするかで有効になる。
古典的な patch の -b suffix オプションは GNU patch の -b -z suffix
オプションと同等である。
· 古典的な patch は、パッチヘッダからパッチを当てるファイルの名前を決
定するのに複雑な ( しかも完全にはドキュメントになっていない ) 手法を
用 いていた。この手法は POSIX に準拠しておらず、いくつか誤りもあった
。今日の patch は異なる、同じくらい複雑な (しかしドキュメントはま し
な) 手法を用いており、オプションで POSIX に準拠することができる。誤
りが減っているとよいのだが。 2 つの手法は、コンテキスト diff のヘ ッ
ダのファイル名と Index: の行がプレフィクスを除いて全く同じである場合
には互換性がある。作ったパッチは、それぞれのヘッダのファイル名がすべ
て同じ数のスラッシュを含んでいれば、通常は互換性がある。
· 古典的な patch がユーザに質問をするときは、質問を標準エラーに出力し
、以下のリストのうちターミナルである最初のファイルから回答を求め る:
標準エラー、標準出力、 /dev/tty、標準入力。今日の patch は質問は標準
出力に出力し、 /dev/tty から回答を得る。回答のデフォルトのうちいくつ
か は変更されており、デフォルトの回答を使っても patch が無限ループに
陥らないようになっている。
· 古典的な patch は、失敗した hunk の数をステータス値として終了し、 本
当 の問題に出くわした場合は 1 をステータス値としていた。今日の patch
は hunk が失敗すると 1 で終了し、問題がある場合は 2 で終了する。
· GNU patch、古典的 patch、 POSIX 準拠の patch のどれを使うか分から な
い人に宛てて手順を送る場合、次のオプション以外は使わないこと。以下の
リストでは空白も意味を持ち、引数は必須である。
-c
-d dir
-D define
-e
-l
-n
-N
-o outfile
-pnum
-R
-r rejectfile
バグ
バグは電子メールで へ報告してください。
patch は部分一致や大きく逸脱したオフセットやひっくり返ったコードに対 し
てもっと賢くすることもできるだろうが、その道は長いだろう。
コ ー ドが重複している場合 ( 例えば #ifdef OLDCODE ... #else ... #endif
のように区切られている場合 ) 、 patch は両方のバージョンにパッチを当 て
る ことはできない。もしパッチが当たったとしたら、間違ったほうにパッチが
当たってしまっていることもよくあり、それでも成功したから続きをやれと い
うだろう。
すでに当たっているパッチを当てようとすると、 patch はパッチが反転してい
ると思い、パッチを戻すかを尋ねる。これは機能のひとつとみなすことがで き
よう。
著作権
Copyright 1984, 1985, 1986, 1988 Larry Wall.
Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a per-
mission notice identical to this one.
Permission is granted to copy and distribute translations of this man-
ual into another language, under the above conditions for modified
versions, except that this permission notice may be included in trans-
lations approved by the copyright holders instead of in the original
English.
著者
オ リジナルの patch は Larry Wall が書いた。 Paul Eggert は恣意的な制限
を取り除き、バイナリファイルへの対応や、ファイルの時刻設定、ファイル の
削 除 を追加した。また、より POSIX に準拠するようにした。ほかには Wayne
Davison が unidiff への対応を追加し、 David MacKenzie がコンフィグレ ー
ションとバックアップへの対応を追加した。
GNU 2005/08/08 PATCH(1)
PATCH(1) PATCH(1)
NAME
patch - apply a diff file to an original
SYNOPSIS
patch [options] [originalfile [patchfile]]
but usually just
patch -pnum >>>>>> lines. A typical conflict will look like
this:
<<<<<<<
lines from the original file
=======
lines from the patch
>>>>>>>
If there are conflicts, the user should edit the result and delete
one of the alternatives. This option implies --forward and does not
take the --fuzz=num option into account.
-n or --normal
Interpret the patch file as a normal diff.
-N or --forward
Ignore patches that seem to be reversed or already applied. See
also -R.
-o outfile or --output=outfile
Send output to outfile instead of patching files in place. Do not
use this option if outfile is one of the files to be patched. When
outfile is -, send output to standard output, and send any messages
that would usually go to standard output to standard error.
-pnum or --strip=num
Strip the smallest prefix containing num leading slashes from each
file name found in the patch file. A sequence of one or more adja-
cent slashes is counted as a single slash. This controls how file
names found in the patch file are treated, in case you keep your
files in a different directory than the person who sent out the
patch. For example, supposing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
setting -p0 gives the entire file name unmodified, -p1 gives
u/howard/src/blurfl/blurfl.c
without the leading slash, -p4 gives
blurfl/blurfl.c
and not specifying -p at all just gives you blurfl.c. Whatever you
end up with is looked for either in the current directory, or the
directory specified by the -d option.
--posix
Conform more strictly to the POSIX standard, as follows.
· Take the first existing file from the list (old, new, index) when
intuiting file names from diff headers.
· Do not remove files that are empty after patching.
· Do not ask whether to get files from RCS, ClearCase, Perforce, or
SCCS.
· Require that all options precede the files in the command line.
· Do not backup files when there is a mismatch.
--quoting-style=word
Use style word to quote output names. The word should be one of the
following:
literal
Output names as-is.
shell Quote names for the shell if they contain shell metacharac-
ters or would cause ambiguous output.
shell-always
Quote names for the shell, even if they would normally not
require quoting.
c Quote names as for a C language string.
escape Quote as with c except omit the surrounding double-quote
characters.
You can specify the default value of the --quoting-style option with
the environment variable QUOTING_STYLE. If that environment vari-
able is not set, the default value is shell.
-r rejectfile or --reject-file=rejectfile
Put rejects into rejectfile instead of the default .rej file. When
rejectfile is -, discard rejects.
-R or --reverse
Assume that this patch was created with the old and new files
swapped. (Yes, I’m afraid that does happen occasionally, human
nature being what it is.) patch attempts to swap each hunk around
before applying it. Rejects come out in the swapped format. The -R
option does not work with ed diff scripts because there is too lit-
tle information to reconstruct the reverse operation.
If the first hunk of a patch fails, patch reverses the hunk to see
if it can be applied that way. If it can, you are asked if you want
to have the -R option 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 diff and 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 matches anywhere. Luckily, most
patches add or change lines rather than delete them, so most
reversed normal diffs begin with a delete, which fails, triggering
the heuristic.)
--reject-format=format
Produce reject files in the specified format (either context or uni-
fied). Without this option, rejected hunks come out in unified diff
format if the input patch was of that format, otherwise in ordinary
context diff form.
-s or --silent or --quiet
Work silently, unless an error occurs.
-t or --batch
Suppress questions like -f, but make some different assumptions:
skip patches whose headers do not contain file names (the same as
-f); skip patches for which the file has the wrong version for the
Prereq: line in the patch; and assume that patches are reversed if
they look like they are.
-T or --set-time
Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use local time. This option is not recommended, because
patches using local time cannot easily be used by people in other
time zones, and because local time stamps are ambiguous when local
clocks move backwards during daylight-saving time adjustments.
Instead of using this option, generate patches with UTC and use the
-Z or --set-utc option instead.
-u or --unified
Interpret the patch file as a unified context diff.
-v or --version
Print out patch’s revision header and patch level, and exit.
-V method or --version-control=method
Use method to determine backup file names. The method can also be
given by the PATCH_VERSION_CONTROL (or, if that’s not set, the VER-
SION_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.
The value of method is like the GNU Emacs ‘version-control’ vari-
able; patch also recognizes synonyms that are more descriptive. The
valid values for method are (unique abbreviations are accepted):
existing or nil
Make numbered backups of files that already have them, otherwise
simple backups. This is the default.
numbered or t
Make numbered backups. The numbered backup file name for F is
F.~N~ where N is the version number.
simple or never
Make simple backups. The -B or --prefix, -Y or --basename-pre-
fix, and -z or --suffix options 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 SIMPLE_BACKUP_SUFFIX envi-
ronment variable if set, and is .orig otherwise.
With numbered or simple backups, if the backup file name is too
long, the backup suffix ~ is used instead; if even appending ~ would
make the name too long, then ~ replaces the last character of the
file name.
--verbose
Output extra information about the work being done.
-x num or --debug=num
Set internal debugging flags of interest only to patch patchers.
-Y pref or --basename-prefix=pref
Use the simple method to determine backup file names (see the -V
method or --version-control method option), and prefix pref to the
basename of a file name when generating its backup file name. For
example, with -Y .del/ the simple backup file name for
src/patch/util.c is src/patch/.del/util.c.
-z suffix or --suffix=suffix
Use the simple method to determine backup file names (see the -V
method or --version-control method option), and use suffix as the
suffix. For example, with -z - the backup file name for
src/patch/util.c is src/patch/util.c-.
-Z or --set-utc
Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use Coordinated Universal Time (UTC, often known as GMT).
Also see the -T or --set-time option.
The -Z or --set-utc and -T or --set-time options normally refrain
from setting a file’s time if the file’s original time does not
match the time given in the patch header, or if its contents do not
match the patch exactly. However, if the -f or --force option is
given, the file time is set regardless.
Due to the limitations of diff output format, these options cannot
update the times of files whose contents have not changed. Also, if
you use these options, you should remove (e.g. with make clean) all
files that depend on the patched files, so that later invocations of
make do not get confused by the patched files’ times.
ENVIRONMENT
PATCH_GET
This specifies whether patch gets missing or read-only files from
RCS, ClearCase, Perforce, or SCCS by default; see the -g or --get
option.
POSIXLY_CORRECT
If set, patch conforms more strictly to the POSIX standard by
default: see the --posix option.
QUOTING_STYLE
Default value of the --quoting-style option.
SIMPLE_BACKUP_SUFFIX
Extension to use for simple backup file names instead of .orig.
TMPDIR, TMP, TEMP
Directory to put temporary files in; patch uses the first environ-
ment variable in this list that is set. If none are set, the
default is system-dependent; it is normally /tmp on Unix hosts.
VERSION_CONTROL or PATCH_VERSION_CONTROL
Selects version control style; see the -v or --version-control
option.
FILES
$TMPDIR/p*
temporary files
/dev/tty
controlling terminal; used to get answers to questions asked of the
user
SEE ALSO
diff(1), ed(1), merge(1).
Marshall T. Rose and Einar A. Stefferud, Proposed Standard for Message
Encapsulation, Internet RFC 934 (1985-01).
NOTES FOR PATCH SENDERS
There are several things you should bear in mind if you are going to be
sending out patches.
Create your patch systematically. A good method is the command
diff -Naur old new where old and new identify the old and new directo-
ries. The names old and new should not contain any slashes. The diff
command’s headers should have dates and times in Universal Time using
traditional Unix format, so that patch recipients can use the -Z or
--set-utc option. Here is an example command, using Bourne shell syn-
tax:
LC_ALL=C TZ=UTC0 diff -Naur gcc-2.7 gcc-2.8
Tell your recipients how to apply the patch by telling them which
directory to cd to, and which patch options to use. The option string
-Np1 is recommended. Test your procedure by pretending to be a recipi-
ent and applying your patch to a copy of the original files.
You can save people a lot of grief by keeping a patchlevel.h file which
is patched to increment the patch level as the first diff in the patch
file you send out. If you put a Prereq: line in with the patch, it
won’t let them apply patches out of order without some warning.
You can create a file by sending out a diff that compares /dev/null or
an empty file dated the Epoch (1970-01-01 00:00:00 UTC) to the file you
want to create. This only works if the file you want to create doesn’t
exist already in the target directory. Conversely, you can remove a
file by sending out a context diff that compares the file to be deleted
with an empty file dated the Epoch. The file will be removed unless
patch is conforming to POSIX and the -E or --remove-empty-files option
is not given. An easy way to generate patches that create and remove
files is to use GNU diff’s -N or --new-file option.
If the recipient is supposed to use the -pN option, do not send output
that looks like this:
diff -Naur v2.0.29/prog/README prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ prog/README Mon Mar 17 14:58:22 1997
because the two file names have different numbers of slashes, and dif-
ferent versions of patch interpret the file names differently. To
avoid confusion, send output that looks like this instead:
diff -Naur v2.0.29/prog/README v2.0.30/prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
Avoid sending patches that compare backup file names like README.orig,
since this might confuse patch into patching a backup file instead of
the real file. Instead, send patches that compare the same base file
names in different directories, e.g. old/README and new/README.
Take care not to send out reversed patches, since it makes people won-
der whether they already applied the patch.
Try not to have your patch modify derived files (e.g. the file config-
ure where there is a line configure: configure.in in your makefile),
since the recipient should be able to regenerate the derived files any-
way. If you must send diffs of derived files, generate the diffs using
UTC, have the recipients apply the patch with the -Z or --set-utc
option, and have them remove any unpatched files that depend on patched
files (e.g. with make clean).
While you may be able to get away with putting 582 diff listings into
one file, it may be wiser to group related patches into separate files
in case something goes haywire.
DIAGNOSTICS
Diagnostics generally indicate that patch couldn’t parse your patch
file.
If the --verbose option is given, the message Hmm... indicates that
there is unprocessed text in the patch file and that patch is attempt-
ing to intuit whether there is a patch in that text and, if so, what
kind of patch it is.
patch’s exit status is 0 if all hunks are applied successfully, 1 if
some hunks cannot be applied or there were merge conflicts, and 2 if
there is more serious trouble. When applying a set of patches in a
loop it behooves you to check this exit status so you don’t apply a
later patch to a partially patched file.
CAVEATS
Context diffs cannot reliably represent the creation or deletion of
empty 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.
patch cannot tell if the line numbers are off in an ed script, and can
detect bad 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 prob-
lem. You should probably do a context diff in these cases to see if
the changes made sense. Of course, compiling without errors is a
pretty good indication that the patch worked, but not always.
patch usually produces the correct results, even when it has to do a
lot of guessing. However, the results are guaranteed to be correct
only when the patch is applied to exactly the same version of the file
that the patch was generated from.
COMPATIBILITY ISSUES
The POSIX standard specifies behavior that differs from patch’s tradi-
tional behavior. You should be aware of these differences if you must
interoperate with patch versions 2.1 and earlier, which do not conform
to POSIX.
· In traditional patch, the -p option’s operand was optional, and a
bare -p was equivalent to -p0. The -p option now requires an
operand, and -p 0 is now equivalent to -p0. For maximum compatibil-
ity, use options like -p0 and -p1.
Also, traditional patch simply counted slashes when stripping path
prefixes; patch now counts pathname components. That is, a sequence
of one or more adjacent slashes now counts as a single slash. For
maximum portability, avoid sending patches containing // in file
names.
· In traditional patch, backups were enabled by default. This behav-
ior is now enabled with the -b or --backup option.
Conversely, in POSIX patch, backups are never made, even when there
is a mismatch. In GNU patch, this behavior is enabled with the
--no-backup-if-mismatch option, or by conforming to POSIX with the
--posix option or by setting the POSIXLY_CORRECT environment vari-
able.
The -b suffix option of traditional patch is equivalent to the
-b -z suffix options of GNU patch.
· Traditional patch used a complicated (and incompletely documented)
method to intuit the name of the file to be patched from the patch
header. This method did not conform to POSIX, and had a few
gotchas. Now patch uses a different, equally complicated (but bet-
ter documented) method that is optionally POSIX-conforming; we hope
it has fewer gotchas. The two methods are compatible if the file
names in the context diff header and the Index: line are all identi-
cal after prefix-stripping. Your patch is normally compatible if
each header’s file names all contain the same number of slashes.
· When traditional patch asked the user a question, it sent the ques-
tion to standard error and looked for an answer from the first file
in the following list that was a terminal: standard error, standard
output, /dev/tty, and standard input. Now patch sends questions to
standard output and gets answers from /dev/tty. Defaults for some
answers have been changed so that patch never goes into an infinite
loop when using default answers.
· Traditional patch exited with a status value that counted the number
of bad hunks, or with status 1 if there was real trouble. Now patch
exits with status 1 if some hunks failed, or with 2 if there was
real trouble.
· Limit yourself to the following options when sending instructions
meant to be executed by anyone running GNU patch, traditional patch,
or a patch that conforms to POSIX. Spaces are significant in the
following list, and operands are required.
-c
-d dir
-D define
-e
-l
-n
-N
-o outfile
-pnum
-R
-r rejectfile
BUGS
Please report bugs via email to .
If code has been duplicated (for instance with #ifdef OLDCODE ... #else
... #endif), patch is incapable of patching both versions, and, if it
works at all, will likely patch the wrong one, and tell you that it
succeeded to boot.
If you apply a patch you’ve already applied, patch thinks it is a
reversed patch, and offers to un-apply the patch. This could be con-
strued as a feature.
Computing how to merge a hunk is significantly harder than using the
standard fuzzy algorithm. Bigger hunks, more context, a bigger offset
from the original location, and a worse match all slow the algorithm
down.
COPYING
Copyright (C) 1984, 1985, 1986, 1988 Larry Wall.
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a per-
mission notice identical to this one.
Permission is granted to copy and distribute translations of this man-
ual into another language, under the above conditions for modified ver-
sions, except that this permission notice may be included in transla-
tions approved by the copyright holders instead of in the original
English.
AUTHORS
Larry Wall wrote the original version of patch. Paul Eggert removed
patch’s arbitrary limits; added support for binary files, setting file
times, and deleting files; and made it conform better to POSIX. Other
contributors include Wayne Davison, who added unidiff support, and
David MacKenzie, who added configuration and backup support. Andreas
Grünbacher added support for merging.
GNU PATCH(1)