blob: 5ee8c91f2d0a376bf755f0802825ae184cea2a28 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-apply(1)
2============
3
4NAME
5----
Junio C Hamano3d141512009-06-01 01:22:406git-apply - Apply a patch on a git index file and/or a working tree
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 Hamanofce7c7e2008-07-02 03:06:3815 [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached]
Junio C Hamanofe24db02009-08-22 05:10:4716 [--ignore-space-change | --ignore-whitespace ]
Junio C Hamano942b35e2007-12-09 10:19:3317 [--whitespace=<nowarn|warn|fix|error|error-all>]
Junio C Hamanoa476efa2008-10-10 15:31:4218 [--exclude=PATH] [--include=PATH] [--directory=<root>]
19 [--verbose] [<patch>...]
Junio C Hamano1a4e8412005-12-27 08:17:2320
21DESCRIPTION
22-----------
Junio C Hamanoba4b9282008-07-06 05:20:3123Reads supplied 'diff' output and applies it on a git index file
Junio C Hamano1a4e8412005-12-27 08:17:2324and a work tree.
25
26OPTIONS
27-------
28<patch>...::
Junio C Hamano7924d5e2009-03-03 08:28:4829The files to read the patch from. '-' can be used to read
Junio C Hamano1a4e8412005-12-27 08:17:2330from the standard input.
31
32--stat::
33Instead of applying the patch, output diffstat for the
34input. Turns off "apply".
35
36--numstat::
Junio C Hamano7924d5e2009-03-03 08:28:4837Similar to \--stat, but shows the number of added and
38deleted lines in decimal notation and the pathname without
Junio C Hamanod793de52006-12-26 09:11:4339abbreviation, to make it more machine friendly. For
40binary files, outputs two `-` instead of saying
41`0 0`. Turns off "apply".
Junio C Hamano1a4e8412005-12-27 08:17:2342
43--summary::
44Instead of applying the patch, output a condensed
45summary of information obtained from git diff extended
46headers, such as creations, renames and mode changes.
47Turns off "apply".
48
49--check::
50Instead of applying the patch, see if the patch is
51applicable to the current work tree and/or the index
52file and detects errors. Turns off "apply".
53
54--index::
55When --check is in effect, or when applying the patch
56(which is the default when none of the options that
57disables it is in effect), make sure the patch is
58applicable to what the current index file records. If
59the file to be patched in the work tree is not
60up-to-date, it is flagged as an error. This flag also
61causes the index file to be updated.
62
Junio C Hamano6b2cee12006-08-26 08:43:3163--cached::
Junio C Hamano7924d5e2009-03-03 08:28:4864Apply a patch without touching the working tree. Instead take the
65cached data, apply the patch, and store the result in the index
Junio C Hamano6b2cee12006-08-26 08:43:3166without using the working tree. This implies '--index'.
67
Junio C Hamanobd53dbf2009-01-18 18:26:3768--build-fake-ancestor=<file>::
Junio C Hamanoba4b9282008-07-06 05:20:3169Newer 'git-diff' output has embedded 'index information'
Junio C Hamano1a4e8412005-12-27 08:17:2370for each blob to help identify the original version that
71the patch applies to. When this flag is given, and if
Junio C Hamano7924d5e2009-03-03 08:28:4872the original versions of the blobs are available locally,
Junio C Hamano01d8f832007-09-24 07:37:3073builds a temporary index containing those blobs.
74+
75When a pure mode change is encountered (which has no index information),
76the information is read from the current index instead.
Junio C Hamano1a4e8412005-12-27 08:17:2377
Junio C Hamanoeb415992008-06-08 22:49:4778-R::
79--reverse::
Junio C Hamano6b2cee12006-08-26 08:43:3180Apply the patch in reverse.
81
82--reject::
Junio C Hamanoba4b9282008-07-06 05:20:3183For atomicity, 'git-apply' by default fails the whole patch and
Junio C Hamano6b2cee12006-08-26 08:43:3184does not touch the working tree when some of the hunks
85do not apply. This option makes it apply
Junio C Hamano9adfc6a2006-08-28 07:18:3886the parts of the patch that are applicable, and leave the
87rejected hunks in corresponding *.rej files.
Junio C Hamano6b2cee12006-08-26 08:43:3188
Junio C Hamano1a4e8412005-12-27 08:17:2389-z::
90When showing the index information, do not munge paths,
91but use NUL terminated machine readable format. Without
92this flag, the pathnames output will have TAB, LF, and
93backslash characters replaced with `\t`, `\n`, and `\\`,
94respectively.
95
Junio C Hamano8af15b02006-02-01 00:59:2696-p<n>::
97Remove <n> leading slashes from traditional diff paths. The
98default is 1.
99
Junio C Hamano54559c82006-04-13 07:45:12100-C<n>::
101Ensure at least <n> lines of surrounding context match before
102and after each change. When fewer lines of surrounding
Junio C Hamano33db4372006-06-07 19:51:45103context exist they all must match. By default no context is
Junio C Hamano54559c82006-04-13 07:45:12104ever ignored.
105
Junio C Hamano3eb513f2006-09-18 02:47:16106--unidiff-zero::
Junio C Hamanoba4b9282008-07-06 05:20:31107By default, 'git-apply' expects that the patch being
Junio C Hamano3eb513f2006-09-18 02:47:16108applied is a unified diff with at least one line of context.
109This provides good safety measures, but breaks down when
110applying a diff generated with --unified=0. To bypass these
111checks use '--unidiff-zero'.
112+
Junio C Hamano7924d5e2009-03-03 08:28:48113Note, for the reasons stated above usage of context-free patches is
Junio C Hamano3eb513f2006-09-18 02:47:16114discouraged.
115
Junio C Hamano1a4e8412005-12-27 08:17:23116--apply::
Junio C Hamano6b2cee12006-08-26 08:43:31117If you use any of the options marked "Turns off
Junio C Hamanoba4b9282008-07-06 05:20:31118'apply'" above, 'git-apply' reads and outputs the
Junio C Hamano7924d5e2009-03-03 08:28:48119requested information without actually applying the
Junio C Hamano1a4e8412005-12-27 08:17:23120patch. Give this flag after those flags to also apply
121the patch.
122
123--no-add::
124When applying a patch, ignore additions made by the
Junio C Hamano3a702342007-12-12 21:34:02125patch. This can be used to extract the common part between
Junio C Hamanoba4b9282008-07-06 05:20:31126two files by first running 'diff' on them and applying
Junio C Hamano1a4e8412005-12-27 08:17:23127the result with this option, which would apply the
Junio C Hamano7924d5e2009-03-03 08:28:48128deletion part but not the addition part.
Junio C Hamano1a4e8412005-12-27 08:17:23129
Junio C Hamanoeb415992008-06-08 22:49:47130--allow-binary-replacement::
131--binary::
Junio C Hamanofd73d892006-09-14 07:38:22132Historically we did not allow binary patch applied
133without an explicit permission from the user, and this
134flag was the way to do so. Currently we always allow binary
135patch application, so this is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:23136
Junio C Hamano6b2cee12006-08-26 08:43:31137--exclude=<path-pattern>::
138Don't apply changes to files matching the given path pattern. This can
139be useful when importing patchsets, where you want to exclude certain
140files or directories.
141
Junio C Hamanoa476efa2008-10-10 15:31:42142--include=<path-pattern>::
143Apply changes to files matching the given path pattern. This can
144be useful when importing patchsets, where you want to include certain
145files or directories.
146+
147When --exclude and --include patterns are used, they are examined in the
148order they appear on the command line, and the first match determines if a
149patch to each path is used. A patch to a path that does not match any
150include/exclude pattern is used by default if there is no include pattern
151on the command line, and ignored if there is any include pattern.
152
Junio C Hamanofe24db02009-08-22 05:10:47153--ignore-space-change::
154--ignore-whitespace::
155When applying a patch, ignore changes in whitespace in context
156lines if necessary.
157Context lines will preserve their whitespace, and they will not
158undergo whitespace fixing regardless of the value of the
159`--whitespace` option. New lines will still be fixed, though.
160
Junio C Hamano942b35e2007-12-09 10:19:33161--whitespace=<action>::
162When applying a patch, detect a new or modified line that has
163whitespace errors. What are considered whitespace errors is
164controlled by `core.whitespace` configuration. By default,
165trailing whitespaces (including lines that solely consist of
166whitespaces) and a space character that is immediately followed
167by a tab character inside the initial indent of the line are
168considered whitespace errors.
169+
170By default, the command outputs warning messages but applies the patch.
Junio C Hamanof8a79222009-03-01 08:02:50171When `git-apply` is used for statistics and not applying a
Junio C Hamano942b35e2007-12-09 10:19:33172patch, it defaults to `nowarn`.
173+
Junio C Hamano7924d5e2009-03-03 08:28:48174You can use different `<action>` values to control this
Junio C Hamano942b35e2007-12-09 10:19:33175behavior:
Junio C Hamano5f327762006-03-02 09:14:51176+
177* `nowarn` turns off the trailing whitespace warning.
178* `warn` outputs warnings for a few such errors, but applies the
Junio C Hamano942b35e2007-12-09 10:19:33179 patch as-is (default).
180* `fix` outputs warnings for a few such errors, and applies the
181 patch after fixing them (`strip` is a synonym --- the tool
Junio C Hamano7924d5e2009-03-03 08:28:48182 used to consider only trailing whitespace characters as errors, and the
Junio C Hamano942b35e2007-12-09 10:19:33183 fix involved 'stripping' them, but modern gits do more).
Junio C Hamano5f327762006-03-02 09:14:51184* `error` outputs warnings for a few such errors, and refuses
185 to apply the patch.
186* `error-all` is similar to `error` but shows all errors.
Junio C Hamano5f327762006-03-02 09:14:51187
Junio C Hamano3a971022006-11-18 22:17:58188--inaccurate-eof::
Junio C Hamanoba4b9282008-07-06 05:20:31189Under certain circumstances, some versions of 'diff' do not correctly
Junio C Hamano6b2cee12006-08-26 08:43:31190detect a missing new-line at the end of the file. As a result, patches
Junio C Hamanoba4b9282008-07-06 05:20:31191created by such 'diff' programs do not record incomplete lines
Junio C Hamano6b2cee12006-08-26 08:43:31192correctly. This option adds support for applying such patches by
193working around this bug.
194
Junio C Hamanoeb415992008-06-08 22:49:47195-v::
196--verbose::
Junio C Hamano6b2cee12006-08-26 08:43:31197Report progress to stderr. By default, only a message about the
198current patch being applied will be printed. This option will cause
199additional information to be reported.
Junio C Hamano5f327762006-03-02 09:14:51200
Junio C Hamanofce7c7e2008-07-02 03:06:38201--recount::
202Do not trust the line counts in the hunk headers, but infer them
203by inspecting the patch (e.g. after editing the patch without
204adjusting the hunk headers appropriately).
205
Junio C Hamano208beb72008-07-10 02:30:50206--directory=<root>::
Junio C Hamano7924d5e2009-03-03 08:28:48207Prepend <root> to all filenames. If a "-p" argument was also passed,
Junio C Hamano208beb72008-07-10 02:30:50208it is applied before prepending the new root.
209+
210For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
211can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
212running `git apply --directory=modules/git-gui`.
213
Junio C Hamano5f327762006-03-02 09:14:51214Configuration
215-------------
216
Junio C Hamanofe24db02009-08-22 05:10:47217apply.ignorewhitespace::
218Set to 'change' if you want changes in whitespace to be ignored by default.
219Set to one of: no, none, never, false if you want changes in
220whitespace to be significant.
Junio C Hamano5f327762006-03-02 09:14:51221apply.whitespace::
222When no `--whitespace` flag is given from the command
223line, this configuration item is used as the default.
224
Junio C Hamano3b178be2007-08-16 04:59:27225Submodules
226----------
Junio C Hamanoba4b9282008-07-06 05:20:31227If the patch contains any changes to submodules then 'git-apply'
Junio C Hamano3b178be2007-08-16 04:59:27228treats these changes as follows.
229
230If --index is specified (explicitly or implicitly), then the submodule
231commits must match the index exactly for the patch to apply. If any
232of the submodules are checked-out, then these check-outs are completely
233ignored, i.e., they are not required to be up-to-date or clean and they
234are not updated.
235
236If --index is not specified, then the submodule commits in the patch
Junio C Hamano7924d5e2009-03-03 08:28:48237are ignored and only the absence or presence of the corresponding
Junio C Hamano3b178be2007-08-16 04:59:27238subdirectory is checked and (if possible) updated.
Junio C Hamano5f327762006-03-02 09:14:51239
Junio C Hamano1a4e8412005-12-27 08:17:23240Author
241------
242Written by Linus Torvalds <torvalds@osdl.org>
243
244Documentation
245--------------
246Documentation by Junio C Hamano
247
248GIT
249---
Junio C Hamanof7c042d2008-06-06 22:50:53250Part of the linkgit:git[1] suite