1GIT-APPLY(1)                      Git Manual                      GIT-APPLY(1)
2
3
4

NAME

6       git-apply - Apply a patch to files and/or to the index
7

SYNOPSIS

9       git apply [--stat] [--numstat] [--summary] [--check] [--index]
10                 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
11                 [--allow-binary-replacement | --binary] [--reject] [-z]
12                 [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
13                 [--ignore-space-change | --ignore-whitespace ]
14                 [--whitespace=(nowarn|warn|fix|error|error-all)]
15                 [--exclude=<path>] [--include=<path>] [--directory=<root>]
16                 [--verbose] [<patch>...]
17
18

DESCRIPTION

20       Reads the supplied diff output (i.e. "a patch") and applies it to
21       files. With the --index option the patch is also applied to the index,
22       and with the --cached option the patch is only applied to the index.
23       Without these options, the command applies the patch only to files, and
24       does not require them to be in a git repository.
25
26       This command applies the patch but does not create a commit. Use git-
27       am(1) to create commits from patches generated by git-format-patch(1)
28       and/or received by email.
29

OPTIONS

31       <patch>...
32           The files to read the patch from.  - can be used to read from the
33           standard input.
34
35       --stat
36           Instead of applying the patch, output diffstat for the input. Turns
37           off "apply".
38
39       --numstat
40           Similar to --stat, but shows the number of added and deleted lines
41           in decimal notation and the pathname without abbreviation, to make
42           it more machine friendly. For binary files, outputs two - instead
43           of saying 0 0. Turns off "apply".
44
45       --summary
46           Instead of applying the patch, output a condensed summary of
47           information obtained from git diff extended headers, such as
48           creations, renames and mode changes. Turns off "apply".
49
50       --check
51           Instead of applying the patch, see if the patch is applicable to
52           the current working tree and/or the index file and detects errors.
53           Turns off "apply".
54
55       --index
56           When --check is in effect, or when applying the patch (which is the
57           default when none of the options that disables it is in effect),
58           make sure the patch is applicable to what the current index file
59           records. If the file to be patched in the working tree is not
60           up-to-date, it is flagged as an error. This flag also causes the
61           index file to be updated.
62
63       --cached
64           Apply a patch without touching the working tree. Instead take the
65           cached data, apply the patch, and store the result in the index
66           without using the working tree. This implies --index.
67
68       --build-fake-ancestor=<file>
69           Newer git diff output has embedded index information for each blob
70           to help identify the original version that the patch applies to.
71           When this flag is given, and if the original versions of the blobs
72           are available locally, builds a temporary index containing those
73           blobs.
74
75           When a pure mode change is encountered (which has no index
76           information), the information is read from the current index
77           instead.
78
79       -R, --reverse
80           Apply the patch in reverse.
81
82       --reject
83           For atomicity, git apply by default fails the whole patch and does
84           not touch the working tree when some of the hunks do not apply.
85           This option makes it apply the parts of the patch that are
86           applicable, and leave the rejected hunks in corresponding *.rej
87           files.
88
89       -z
90           When --numstat has been given, do not munge pathnames, but use a
91           NUL-terminated machine-readable format.
92
93           Without this option, each pathname output will have TAB, LF, double
94           quotes, and backslash characters replaced with \t, \n, \", and \\,
95           respectively, and the pathname will be enclosed in double quotes if
96           any of those replacements occurred.
97
98       -p<n>
99           Remove <n> leading slashes from traditional diff paths. The default
100           is 1.
101
102       -C<n>
103           Ensure at least <n> lines of surrounding context match before and
104           after each change. When fewer lines of surrounding context exist
105           they all must match. By default no context is ever ignored.
106
107       --unidiff-zero
108           By default, git apply expects that the patch being applied is a
109           unified diff with at least one line of context. This provides good
110           safety measures, but breaks down when applying a diff generated
111           with --unified=0. To bypass these checks use --unidiff-zero.
112
113           Note, for the reasons stated above usage of context-free patches is
114           discouraged.
115
116       --apply
117           If you use any of the options marked "Turns off apply" above, git
118           apply reads and outputs the requested information without actually
119           applying the patch. Give this flag after those flags to also apply
120           the patch.
121
122       --no-add
123           When applying a patch, ignore additions made by the patch. This can
124           be used to extract the common part between two files by first
125           running diff on them and applying the result with this option,
126           which would apply the deletion part but not the addition part.
127
128       --allow-binary-replacement, --binary
129           Historically we did not allow binary patch applied without an
130           explicit permission from the user, and this flag was the way to do
131           so. Currently we always allow binary patch application, so this is
132           a no-op.
133
134       --exclude=<path-pattern>
135           Don’t apply changes to files matching the given path pattern. This
136           can be useful when importing patchsets, where you want to exclude
137           certain files or directories.
138
139       --include=<path-pattern>
140           Apply changes to files matching the given path pattern. This can be
141           useful when importing patchsets, where you want to include certain
142           files or directories.
143
144           When --exclude and --include patterns are used, they are examined
145           in the order they appear on the command line, and the first match
146           determines if a patch to each path is used. A patch to a path that
147           does not match any include/exclude pattern is used by default if
148           there is no include pattern on the command line, and ignored if
149           there is any include pattern.
150
151       --ignore-space-change, --ignore-whitespace
152           When applying a patch, ignore changes in whitespace in context
153           lines if necessary. Context lines will preserve their whitespace,
154           and they will not undergo whitespace fixing regardless of the value
155           of the --whitespace option. New lines will still be fixed, though.
156
157       --whitespace=<action>
158           When applying a patch, detect a new or modified line that has
159           whitespace errors. What are considered whitespace errors is
160           controlled by core.whitespace configuration. By default, trailing
161           whitespaces (including lines that solely consist of whitespaces)
162           and a space character that is immediately followed by a tab
163           character inside the initial indent of the line are considered
164           whitespace errors.
165
166           By default, the command outputs warning messages but applies the
167           patch. When git-apply is used for statistics and not applying a
168           patch, it defaults to nowarn.
169
170           You can use different <action> values to control this behavior:
171
172           ·    nowarn turns off the trailing whitespace warning.
173
174           ·    warn outputs warnings for a few such errors, but applies the
175               patch as-is (default).
176
177           ·    fix outputs warnings for a few such errors, and applies the
178               patch after fixing them (strip is a synonym --- the tool used
179               to consider only trailing whitespace characters as errors, and
180               the fix involved stripping them, but modern gits do more).
181
182           ·    error outputs warnings for a few such errors, and refuses to
183               apply the patch.
184
185           ·    error-all is similar to error but shows all errors.
186
187       --inaccurate-eof
188           Under certain circumstances, some versions of diff do not correctly
189           detect a missing new-line at the end of the file. As a result,
190           patches created by such diff programs do not record incomplete
191           lines correctly. This option adds support for applying such patches
192           by working around this bug.
193
194       -v, --verbose
195           Report progress to stderr. By default, only a message about the
196           current patch being applied will be printed. This option will cause
197           additional information to be reported.
198
199       --recount
200           Do not trust the line counts in the hunk headers, but infer them by
201           inspecting the patch (e.g. after editing the patch without
202           adjusting the hunk headers appropriately).
203
204       --directory=<root>
205           Prepend <root> to all filenames. If a "-p" argument was also
206           passed, it is applied before prepending the new root.
207
208           For example, a patch that talks about updating a/git-gui.sh to
209           b/git-gui.sh can be applied to the file in the working tree
210           modules/git-gui/git-gui.sh by running git apply
211           --directory=modules/git-gui.
212

CONFIGURATION

214       apply.ignorewhitespace
215           Set to change if you want changes in whitespace to be ignored by
216           default. Set to one of: no, none, never, false if you want changes
217           in whitespace to be significant.
218
219       apply.whitespace
220           When no --whitespace flag is given from the command line, this
221           configuration item is used as the default.
222

SUBMODULES

224       If the patch contains any changes to submodules then git apply treats
225       these changes as follows.
226
227       If --index is specified (explicitly or implicitly), then the submodule
228       commits must match the index exactly for the patch to apply. If any of
229       the submodules are checked-out, then these check-outs are completely
230       ignored, i.e., they are not required to be up-to-date or clean and they
231       are not updated.
232
233       If --index is not specified, then the submodule commits in the patch
234       are ignored and only the absence or presence of the corresponding
235       subdirectory is checked and (if possible) updated.
236

SEE ALSO

238       git-am(1).
239

AUTHOR

241       Written by Linus Torvalds <torvalds@osdl.org[1]>
242

DOCUMENTATION

244       Documentation by Junio C Hamano
245

GIT

247       Part of the git(1) suite
248

NOTES

250        1. torvalds@osdl.org
251           mailto:torvalds@osdl.org
252
253
254
255Git 1.7.4.4                       04/11/2011                      GIT-APPLY(1)
Impressum