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

CONFIGURATION

241       apply.ignoreWhitespace
242           Set to change if you want changes in whitespace to be ignored by
243           default. Set to one of: no, none, never, false if you want changes
244           in whitespace to be significant.
245
246       apply.whitespace
247           When no --whitespace flag is given from the command line, this
248           configuration item is used as the default.
249

SUBMODULES

251       If the patch contains any changes to submodules then git apply treats
252       these changes as follows.
253
254       If --index is specified (explicitly or implicitly), then the submodule
255       commits must match the index exactly for the patch to apply. If any of
256       the submodules are checked-out, then these check-outs are completely
257       ignored, i.e., they are not required to be up to date or clean and they
258       are not updated.
259
260       If --index is not specified, then the submodule commits in the patch
261       are ignored and only the absence or presence of the corresponding
262       subdirectory is checked and (if possible) updated.
263

SEE ALSO

265       git-am(1).
266

GIT

268       Part of the git(1) suite
269
270
271
272Git 2.30.2                        2021-03-08                      GIT-APPLY(1)
Impressum