blob: 2dcfc097d39dc3a18c774dbc1eab8ac343abf601 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-apply(1)
2============
3
4NAME
5----
Junio C Hamano5706e0b2009-11-24 10:54:166git-apply - Apply a patch to files and/or to the index
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano235a91e2006-01-07 01:13:5811[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3812'git apply' [--stat] [--numstat] [--summary] [--check] [--index]
Junio C Hamanobd53dbf2009-01-18 18:26:3713 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
Junio C Hamano0e3cb532007-04-17 08:28:1114 [--allow-binary-replacement | --binary] [--reject] [-z]
Junio C Hamanod2179ef2010-10-22 04:12:1715 [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
Junio C Hamanofe24db02009-08-22 05:10:4716 [--ignore-space-change | --ignore-whitespace ]
Junio C Hamanod2179ef2010-10-22 04:12:1717 [--whitespace=(nowarn|warn|fix|error|error-all)]
18 [--exclude=<path>] [--include=<path>] [--directory=<root>]
Junio C Hamanoa476efa2008-10-10 15:31:4219 [--verbose] [<patch>...]
Junio C Hamano1a4e8412005-12-27 08:17:2320
21DESCRIPTION
22-----------
Junio C Hamano5706e0b2009-11-24 10:54:1623Reads 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
Junio C Hamano6b8a0792011-03-04 23:54:3025with the `--cached` option the patch is only applied to the index.
Junio C Hamano5706e0b2009-11-24 10:54:1626Without these options, the command applies the patch only to files,
27and does not require them to be in a git repository.
Junio C Hamano1a4e8412005-12-27 08:17:2328
Junio C Hamanoe85e36f2010-08-10 05:30:1429This 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
Junio C Hamano1a4e8412005-12-27 08:17:2333OPTIONS
34-------
35<patch>...::
Junio C Hamano7924d5e2009-03-03 08:28:4836The files to read the patch from. '-' can be used to read
Junio C Hamano1a4e8412005-12-27 08:17:2337from the standard input.
38
39--stat::
40Instead of applying the patch, output diffstat for the
41input. Turns off "apply".
42
43--numstat::
Junio C Hamano5706e0b2009-11-24 10:54:1644Similar to `--stat`, but shows the number of added and
Junio C Hamano7924d5e2009-03-03 08:28:4845deleted lines in decimal notation and the pathname without
Junio C Hamanod793de52006-12-26 09:11:4346abbreviation, to make it more machine friendly. For
47binary files, outputs two `-` instead of saying
48`0 0`. Turns off "apply".
Junio C Hamano1a4e8412005-12-27 08:17:2349
50--summary::
51Instead of applying the patch, output a condensed
52summary of information obtained from git diff extended
53headers, such as creations, renames and mode changes.
54Turns off "apply".
55
56--check::
57Instead of applying the patch, see if the patch is
Junio C Hamano5706e0b2009-11-24 10:54:1658applicable to the current working tree and/or the index
Junio C Hamano1a4e8412005-12-27 08:17:2359file and detects errors. Turns off "apply".
60
61--index::
Junio C Hamano5706e0b2009-11-24 10:54:1662When `--check` is in effect, or when applying the patch
Junio C Hamano1a4e8412005-12-27 08:17:2363(which is the default when none of the options that
64disables it is in effect), make sure the patch is
65applicable to what the current index file records. If
Junio C Hamano5706e0b2009-11-24 10:54:1666the file to be patched in the working tree is not
Junio C Hamano1a4e8412005-12-27 08:17:2367up-to-date, it is flagged as an error. This flag also
68causes the index file to be updated.
69
Junio C Hamano6b2cee12006-08-26 08:43:3170--cached::
Junio C Hamano7924d5e2009-03-03 08:28:4871Apply a patch without touching the working tree. Instead take the
72cached data, apply the patch, and store the result in the index
Junio C Hamano5706e0b2009-11-24 10:54:1673without using the working tree. This implies `--index`.
Junio C Hamano6b2cee12006-08-26 08:43:3174
Junio C Hamanobd53dbf2009-01-18 18:26:3775--build-fake-ancestor=<file>::
Junio C Hamano1aa40d22010-01-21 17:46:4376Newer 'git diff' output has embedded 'index information'
Junio C Hamano1a4e8412005-12-27 08:17:2377for each blob to help identify the original version that
78the patch applies to. When this flag is given, and if
Junio C Hamano7924d5e2009-03-03 08:28:4879the original versions of the blobs are available locally,
Junio C Hamano01d8f832007-09-24 07:37:3080builds 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.
Junio C Hamano1a4e8412005-12-27 08:17:2384
Junio C Hamanoeb415992008-06-08 22:49:4785-R::
86--reverse::
Junio C Hamano6b2cee12006-08-26 08:43:3187Apply the patch in reverse.
88
89--reject::
Junio C Hamano1aa40d22010-01-21 17:46:4390For atomicity, 'git apply' by default fails the whole patch and
Junio C Hamano6b2cee12006-08-26 08:43:3191does not touch the working tree when some of the hunks
92do not apply. This option makes it apply
Junio C Hamano9adfc6a2006-08-28 07:18:3893the parts of the patch that are applicable, and leave the
94rejected hunks in corresponding *.rej files.
Junio C Hamano6b2cee12006-08-26 08:43:3195
Junio C Hamano1a4e8412005-12-27 08:17:2396-z::
Junio C Hamano5706e0b2009-11-24 10:54:1697When `--numstat` has been given, do not munge pathnames,
98but 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.
Junio C Hamano1a4e8412005-12-27 08:17:23104
Junio C Hamano8af15b02006-02-01 00:59:26105-p<n>::
106Remove <n> leading slashes from traditional diff paths. The
107default is 1.
108
Junio C Hamano54559c82006-04-13 07:45:12109-C<n>::
110Ensure at least <n> lines of surrounding context match before
111and after each change. When fewer lines of surrounding
Junio C Hamano33db4372006-06-07 19:51:45112context exist they all must match. By default no context is
Junio C Hamano54559c82006-04-13 07:45:12113ever ignored.
114
Junio C Hamano3eb513f2006-09-18 02:47:16115--unidiff-zero::
Junio C Hamano1aa40d22010-01-21 17:46:43116By default, 'git apply' expects that the patch being
Junio C Hamano3eb513f2006-09-18 02:47:16117applied is a unified diff with at least one line of context.
118This provides good safety measures, but breaks down when
Junio C Hamano5706e0b2009-11-24 10:54:16119applying a diff generated with `--unified=0`. To bypass these
120checks use `--unidiff-zero`.
Junio C Hamano3eb513f2006-09-18 02:47:16121+
Junio C Hamano7924d5e2009-03-03 08:28:48122Note, for the reasons stated above usage of context-free patches is
Junio C Hamano3eb513f2006-09-18 02:47:16123discouraged.
124
Junio C Hamano1a4e8412005-12-27 08:17:23125--apply::
Junio C Hamano6b2cee12006-08-26 08:43:31126If you use any of the options marked "Turns off
Junio C Hamano1aa40d22010-01-21 17:46:43127'apply'" above, 'git apply' reads and outputs the
Junio C Hamano7924d5e2009-03-03 08:28:48128requested information without actually applying the
Junio C Hamano1a4e8412005-12-27 08:17:23129patch. Give this flag after those flags to also apply
130the patch.
131
132--no-add::
133When applying a patch, ignore additions made by the
Junio C Hamano3a702342007-12-12 21:34:02134patch. This can be used to extract the common part between
Junio C Hamanoba4b9282008-07-06 05:20:31135two files by first running 'diff' on them and applying
Junio C Hamano1a4e8412005-12-27 08:17:23136the result with this option, which would apply the
Junio C Hamano7924d5e2009-03-03 08:28:48137deletion part but not the addition part.
Junio C Hamano1a4e8412005-12-27 08:17:23138
Junio C Hamanoeb415992008-06-08 22:49:47139--allow-binary-replacement::
140--binary::
Junio C Hamanofd73d892006-09-14 07:38:22141Historically we did not allow binary patch applied
142without an explicit permission from the user, and this
143flag was the way to do so. Currently we always allow binary
144patch application, so this is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:23145
Junio C Hamano6b2cee12006-08-26 08:43:31146--exclude=<path-pattern>::
147Don't apply changes to files matching the given path pattern. This can
148be useful when importing patchsets, where you want to exclude certain
149files or directories.
150
Junio C Hamanoa476efa2008-10-10 15:31:42151--include=<path-pattern>::
152Apply changes to files matching the given path pattern. This can
153be useful when importing patchsets, where you want to include certain
154files or directories.
155+
Junio C Hamano5706e0b2009-11-24 10:54:16156When `--exclude` and `--include` patterns are used, they are examined in the
Junio C Hamanoa476efa2008-10-10 15:31:42157order 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
Junio C Hamanofe24db02009-08-22 05:10:47162--ignore-space-change::
163--ignore-whitespace::
164When applying a patch, ignore changes in whitespace in context
165lines if necessary.
166Context lines will preserve their whitespace, and they will not
167undergo whitespace fixing regardless of the value of the
168`--whitespace` option. New lines will still be fixed, though.
169
Junio C Hamano942b35e2007-12-09 10:19:33170--whitespace=<action>::
171When applying a patch, detect a new or modified line that has
172whitespace errors. What are considered whitespace errors is
173controlled by `core.whitespace` configuration. By default,
174trailing whitespaces (including lines that solely consist of
175whitespaces) and a space character that is immediately followed
176by a tab character inside the initial indent of the line are
177considered whitespace errors.
178+
179By default, the command outputs warning messages but applies the patch.
Junio C Hamanof8a79222009-03-01 08:02:50180When `git-apply` is used for statistics and not applying a
Junio C Hamano942b35e2007-12-09 10:19:33181patch, it defaults to `nowarn`.
182+
Junio C Hamano7924d5e2009-03-03 08:28:48183You can use different `<action>` values to control this
Junio C Hamano942b35e2007-12-09 10:19:33184behavior:
Junio C Hamano5f327762006-03-02 09:14:51185+
186* `nowarn` turns off the trailing whitespace warning.
187* `warn` outputs warnings for a few such errors, but applies the
Junio C Hamano942b35e2007-12-09 10:19:33188 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
Junio C Hamano7924d5e2009-03-03 08:28:48191 used to consider only trailing whitespace characters as errors, and the
Junio C Hamano942b35e2007-12-09 10:19:33192 fix involved 'stripping' them, but modern gits do more).
Junio C Hamano5f327762006-03-02 09:14:51193* `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.
Junio C Hamano5f327762006-03-02 09:14:51196
Junio C Hamano3a971022006-11-18 22:17:58197--inaccurate-eof::
Junio C Hamanoba4b9282008-07-06 05:20:31198Under certain circumstances, some versions of 'diff' do not correctly
Junio C Hamano6b2cee12006-08-26 08:43:31199detect a missing new-line at the end of the file. As a result, patches
Junio C Hamanoba4b9282008-07-06 05:20:31200created by such 'diff' programs do not record incomplete lines
Junio C Hamano6b2cee12006-08-26 08:43:31201correctly. This option adds support for applying such patches by
202working around this bug.
203
Junio C Hamanoeb415992008-06-08 22:49:47204-v::
205--verbose::
Junio C Hamano6b2cee12006-08-26 08:43:31206Report progress to stderr. By default, only a message about the
207current patch being applied will be printed. This option will cause
208additional information to be reported.
Junio C Hamano5f327762006-03-02 09:14:51209
Junio C Hamanofce7c7e2008-07-02 03:06:38210--recount::
211Do not trust the line counts in the hunk headers, but infer them
212by inspecting the patch (e.g. after editing the patch without
213adjusting the hunk headers appropriately).
214
Junio C Hamano208beb72008-07-10 02:30:50215--directory=<root>::
Junio C Hamano7924d5e2009-03-03 08:28:48216Prepend <root> to all filenames. If a "-p" argument was also passed,
Junio C Hamano208beb72008-07-10 02:30:50217it is applied before prepending the new root.
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`.
222
Junio C Hamano5f327762006-03-02 09:14:51223Configuration
224-------------
225
Junio C Hamanofe24db02009-08-22 05:10:47226apply.ignorewhitespace::
227Set to 'change' if you want changes in whitespace to be ignored by default.
228Set to one of: no, none, never, false if you want changes in
229whitespace to be significant.
Junio C Hamano5f327762006-03-02 09:14:51230apply.whitespace::
231When no `--whitespace` flag is given from the command
232line, this configuration item is used as the default.
233
Junio C Hamano3b178be2007-08-16 04:59:27234Submodules
235----------
Junio C Hamano1aa40d22010-01-21 17:46:43236If the patch contains any changes to submodules then 'git apply'
Junio C Hamano3b178be2007-08-16 04:59:27237treats these changes as follows.
238
Junio C Hamano5706e0b2009-11-24 10:54:16239If `--index` is specified (explicitly or implicitly), then the submodule
Junio C Hamano3b178be2007-08-16 04:59:27240commits 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
Junio C Hamano5706e0b2009-11-24 10:54:16245If `--index` is not specified, then the submodule commits in the patch
Junio C Hamano7924d5e2009-03-03 08:28:48246are ignored and only the absence or presence of the corresponding
Junio C Hamano3b178be2007-08-16 04:59:27247subdirectory is checked and (if possible) updated.
Junio C Hamano5f327762006-03-02 09:14:51248
Junio C Hamanoe85e36f2010-08-10 05:30:14249
250SEE ALSO
251--------
252linkgit:git-am[1].
253
254
Junio C Hamano1a4e8412005-12-27 08:17:23255Author
256------
257Written by Linus Torvalds <torvalds@osdl.org>
258
259Documentation
260--------------
261Documentation by Junio C Hamano
262
263GIT
264---
Junio C Hamanof7c042d2008-06-06 22:50:53265Part of the linkgit:git[1] suite