1GIT-APPLY(1) Git Manual GIT-APPLY(1)
2
3
4
6 git-apply - Apply a patch to files and/or to the index
7
9 git apply [--stat] [--numstat] [--summary] [--check] [--index] [--3way]
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] [--unsafe-paths] [<patch>...]
17
18
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
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 -3, --3way
69 When the patch does not apply cleanly, fall back on 3-way merge if
70 the patch records the identity of blobs it is supposed to apply to,
71 and we have those blobs available locally, possibly leaving the
72 conflict markers in the files in the working tree for the user to
73 resolve. This option implies the --index option, and is
74 incompatible with the --reject and the --cached options.
75
76 --build-fake-ancestor=<file>
77 Newer git diff output has embedded index information for each blob
78 to help identify the original version that the patch applies to.
79 When this flag is given, and if the original versions of the blobs
80 are available locally, builds a temporary index containing those
81 blobs.
82
83 When a pure mode change is encountered (which has no index
84 information), the information is read from the current index
85 instead.
86
87 -R, --reverse
88 Apply the patch in reverse.
89
90 --reject
91 For atomicity, git apply by default fails the whole patch and does
92 not touch the working tree when some of the hunks do not apply.
93 This option makes it apply the parts of the patch that are
94 applicable, and leave the rejected hunks in corresponding *.rej
95 files.
96
97 -z
98 When --numstat has been given, do not munge pathnames, but use a
99 NUL-terminated machine-readable format.
100
101 Without this option, each pathname output will have TAB, LF, double
102 quotes, and backslash characters replaced with \t, \n, \", and \\,
103 respectively, and the pathname will be enclosed in double quotes if
104 any of those replacements occurred.
105
106 -p<n>
107 Remove <n> leading slashes from traditional diff paths. The default
108 is 1.
109
110 -C<n>
111 Ensure at least <n> lines of surrounding context match before and
112 after each change. When fewer lines of surrounding context exist
113 they all must match. By default no context is ever ignored.
114
115 --unidiff-zero
116 By default, git apply expects that the patch being applied is a
117 unified diff with at least one line of context. This provides good
118 safety measures, but breaks down when applying a diff generated
119 with --unified=0. To bypass these checks use --unidiff-zero.
120
121 Note, for the reasons stated above usage of context-free patches is
122 discouraged.
123
124 --apply
125 If you use any of the options marked "Turns off apply" above, git
126 apply reads and outputs the requested information without actually
127 applying the patch. Give this flag after those flags to also apply
128 the patch.
129
130 --no-add
131 When applying a patch, ignore additions made by the patch. This can
132 be used to extract the common part between two files by first
133 running diff on them and applying the result with this option,
134 which would apply the deletion part but not the addition part.
135
136 --allow-binary-replacement, --binary
137 Historically we did not allow binary patch applied without an
138 explicit permission from the user, and this flag was the way to do
139 so. Currently we always allow binary patch application, so this is
140 a no-op.
141
142 --exclude=<path-pattern>
143 Don’t apply changes to files matching the given path pattern. This
144 can be useful when importing patchsets, where you want to exclude
145 certain files or directories.
146
147 --include=<path-pattern>
148 Apply changes to files matching the given path pattern. This can be
149 useful when importing patchsets, where you want to include certain
150 files or directories.
151
152 When --exclude and --include patterns are used, they are examined
153 in the order they appear on the command line, and the first match
154 determines if a patch to each path is used. A patch to a path that
155 does not match any include/exclude pattern is used by default if
156 there is no include pattern on the command line, and ignored if
157 there is any include pattern.
158
159 --ignore-space-change, --ignore-whitespace
160 When applying a patch, ignore changes in whitespace in context
161 lines if necessary. Context lines will preserve their whitespace,
162 and they will not undergo whitespace fixing regardless of the value
163 of the --whitespace option. New lines will still be fixed, though.
164
165 --whitespace=<action>
166 When applying a patch, detect a new or modified line that has
167 whitespace errors. What are considered whitespace errors is
168 controlled by core.whitespace configuration. By default, trailing
169 whitespaces (including lines that solely consist of whitespaces)
170 and a space character that is immediately followed by a tab
171 character inside the initial indent of the line are considered
172 whitespace errors.
173
174 By default, the command outputs warning messages but applies the
175 patch. When git-apply is used for statistics and not applying a
176 patch, it defaults to nowarn.
177
178 You can use different <action> values to control this behavior:
179
180 · nowarn turns off the trailing whitespace warning.
181
182 · warn outputs warnings for a few such errors, but applies the
183 patch as-is (default).
184
185 · fix outputs warnings for a few such errors, and applies the
186 patch after fixing them (strip is a synonym --- the tool used
187 to consider only trailing whitespace characters as errors, and
188 the fix involved stripping them, but modern Gits do more).
189
190 · error outputs warnings for a few such errors, and refuses to
191 apply the patch.
192
193 · error-all is similar to error but shows all errors.
194
195 --inaccurate-eof
196 Under certain circumstances, some versions of diff do not correctly
197 detect a missing new-line at the end of the file. As a result,
198 patches created by such diff programs do not record incomplete
199 lines correctly. This option adds support for applying such patches
200 by working around this bug.
201
202 -v, --verbose
203 Report progress to stderr. By default, only a message about the
204 current patch being applied will be printed. This option will cause
205 additional information to be reported.
206
207 --recount
208 Do not trust the line counts in the hunk headers, but infer them by
209 inspecting the patch (e.g. after editing the patch without
210 adjusting the hunk headers appropriately).
211
212 --directory=<root>
213 Prepend <root> to all filenames. If a "-p" argument was also
214 passed, it is applied before prepending the new root.
215
216 For example, a patch that talks about updating a/git-gui.sh to
217 b/git-gui.sh can be applied to the file in the working tree
218 modules/git-gui/git-gui.sh by running git apply
219 --directory=modules/git-gui.
220
221 --unsafe-paths
222 By default, a patch that affects outside the working area (either a
223 Git controlled working tree, or the current working directory when
224 "git apply" is used as a replacement of GNU patch) is rejected as a
225 mistake (or a mischief).
226
227 When git apply is used as a "better GNU patch", the user can pass
228 the --unsafe-paths option to override this safety check. This
229 option has no effect when --index or --cached is in use.
230
232 apply.ignorewhitespace
233 Set to change if you want changes in whitespace to be ignored by
234 default. Set to one of: no, none, never, false if you want changes
235 in whitespace to be significant.
236
237 apply.whitespace
238 When no --whitespace flag is given from the command line, this
239 configuration item is used as the default.
240
242 If the patch contains any changes to submodules then git apply treats
243 these changes as follows.
244
245 If --index is specified (explicitly or implicitly), then the submodule
246 commits must match the index exactly for the patch to apply. If any of
247 the submodules are checked-out, then these check-outs are completely
248 ignored, i.e., they are not required to be up-to-date or clean and they
249 are not updated.
250
251 If --index is not specified, then the submodule commits in the patch
252 are ignored and only the absence or presence of the corresponding
253 subdirectory is checked and (if possible) updated.
254
256 git-am(1).
257
259 Part of the git(1) suite
260
261
262
263Git 1.8.3.1 11/19/2018 GIT-APPLY(1)