blob: 70d19f63eb562063dd373a4474f6efc0e2ea32dc [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-apply(1)
2============
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-apply - Apply a patch on a git index file and 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 Hamano01d8f832007-09-24 07:37:3013 [--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 Hamano942b35e2007-12-09 10:19:3316 [--whitespace=<nowarn|warn|fix|error|error-all>]
Junio C Hamano0e3cb532007-04-17 08:28:1117 [--exclude=PATH] [--verbose] [<patch>...]
Junio C Hamano1a4e8412005-12-27 08:17:2318
19DESCRIPTION
20-----------
21Reads supplied diff output and applies it on a git index file
22and a work tree.
23
24OPTIONS
25-------
26<patch>...::
27The files to read patch from. '-' can be used to read
28from the standard input.
29
30--stat::
31Instead of applying the patch, output diffstat for the
32input. Turns off "apply".
33
34--numstat::
35Similar to \--stat, but shows number of added and
36deleted lines in decimal notation and pathname without
Junio C Hamanod793de52006-12-26 09:11:4337abbreviation, to make it more machine friendly. For
38binary files, outputs two `-` instead of saying
39`0 0`. Turns off "apply".
Junio C Hamano1a4e8412005-12-27 08:17:2340
41--summary::
42Instead of applying the patch, output a condensed
43summary of information obtained from git diff extended
44headers, such as creations, renames and mode changes.
45Turns off "apply".
46
47--check::
48Instead of applying the patch, see if the patch is
49applicable to the current work tree and/or the index
50file and detects errors. Turns off "apply".
51
52--index::
53When --check is in effect, or when applying the patch
54(which is the default when none of the options that
55disables it is in effect), make sure the patch is
56applicable to what the current index file records. If
57the file to be patched in the work tree is not
58up-to-date, it is flagged as an error. This flag also
59causes the index file to be updated.
60
Junio C Hamano6b2cee12006-08-26 08:43:3161--cached::
62Apply a patch without touching the working tree. Instead, take the
63cached data, apply the patch, and store the result in the index,
64without using the working tree. This implies '--index'.
65
Junio C Hamano01d8f832007-09-24 07:37:3066--build-fake-ancestor <file>::
Junio C Hamanofce7c7e2008-07-02 03:06:3867Newer `git-diff` output has embedded 'index information'
Junio C Hamano1a4e8412005-12-27 08:17:2368for each blob to help identify the original version that
69the patch applies to. When this flag is given, and if
Junio C Hamano01d8f832007-09-24 07:37:3070the original versions of the blobs is available locally,
71builds a temporary index containing those blobs.
72+
73When a pure mode change is encountered (which has no index information),
74the information is read from the current index instead.
Junio C Hamano1a4e8412005-12-27 08:17:2375
Junio C Hamanoeb415992008-06-08 22:49:4776-R::
77--reverse::
Junio C Hamano6b2cee12006-08-26 08:43:3178Apply the patch in reverse.
79
80--reject::
Junio C Hamanofce7c7e2008-07-02 03:06:3881For atomicity, `git-apply` by default fails the whole patch and
Junio C Hamano6b2cee12006-08-26 08:43:3182does not touch the working tree when some of the hunks
83do not apply. This option makes it apply
Junio C Hamano9adfc6a2006-08-28 07:18:3884the parts of the patch that are applicable, and leave the
85rejected hunks in corresponding *.rej files.
Junio C Hamano6b2cee12006-08-26 08:43:3186
Junio C Hamano1a4e8412005-12-27 08:17:2387-z::
88When showing the index information, do not munge paths,
89but use NUL terminated machine readable format. Without
90this flag, the pathnames output will have TAB, LF, and
91backslash characters replaced with `\t`, `\n`, and `\\`,
92respectively.
93
Junio C Hamano8af15b02006-02-01 00:59:2694-p<n>::
95Remove <n> leading slashes from traditional diff paths. The
96default is 1.
97
Junio C Hamano54559c82006-04-13 07:45:1298-C<n>::
99Ensure at least <n> lines of surrounding context match before
100and after each change. When fewer lines of surrounding
Junio C Hamano33db4372006-06-07 19:51:45101context exist they all must match. By default no context is
Junio C Hamano54559c82006-04-13 07:45:12102ever ignored.
103
Junio C Hamano3eb513f2006-09-18 02:47:16104--unidiff-zero::
Junio C Hamanofce7c7e2008-07-02 03:06:38105By default, `git-apply` expects that the patch being
Junio C Hamano3eb513f2006-09-18 02:47:16106applied is a unified diff with at least one line of context.
107This provides good safety measures, but breaks down when
108applying a diff generated with --unified=0. To bypass these
109checks use '--unidiff-zero'.
110+
111Note, for the reasons stated above usage of context-free patches are
112discouraged.
113
Junio C Hamano1a4e8412005-12-27 08:17:23114--apply::
Junio C Hamano6b2cee12006-08-26 08:43:31115If you use any of the options marked "Turns off
Junio C Hamanofce7c7e2008-07-02 03:06:38116'apply'" above, `git-apply` reads and outputs the
Junio C Hamano1a4e8412005-12-27 08:17:23117information you asked without actually applying the
118patch. Give this flag after those flags to also apply
119the patch.
120
121--no-add::
122When applying a patch, ignore additions made by the
Junio C Hamano3a702342007-12-12 21:34:02123patch. This can be used to extract the common part between
Junio C Hamano1a4e8412005-12-27 08:17:23124two files by first running `diff` on them and applying
125the result with this option, which would apply the
126deletion part but not addition part.
127
Junio C Hamanoeb415992008-06-08 22:49:47128--allow-binary-replacement::
129--binary::
Junio C Hamanofd73d892006-09-14 07:38:22130Historically we did not allow binary patch applied
131without an explicit permission from the user, and this
132flag was the way to do so. Currently we always allow binary
133patch application, so this is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:23134
Junio C Hamano6b2cee12006-08-26 08:43:31135--exclude=<path-pattern>::
136Don't apply changes to files matching the given path pattern. This can
137be useful when importing patchsets, where you want to exclude certain
138files or directories.
139
Junio C Hamano942b35e2007-12-09 10:19:33140--whitespace=<action>::
141When applying a patch, detect a new or modified line that has
142whitespace errors. What are considered whitespace errors is
143controlled by `core.whitespace` configuration. By default,
144trailing whitespaces (including lines that solely consist of
145whitespaces) and a space character that is immediately followed
146by a tab character inside the initial indent of the line are
147considered whitespace errors.
148+
149By default, the command outputs warning messages but applies the patch.
Junio C Hamanofce7c7e2008-07-02 03:06:38150When `git-apply is used for statistics and not applying a
Junio C Hamano942b35e2007-12-09 10:19:33151patch, it defaults to `nowarn`.
152+
153You can use different `<action>` to control this
154behavior:
Junio C Hamano5f327762006-03-02 09:14:51155+
156* `nowarn` turns off the trailing whitespace warning.
157* `warn` outputs warnings for a few such errors, but applies the
Junio C Hamano942b35e2007-12-09 10:19:33158 patch as-is (default).
159* `fix` outputs warnings for a few such errors, and applies the
160 patch after fixing them (`strip` is a synonym --- the tool
161 used to consider only trailing whitespaces as errors, and the
162 fix involved 'stripping' them, but modern gits do more).
Junio C Hamano5f327762006-03-02 09:14:51163* `error` outputs warnings for a few such errors, and refuses
164 to apply the patch.
165* `error-all` is similar to `error` but shows all errors.
Junio C Hamano5f327762006-03-02 09:14:51166
Junio C Hamano3a971022006-11-18 22:17:58167--inaccurate-eof::
Junio C Hamano6b2cee12006-08-26 08:43:31168Under certain circumstances, some versions of diff do not correctly
169detect a missing new-line at the end of the file. As a result, patches
170created by such diff programs do not record incomplete lines
171correctly. This option adds support for applying such patches by
172working around this bug.
173
Junio C Hamanoeb415992008-06-08 22:49:47174-v::
175--verbose::
Junio C Hamano6b2cee12006-08-26 08:43:31176Report progress to stderr. By default, only a message about the
177current patch being applied will be printed. This option will cause
178additional information to be reported.
Junio C Hamano5f327762006-03-02 09:14:51179
Junio C Hamanofce7c7e2008-07-02 03:06:38180--recount::
181Do not trust the line counts in the hunk headers, but infer them
182by inspecting the patch (e.g. after editing the patch without
183adjusting the hunk headers appropriately).
184
Junio C Hamano5f327762006-03-02 09:14:51185Configuration
186-------------
187
188apply.whitespace::
189When no `--whitespace` flag is given from the command
190line, this configuration item is used as the default.
191
Junio C Hamano3b178be2007-08-16 04:59:27192Submodules
193----------
Junio C Hamanofce7c7e2008-07-02 03:06:38194If the patch contains any changes to submodules then `git-apply`
Junio C Hamano3b178be2007-08-16 04:59:27195treats these changes as follows.
196
197If --index is specified (explicitly or implicitly), then the submodule
198commits must match the index exactly for the patch to apply. If any
199of the submodules are checked-out, then these check-outs are completely
200ignored, i.e., they are not required to be up-to-date or clean and they
201are not updated.
202
203If --index is not specified, then the submodule commits in the patch
204are ignored and only the absence of presence of the corresponding
205subdirectory is checked and (if possible) updated.
Junio C Hamano5f327762006-03-02 09:14:51206
Junio C Hamano1a4e8412005-12-27 08:17:23207Author
208------
209Written by Linus Torvalds <torvalds@osdl.org>
210
211Documentation
212--------------
213Documentation by Junio C Hamano
214
215GIT
216---
Junio C Hamanof7c042d2008-06-06 22:50:53217Part of the linkgit:git[1] suite