1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
NAME
patch - Apply patches to files
SYNOPSIS
patch [-c | -e | -n | -u] [-d dir] [-D define] [-o outfile] [-p num]
[-r rejectfile] [-bflNRU] (-i patchfile | < patchfile) [file]
DESCRIPTION
patch applies patches to files from difference listings produced by
diff(1).
patch will skip any garbage unless the patchfile consists entirely of
garbage. Garbage is any data that does not conform to the supported
difference listing formats. patch supports all difference listing
formats specified in diff(1p) except for the -f flag in diff(1p).
patch shall figure out which files to patch from the mentions of
filenames in the patch, unless the files are specified explicitly.
As an extension to the standard, this implementation of patch can
determine the filename by looking at the diff-lines that are produced
by diff(1) when comparing directories. However, if the file is
specified, all patches in the patchfile shall be applied to that file.
OPTIONS
-b
Back up files before the first time that a patch is applied to
them. The backups will have the suffix .orig.
-c
Treat anything that is not conforming to the copied context
format as garbage.
-d dir
Prepend dir to all filenames that appear in the patchfile.
-D define
Mark added lines with the C preprocessor construct
#ifdef define
...
#endif
Mark removed lines with the C preprocessor construct
#ifndef define
...
#endif
Mark changed lines with the C preprocessor construct
#ifdef define
...
#else
...
#endif
As an extension to the standard, define can be 1 or 0 to use
#if 1
#if 0
(swap those lines if define is 0) instead of
#ifdef define
#ifndef define
As another extension to the standard, if define begins with an
exclamation point (!),
#ifdef define
#if 1
and
#ifndef define
#if 0
are swapped.
patch does not guarantee that a patched C source code file will
be at least as syntactically correct after patching as it was
before, despite this being implied by the standard. The
syntactic correctness can be broken when edits are made on lines
split using line continuation, made in comments, or spanning CPP
conditional directives.
-e
Treat anything that is not conforming to the ed-script format as
garbage.
-f
Don't ask any questions.
-i patchfile
Read the patchfile instead of standard output.
-l
Any sequence of whitespace of at least length 1 in the input
file shall match any sequence of whitespace of at least length
1 in the difference script when testing if lines match.
Additionally, any whitespace at the beginning of a line or at
the end of a line is ignored when matching lines. The former
case is an extension of the standard.
-n
Treat anything that is not conforming to the normal format as
garbage.
-N
Ignore already applied hunks. POSIX specifies that already
applied patches shall be ignored if this flag is used. A hunk
is a contiguous portion of a patch. A patch is a single
file-comparison output from diff(1).
-o outfile
Store resulting files from patches to outfile instead of to
the patched file itself. If the patchfile patches multiple
files, the results are concatenated. If a patchfile patches a
file multiple times, intermediary results are also stored.
As an extension to the standard, you may use non-regular files
such as /dev/stdout and /dev/null. /dev/null can be used
to perform a dryrun.
-p num
Remove the first num components from filenames that appear in
the patchfile. Any leading / is regarded as the first component.
If num is 0, the entire filename is used. Without this flag only
basename is used.
-r rejectfile
Save rejected hunks to rejectfile rather than to the
filename.rej where filename is the filename of the file that is
being patched. Rejected hunks are hunks that cannot be applied.
Unless -U is used, rejected hunks are stored in copied context
format. However, the timestamps will be omitted.
-R
Try to apply patches reversed before trying to apply them in
normal direction.
-u
Treat anything that is not conforming to the unified context
format as garbage.
-U
Store rejected hunks in unified context rather than copied
context. Copied context is the default even for unified context
patches.
NOTES
Files that become empty as a result of a patch are not removed.
Symbolic links are treated as regular files, provided that they link to
regular files.
Timestamps that appear in diff headers are not applied.
Encapsulated patches, and patches with CRLF line breaks — or any other
string — rather than LF line breaks are not supported.
In this implementation, when the user is prompted, the message is
printed to /dev/tty, rather than /dev/stdout despite POSIX's
mandate. This is to make it possible to use /dev/stdout as the output
file.
Unportable characters in filenames are supported by parsing them as C
string literals.
In this implementation, the -D flag can be used with ed-scripts.
SEE ALSO
diff(1), ed(1)
STANDARDS
The patch utility is compliant with the specification except for the
exceptions noted above.
The [-fU] flags are extensions to that specification, other extensions
are noted above.
|