blob: d9ed6a1a4ea6dc0068144eac4c5e0f5ef33a04cb [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 Hamano02482692012-07-16 05:28:3912'git apply' [--stat] [--numstat] [--summary] [--check] [--index] [--3way]
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 Hamano22b75492015-03-03 23:14:2519 [--verbose] [--unsafe-paths] [<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,
Junio C Hamano076ffcc2013-02-06 05:13:2127and 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 Hamano02482692012-07-16 05:28:3975-3::
76--3way::
77When the patch does not apply cleanly, fall back on 3-way merge if
78the patch records the identity of blobs it is supposed to apply to,
79and we have those blobs available locally, possibly leaving the
80conflict markers in the files in the working tree for the user to
81resolve. This option implies the `--index` option, and is incompatible
82with the `--reject` and the `--cached` options.
83
Junio C Hamanobd53dbf2009-01-18 18:26:3784--build-fake-ancestor=<file>::
Junio C Hamano1aa40d22010-01-21 17:46:4385Newer 'git diff' output has embedded 'index information'
Junio C Hamano1a4e8412005-12-27 08:17:2386for each blob to help identify the original version that
87the patch applies to. When this flag is given, and if
Junio C Hamano7924d5e2009-03-03 08:28:4888the original versions of the blobs are available locally,
Junio C Hamano01d8f832007-09-24 07:37:3089builds a temporary index containing those blobs.
90+
91When a pure mode change is encountered (which has no index information),
92the information is read from the current index instead.
Junio C Hamano1a4e8412005-12-27 08:17:2393
Junio C Hamanoeb415992008-06-08 22:49:4794-R::
95--reverse::
Junio C Hamano6b2cee12006-08-26 08:43:3196Apply the patch in reverse.
97
98--reject::
Junio C Hamano1aa40d22010-01-21 17:46:4399For atomicity, 'git apply' by default fails the whole patch and
Junio C Hamano6b2cee12006-08-26 08:43:31100does not touch the working tree when some of the hunks
101do not apply. This option makes it apply
Junio C Hamano9adfc6a2006-08-28 07:18:38102the parts of the patch that are applicable, and leave the
103rejected hunks in corresponding *.rej files.
Junio C Hamano6b2cee12006-08-26 08:43:31104
Junio C Hamano1a4e8412005-12-27 08:17:23105-z::
Junio C Hamano5706e0b2009-11-24 10:54:16106When `--numstat` has been given, do not munge pathnames,
107but use a NUL-terminated machine-readable format.
108+
109Without this option, each pathname output will have TAB, LF, double quotes,
110and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`,
111respectively, and the pathname will be enclosed in double quotes if
112any of those replacements occurred.
Junio C Hamano1a4e8412005-12-27 08:17:23113
Junio C Hamano8af15b02006-02-01 00:59:26114-p<n>::
115Remove <n> leading slashes from traditional diff paths. The
116default is 1.
117
Junio C Hamano54559c82006-04-13 07:45:12118-C<n>::
119Ensure at least <n> lines of surrounding context match before
120and after each change. When fewer lines of surrounding
Junio C Hamano33db4372006-06-07 19:51:45121context exist they all must match. By default no context is
Junio C Hamano54559c82006-04-13 07:45:12122ever ignored.
123
Junio C Hamano3eb513f2006-09-18 02:47:16124--unidiff-zero::
Junio C Hamano1aa40d22010-01-21 17:46:43125By default, 'git apply' expects that the patch being
Junio C Hamano3eb513f2006-09-18 02:47:16126applied is a unified diff with at least one line of context.
127This provides good safety measures, but breaks down when
Junio C Hamano5706e0b2009-11-24 10:54:16128applying a diff generated with `--unified=0`. To bypass these
129checks use `--unidiff-zero`.
Junio C Hamano3eb513f2006-09-18 02:47:16130+
Junio C Hamano7924d5e2009-03-03 08:28:48131Note, for the reasons stated above usage of context-free patches is
Junio C Hamano3eb513f2006-09-18 02:47:16132discouraged.
133
Junio C Hamano1a4e8412005-12-27 08:17:23134--apply::
Junio C Hamano6b2cee12006-08-26 08:43:31135If you use any of the options marked "Turns off
Junio C Hamano1aa40d22010-01-21 17:46:43136'apply'" above, 'git apply' reads and outputs the
Junio C Hamano7924d5e2009-03-03 08:28:48137requested information without actually applying the
Junio C Hamano1a4e8412005-12-27 08:17:23138patch. Give this flag after those flags to also apply
139the patch.
140
141--no-add::
142When applying a patch, ignore additions made by the
Junio C Hamano3a702342007-12-12 21:34:02143patch. This can be used to extract the common part between
Junio C Hamanoba4b9282008-07-06 05:20:31144two files by first running 'diff' on them and applying
Junio C Hamano1a4e8412005-12-27 08:17:23145the result with this option, which would apply the
Junio C Hamano7924d5e2009-03-03 08:28:48146deletion part but not the addition part.
Junio C Hamano1a4e8412005-12-27 08:17:23147
Junio C Hamanoeb415992008-06-08 22:49:47148--allow-binary-replacement::
149--binary::
Junio C Hamanofd73d892006-09-14 07:38:22150Historically we did not allow binary patch applied
151without an explicit permission from the user, and this
152flag was the way to do so. Currently we always allow binary
153patch application, so this is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:23154
Junio C Hamano6b2cee12006-08-26 08:43:31155--exclude=<path-pattern>::
156Don't apply changes to files matching the given path pattern. This can
157be useful when importing patchsets, where you want to exclude certain
158files or directories.
159
Junio C Hamanoa476efa2008-10-10 15:31:42160--include=<path-pattern>::
161Apply changes to files matching the given path pattern. This can
162be useful when importing patchsets, where you want to include certain
163files or directories.
164+
Junio C Hamano5706e0b2009-11-24 10:54:16165When `--exclude` and `--include` patterns are used, they are examined in the
Junio C Hamanoa476efa2008-10-10 15:31:42166order they appear on the command line, and the first match determines if a
167patch to each path is used. A patch to a path that does not match any
168include/exclude pattern is used by default if there is no include pattern
169on the command line, and ignored if there is any include pattern.
170
Junio C Hamanofe24db02009-08-22 05:10:47171--ignore-space-change::
172--ignore-whitespace::
173When applying a patch, ignore changes in whitespace in context
174lines if necessary.
175Context lines will preserve their whitespace, and they will not
176undergo whitespace fixing regardless of the value of the
177`--whitespace` option. New lines will still be fixed, though.
178
Junio C Hamano942b35e2007-12-09 10:19:33179--whitespace=<action>::
180When applying a patch, detect a new or modified line that has
181whitespace errors. What are considered whitespace errors is
182controlled by `core.whitespace` configuration. By default,
183trailing whitespaces (including lines that solely consist of
184whitespaces) and a space character that is immediately followed
185by a tab character inside the initial indent of the line are
186considered whitespace errors.
187+
188By default, the command outputs warning messages but applies the patch.
Junio C Hamanof8a79222009-03-01 08:02:50189When `git-apply` is used for statistics and not applying a
Junio C Hamano942b35e2007-12-09 10:19:33190patch, it defaults to `nowarn`.
191+
Junio C Hamano7924d5e2009-03-03 08:28:48192You can use different `<action>` values to control this
Junio C Hamano942b35e2007-12-09 10:19:33193behavior:
Junio C Hamano5f327762006-03-02 09:14:51194+
195* `nowarn` turns off the trailing whitespace warning.
196* `warn` outputs warnings for a few such errors, but applies the
Junio C Hamano942b35e2007-12-09 10:19:33197 patch as-is (default).
198* `fix` outputs warnings for a few such errors, and applies the
199 patch after fixing them (`strip` is a synonym --- the tool
Junio C Hamano7924d5e2009-03-03 08:28:48200 used to consider only trailing whitespace characters as errors, and the
Junio C Hamano076ffcc2013-02-06 05:13:21201 fix involved 'stripping' them, but modern Gits do more).
Junio C Hamano5f327762006-03-02 09:14:51202* `error` outputs warnings for a few such errors, and refuses
203 to apply the patch.
204* `error-all` is similar to `error` but shows all errors.
Junio C Hamano5f327762006-03-02 09:14:51205
Junio C Hamano3a971022006-11-18 22:17:58206--inaccurate-eof::
Junio C Hamanoba4b9282008-07-06 05:20:31207Under certain circumstances, some versions of 'diff' do not correctly
Junio C Hamano6b2cee12006-08-26 08:43:31208detect a missing new-line at the end of the file. As a result, patches
Junio C Hamanoba4b9282008-07-06 05:20:31209created by such 'diff' programs do not record incomplete lines
Junio C Hamano6b2cee12006-08-26 08:43:31210correctly. This option adds support for applying such patches by
211working around this bug.
212
Junio C Hamanoeb415992008-06-08 22:49:47213-v::
214--verbose::
Junio C Hamano6b2cee12006-08-26 08:43:31215Report progress to stderr. By default, only a message about the
216current patch being applied will be printed. This option will cause
217additional information to be reported.
Junio C Hamano5f327762006-03-02 09:14:51218
Junio C Hamanofce7c7e2008-07-02 03:06:38219--recount::
220Do not trust the line counts in the hunk headers, but infer them
221by inspecting the patch (e.g. after editing the patch without
222adjusting the hunk headers appropriately).
223
Junio C Hamano208beb72008-07-10 02:30:50224--directory=<root>::
Junio C Hamano7924d5e2009-03-03 08:28:48225Prepend <root> to all filenames. If a "-p" argument was also passed,
Junio C Hamano208beb72008-07-10 02:30:50226it is applied before prepending the new root.
227+
228For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
229can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
230running `git apply --directory=modules/git-gui`.
231
Junio C Hamano22b75492015-03-03 23:14:25232--unsafe-paths::
233By default, a patch that affects outside the working area
234(either a Git controlled working tree, or the current working
235directory when "git apply" is used as a replacement of GNU
236patch) is rejected as a mistake (or a mischief).
237+
238When `git apply` is used as a "better GNU patch", the user can pass
239the `--unsafe-paths` option to override this safety check. This option
240has no effect when `--index` or `--cached` is in use.
241
Junio C Hamano5f327762006-03-02 09:14:51242Configuration
243-------------
244
Junio C Hamano322c6242015-03-23 21:32:46245apply.ignoreWhitespace::
Junio C Hamanofe24db02009-08-22 05:10:47246Set to 'change' if you want changes in whitespace to be ignored by default.
247Set to one of: no, none, never, false if you want changes in
248whitespace to be significant.
Junio C Hamano5f327762006-03-02 09:14:51249apply.whitespace::
250When no `--whitespace` flag is given from the command
251line, this configuration item is used as the default.
252
Junio C Hamano3b178be2007-08-16 04:59:27253Submodules
254----------
Junio C Hamano1aa40d22010-01-21 17:46:43255If the patch contains any changes to submodules then 'git apply'
Junio C Hamano3b178be2007-08-16 04:59:27256treats these changes as follows.
257
Junio C Hamano5706e0b2009-11-24 10:54:16258If `--index` is specified (explicitly or implicitly), then the submodule
Junio C Hamano3b178be2007-08-16 04:59:27259commits must match the index exactly for the patch to apply. If any
260of the submodules are checked-out, then these check-outs are completely
261ignored, i.e., they are not required to be up-to-date or clean and they
262are not updated.
263
Junio C Hamano5706e0b2009-11-24 10:54:16264If `--index` is not specified, then the submodule commits in the patch
Junio C Hamano7924d5e2009-03-03 08:28:48265are ignored and only the absence or presence of the corresponding
Junio C Hamano3b178be2007-08-16 04:59:27266subdirectory is checked and (if possible) updated.
Junio C Hamano5f327762006-03-02 09:14:51267
Junio C Hamanoe85e36f2010-08-10 05:30:14268SEE ALSO
269--------
270linkgit:git-am[1].
271
Junio C Hamano1a4e8412005-12-27 08:17:23272GIT
273---
Junio C Hamanof7c042d2008-06-06 22:50:53274Part of the linkgit:git[1] suite