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 | --intent-to-add] [--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 | --quiet] [--unsafe-paths] [--allow-empty] [<patch>...]
17

DESCRIPTION

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

OPTIONS

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

CONFIGURATION

250       apply.ignoreWhitespace
251           Set to change if you want changes in whitespace to be ignored by
252           default. Set to one of: no, none, never, false if you want changes
253           in whitespace to be significant.
254
255       apply.whitespace
256           When no --whitespace flag is given from the command line, this
257           configuration item is used as the default.
258

SUBMODULES

260       If the patch contains any changes to submodules then git apply treats
261       these changes as follows.
262
263       If --index is specified (explicitly or implicitly), then the submodule
264       commits must match the index exactly for the patch to apply. If any of
265       the submodules are checked-out, then these check-outs are completely
266       ignored, i.e., they are not required to be up to date or clean and they
267       are not updated.
268
269       If --index is not specified, then the submodule commits in the patch
270       are ignored and only the absence or presence of the corresponding
271       subdirectory is checked and (if possible) updated.
272

SEE ALSO

274       git-am(1).
275

GIT

277       Part of the git(1) suite
278
279
280
281Git 2.36.1                        2022-05-05                      GIT-APPLY(1)
Impressum