Documentation: fix a typo in git-apply.txt
[git/git.git] / Documentation / git-apply.txt
CommitLineData
d0587fd5
JH
1git-apply(1)
2============
d0587fd5
JH
3
4NAME
5----
38a39647 6git-apply - Apply a patch to files and/or to the index
d0587fd5
JH
7
8
9SYNOPSIS
10--------
353ce815 11[verse]
b1889c36 12'git apply' [--stat] [--numstat] [--summary] [--check] [--index]
f26c4940 13 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
0b9a9dd0 14 [--allow-binary-replacement | --binary] [--reject] [-z]
62b4698e 15 [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
86c91f91 16 [--ignore-space-change | --ignore-whitespace ]
0adda936 17 [--whitespace=(nowarn|warn|fix|error|error-all)]
62b4698e 18 [--exclude=<path>] [--include=<path>] [--directory=<root>]
6ecb1ee2 19 [--verbose] [<patch>...]
d0587fd5
JH
20
21DESCRIPTION
22-----------
38a39647
BG
23Reads the supplied diff output (i.e. "a patch") and applies it to files.
24With the `--index` option the patch is also applied to the index, and
964498e7 25with the `--cached` option the patch is only applied to the index.
38a39647
BG
26Without these options, the command applies the patch only to files,
27and does not require them to be in a git repository.
d0587fd5 28
08b29826
BK
29This command applies the patch but does not create a commit. Use
30linkgit:git-am[1] to create commits from patches generated by
31linkgit:git-format-patch[1] and/or received by email.
32
d0587fd5
JH
33OPTIONS
34-------
12dd6e8c 35<patch>...::
1d035f85 36 The files to read the patch from. '-' can be used to read
12dd6e8c 37 from the standard input.
d0587fd5 38
d0587fd5
JH
39--stat::
40 Instead of applying the patch, output diffstat for the
12dd6e8c 41 input. Turns off "apply".
d0587fd5 42
7d8b7c21 43--numstat::
f9821e2b 44 Similar to `--stat`, but shows the number of added and
1d035f85 45 deleted lines in decimal notation and the pathname without
2f89543e
JH
46 abbreviation, to make it more machine friendly. For
47 binary files, outputs two `-` instead of saying
48 `0 0`. Turns off "apply".
7d8b7c21 49
d0587fd5
JH
50--summary::
51 Instead of applying the patch, output a condensed
52 summary of information obtained from git diff extended
53 headers, such as creations, renames and mode changes.
12dd6e8c 54 Turns off "apply".
d0587fd5
JH
55
56--check::
57 Instead of applying the patch, see if the patch is
c34ec655 58 applicable to the current working tree and/or the index
12dd6e8c 59 file and detects errors. Turns off "apply".
d0587fd5
JH
60
61--index::
f9821e2b 62 When `--check` is in effect, or when applying the patch
d0587fd5
JH
63 (which is the default when none of the options that
64 disables it is in effect), make sure the patch is
65 applicable to what the current index file records. If
c34ec655 66 the file to be patched in the working tree is not
d0587fd5
JH
67 up-to-date, it is flagged as an error. This flag also
68 causes the index file to be updated.
69
5684ed6d 70--cached::
1d035f85
DM
71 Apply a patch without touching the working tree. Instead take the
72 cached data, apply the patch, and store the result in the index
f9821e2b 73 without using the working tree. This implies `--index`.
5684ed6d 74
f26c4940 75--build-fake-ancestor=<file>::
0b444cdb 76 Newer 'git diff' output has embedded 'index information'
d88156e9
JH
77 for each blob to help identify the original version that
78 the patch applies to. When this flag is given, and if
1d035f85 79 the original versions of the blobs are available locally,
7a988699
JS
80 builds a temporary index containing those blobs.
81+
82When a pure mode change is encountered (which has no index information),
83the information is read from the current index instead.
d88156e9 84
3240240f
SB
85-R::
86--reverse::
5684ed6d
JF
87 Apply the patch in reverse.
88
89--reject::
0b444cdb 90 For atomicity, 'git apply' by default fails the whole patch and
5684ed6d
JF
91 does not touch the working tree when some of the hunks
92 do not apply. This option makes it apply
b32d37a3 93 the parts of the patch that are applicable, and leave the
8938045a 94 rejected hunks in corresponding *.rej files.
5684ed6d 95
d88156e9 96-z::
64485b4a
BG
97 When `--numstat` has been given, do not munge pathnames,
98 but use a NUL-terminated machine-readable format.
99+
100Without this option, each pathname output will have TAB, LF, double quotes,
101and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`,
102respectively, and the pathname will be enclosed in double quotes if
103any of those replacements occurred.
d88156e9 104
e36f8b60
DB
105-p<n>::
106 Remove <n> leading slashes from traditional diff paths. The
107 default is 1.
108
47495887
EB
109-C<n>::
110 Ensure at least <n> lines of surrounding context match before
111 and after each change. When fewer lines of surrounding
74237d62 112 context exist they all must match. By default no context is
47495887
EB
113 ever ignored.
114
f58bb6fb 115--unidiff-zero::
0b444cdb 116 By default, 'git apply' expects that the patch being
f58bb6fb
JF
117 applied is a unified diff with at least one line of context.
118 This provides good safety measures, but breaks down when
f9821e2b
BG
119 applying a diff generated with `--unified=0`. To bypass these
120 checks use `--unidiff-zero`.
f58bb6fb 121+
1d035f85 122Note, for the reasons stated above usage of context-free patches is
f58bb6fb
JF
123discouraged.
124
12dd6e8c 125--apply::
5684ed6d 126 If you use any of the options marked "Turns off
0b444cdb 127 'apply'" above, 'git apply' reads and outputs the
1d035f85 128 requested information without actually applying the
12dd6e8c
JH
129 patch. Give this flag after those flags to also apply
130 the patch.
131
e433705d
JH
132--no-add::
133 When applying a patch, ignore additions made by the
71a9883d 134 patch. This can be used to extract the common part between
2fd02c92 135 two files by first running 'diff' on them and applying
e433705d 136 the result with this option, which would apply the
1d035f85 137 deletion part but not the addition part.
d0587fd5 138
3240240f
SB
139--allow-binary-replacement::
140--binary::
2b6eef94
JH
141 Historically we did not allow binary patch applied
142 without an explicit permission from the user, and this
143 flag was the way to do so. Currently we always allow binary
144 patch application, so this is a no-op.
27dedf0c 145
5684ed6d
JF
146--exclude=<path-pattern>::
147 Don't apply changes to files matching the given path pattern. This can
148 be useful when importing patchsets, where you want to exclude certain
149 files or directories.
150
6ecb1ee2
JH
151--include=<path-pattern>::
152 Apply changes to files matching the given path pattern. This can
153 be useful when importing patchsets, where you want to include certain
154 files or directories.
155+
f9821e2b 156When `--exclude` and `--include` patterns are used, they are examined in the
6ecb1ee2
JH
157order they appear on the command line, and the first match determines if a
158patch to each path is used. A patch to a path that does not match any
159include/exclude pattern is used by default if there is no include pattern
160on the command line, and ignored if there is any include pattern.
161
86c91f91
GB
162--ignore-space-change::
163--ignore-whitespace::
164 When applying a patch, ignore changes in whitespace in context
165 lines if necessary.
166 Context lines will preserve their whitespace, and they will not
167 undergo whitespace fixing regardless of the value of the
168 `--whitespace` option. New lines will still be fixed, though.
169
91af7ae5
JH
170--whitespace=<action>::
171 When applying a patch, detect a new or modified line that has
172 whitespace errors. What are considered whitespace errors is
173 controlled by `core.whitespace` configuration. By default,
174 trailing whitespaces (including lines that solely consist of
175 whitespaces) and a space character that is immediately followed
176 by a tab character inside the initial indent of the line are
177 considered whitespace errors.
178+
179By default, the command outputs warning messages but applies the patch.
eb006ccf 180When `git-apply` is used for statistics and not applying a
91af7ae5
JH
181patch, it defaults to `nowarn`.
182+
1d035f85 183You can use different `<action>` values to control this
91af7ae5 184behavior:
8273c79a
JH
185+
186* `nowarn` turns off the trailing whitespace warning.
187* `warn` outputs warnings for a few such errors, but applies the
91af7ae5
JH
188 patch as-is (default).
189* `fix` outputs warnings for a few such errors, and applies the
190 patch after fixing them (`strip` is a synonym --- the tool
1d035f85 191 used to consider only trailing whitespace characters as errors, and the
91af7ae5 192 fix involved 'stripping' them, but modern gits do more).
8273c79a
JH
193* `error` outputs warnings for a few such errors, and refuses
194 to apply the patch.
195* `error-all` is similar to `error` but shows all errors.
8273c79a 196
f847c07b 197--inaccurate-eof::
0979c106 198 Under certain circumstances, some versions of 'diff' do not correctly
5684ed6d 199 detect a missing new-line at the end of the file. As a result, patches
0979c106 200 created by such 'diff' programs do not record incomplete lines
5684ed6d
JF
201 correctly. This option adds support for applying such patches by
202 working around this bug.
203
3240240f
SB
204-v::
205--verbose::
5684ed6d
JF
206 Report progress to stderr. By default, only a message about the
207 current patch being applied will be printed. This option will cause
208 additional information to be reported.
8273c79a 209
c14b9d1e
JS
210--recount::
211 Do not trust the line counts in the hunk headers, but infer them
212 by inspecting the patch (e.g. after editing the patch without
213 adjusting the hunk headers appropriately).
214
f5563887 215--directory=<root>::
1d035f85 216 Prepend <root> to all filenames. If a "-p" argument was also passed,
c4730f35 217 it is applied before prepending the new root.
f5563887
JH
218+
219For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
220can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
221running `git apply --directory=modules/git-gui`.
c4730f35 222
8273c79a
JH
223Configuration
224-------------
225
86c91f91
GB
226apply.ignorewhitespace::
227 Set to 'change' if you want changes in whitespace to be ignored by default.
228 Set to one of: no, none, never, false if you want changes in
229 whitespace to be significant.
8273c79a
JH
230apply.whitespace::
231 When no `--whitespace` flag is given from the command
232 line, this configuration item is used as the default.
233
e06c5a6c
SV
234Submodules
235----------
0b444cdb 236If the patch contains any changes to submodules then 'git apply'
e06c5a6c
SV
237treats these changes as follows.
238
f9821e2b 239If `--index` is specified (explicitly or implicitly), then the submodule
e06c5a6c
SV
240commits must match the index exactly for the patch to apply. If any
241of the submodules are checked-out, then these check-outs are completely
242ignored, i.e., they are not required to be up-to-date or clean and they
243are not updated.
244
f9821e2b 245If `--index` is not specified, then the submodule commits in the patch
1d035f85 246are ignored and only the absence or presence of the corresponding
e06c5a6c 247subdirectory is checked and (if possible) updated.
8273c79a 248
08b29826
BK
249
250SEE ALSO
251--------
252linkgit:git-am[1].
253
254
d0587fd5
JH
255Author
256------
257Written by Linus Torvalds <torvalds@osdl.org>
258
259Documentation
260--------------
261Documentation by Junio C Hamano
262
263GIT
264---
9e1f0a85 265Part of the linkgit:git[1] suite