Autogenerated manpages for v2.46.0-39-g891ee
[git-manpages.git] / man1 / git-apply.1
blob54bb5aca60fbc4e82d5721190439c604bb5a63dc
1 '\" t
2 .\"     Title: git-apply
3 .\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
5 .\"      Date: 2024-07-31
6 .\"    Manual: Git Manual
7 .\"    Source: Git 2.46.0.39.g891ee3b9db
8 .\"  Language: English
9 .\"
10 .TH "GIT\-APPLY" "1" "2024-07-31" "Git 2\&.46\&.0\&.39\&.g891ee3b" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 git-apply \- Apply a patch to files and/or to the index
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 \fIgit apply\fR [\-\-stat] [\-\-numstat] [\-\-summary] [\-\-check] [\-\-index | \-\-intent\-to\-add] [\-\-3way]
36           [\-\-apply] [\-\-no\-add] [\-\-build\-fake\-ancestor=<file>] [\-R | \-\-reverse]
37           [\-\-allow\-binary\-replacement | \-\-binary] [\-\-reject] [\-z]
38           [\-p<n>] [\-C<n>] [\-\-inaccurate\-eof] [\-\-recount] [\-\-cached]
39           [\-\-ignore\-space\-change | \-\-ignore\-whitespace]
40           [\-\-whitespace=(nowarn|warn|fix|error|error\-all)]
41           [\-\-exclude=<path>] [\-\-include=<path>] [\-\-directory=<root>]
42           [\-\-verbose | \-\-quiet] [\-\-unsafe\-paths] [\-\-allow\-empty] [<patch>\&...\:]
43 .fi
44 .SH "DESCRIPTION"
45 .sp
46 Reads the supplied diff output (i\&.e\&. "a patch") and applies it to files\&. When running from a subdirectory in a repository, patched paths outside the directory are ignored\&. With the \fB\-\-index\fR option, the patch is also applied to the index, and with the \fB\-\-cached\fR option, the patch is only applied to the index\&. Without these options, the command applies the patch only to files, and does not require them to be in a Git repository\&.
47 .sp
48 This command applies the patch but does not create a commit\&. Use \fBgit-am\fR(1) to create commits from patches generated by \fBgit-format-patch\fR(1) and/or received by email\&.
49 .SH "OPTIONS"
50 .PP
51 <patch>\&...\:
52 .RS 4
53 The files to read the patch from\&.
54 \fI\-\fR
55 can be used to read from the standard input\&.
56 .RE
57 .PP
58 \-\-stat
59 .RS 4
60 Instead of applying the patch, output diffstat for the input\&. Turns off "apply"\&.
61 .RE
62 .PP
63 \-\-numstat
64 .RS 4
65 Similar to
66 \fB\-\-stat\fR, but shows the number of added and deleted lines in decimal notation and the pathname without abbreviation, to make it more machine friendly\&. For binary files, outputs two
67 \fB\-\fR
68 instead of saying
69 \fB0 0\fR\&. Turns off "apply"\&.
70 .RE
71 .PP
72 \-\-summary
73 .RS 4
74 Instead of applying the patch, output a condensed summary of information obtained from git diff extended headers, such as creations, renames, and mode changes\&. Turns off "apply"\&.
75 .RE
76 .PP
77 \-\-check
78 .RS 4
79 Instead of applying the patch, see if the patch is applicable to the current working tree and/or the index file and detects errors\&. Turns off "apply"\&.
80 .RE
81 .PP
82 \-\-index
83 .RS 4
84 Apply the patch to both the index and the working tree (or merely check that it would apply cleanly to both if
85 \fB\-\-check\fR
86 is in effect)\&. Note that
87 \fB\-\-index\fR
88 expects index entries and working tree copies for relevant paths to be identical (their contents and metadata such as file mode must match), and will raise an error if they are not, even if the patch would apply cleanly to both the index and the working tree in isolation\&.
89 .RE
90 .PP
91 \-\-cached
92 .RS 4
93 Apply the patch to just the index, without touching the working tree\&. If
94 \fB\-\-check\fR
95 is in effect, merely check that it would apply cleanly to the index entry\&.
96 .RE
97 .PP
98 \-\-intent\-to\-add
99 .RS 4
100 When applying the patch only to the working tree, mark new files to be added to the index later (see
101 \fB\-\-intent\-to\-add\fR
102 option in
103 \fBgit-add\fR(1))\&. This option is ignored unless running in a Git repository and
104 \fB\-\-index\fR
105 is not specified\&. Note that
106 \fB\-\-index\fR
107 could be implied by other options such as
108 \fB\-\-cached\fR
110 \fB\-\-3way\fR\&.
113 \-3, \-\-3way
114 .RS 4
115 Attempt 3\-way merge if the patch records the identity of blobs it is supposed to apply to and we have those blobs available locally, possibly leaving the conflict markers in the files in the working tree for the user to resolve\&. This option implies the
116 \fB\-\-index\fR
117 option unless the
118 \fB\-\-cached\fR
119 option is used, and is incompatible with the
120 \fB\-\-reject\fR
121 option\&. When used with the
122 \fB\-\-cached\fR
123 option, any conflicts are left at higher stages in the cache\&.
126 \-\-build\-fake\-ancestor=<file>
127 .RS 4
128 Newer
129 \fIgit diff\fR
130 output has embedded
131 \fIindex information\fR
132 for each blob to help identify the original version that the patch applies to\&. When this flag is given, and if the original versions of the blobs are available locally, builds a temporary index containing those blobs\&.
134 When a pure mode change is encountered (which has no index information), the information is read from the current index instead\&.
137 \-R, \-\-reverse
138 .RS 4
139 Apply the patch in reverse\&.
142 \-\-reject
143 .RS 4
144 For atomicity,
145 \fIgit apply\fR
146 by default fails the whole patch and does not touch the working tree when some of the hunks do not apply\&. This option makes it apply the parts of the patch that are applicable, and leave the rejected hunks in corresponding *\&.rej files\&.
150 .RS 4
151 When
152 \fB\-\-numstat\fR
153 has been given, do not munge pathnames, but use a NUL\-terminated machine\-readable format\&.
155 Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable
156 \fBcore\&.quotePath\fR
157 (see
158 \fBgit-config\fR(1))\&.
161 \-p<n>
162 .RS 4
163 Remove <n> leading path components (separated by slashes) from traditional diff paths\&. E\&.g\&., with
164 \fB\-p2\fR, a patch against
165 \fBa/dir/file\fR
166 will be applied directly to
167 \fBfile\fR\&. The default is 1\&.
170 \-C<n>
171 .RS 4
172 Ensure at least <n> lines of surrounding context match before and after each change\&. When fewer lines of surrounding context exist they all must match\&. By default no context is ever ignored\&.
175 \-\-unidiff\-zero
176 .RS 4
177 By default,
178 \fIgit apply\fR
179 expects that the patch being applied is a unified diff with at least one line of context\&. This provides good safety measures, but breaks down when applying a diff generated with
180 \fB\-\-unified=0\fR\&. To bypass these checks use
181 \fB\-\-unidiff\-zero\fR\&.
183 Note, for the reasons stated above, the usage of context\-free patches is discouraged\&.
186 \-\-apply
187 .RS 4
188 If you use any of the options marked "Turns off
189 \fIapply\fR" above,
190 \fIgit apply\fR
191 reads and outputs the requested information without actually applying the patch\&. Give this flag after those flags to also apply the patch\&.
194 \-\-no\-add
195 .RS 4
196 When applying a patch, ignore additions made by the patch\&. This can be used to extract the common part between two files by first running
197 \fIdiff\fR
198 on them and applying the result with this option, which would apply the deletion part but not the addition part\&.
201 \-\-allow\-binary\-replacement, \-\-binary
202 .RS 4
203 Historically we did not allow binary patch application without an explicit permission from the user, and this flag was the way to do so\&. Currently, we always allow binary patch application, so this is a no\-op\&.
206 \-\-exclude=<path\-pattern>
207 .RS 4
208 Don\(cqt apply changes to files matching the given path pattern\&. This can be useful when importing patchsets, where you want to exclude certain files or directories\&.
211 \-\-include=<path\-pattern>
212 .RS 4
213 Apply changes to files matching the given path pattern\&. This can be useful when importing patchsets, where you want to include certain files or directories\&.
215 When
216 \fB\-\-exclude\fR
218 \fB\-\-include\fR
219 patterns are used, they are examined in the order they appear on the command line, and the first match determines if a patch to each path is used\&. A patch to a path that does not match any include/exclude pattern is used by default if there is no include pattern on the command line, and ignored if there is any include pattern\&.
222 \-\-ignore\-space\-change, \-\-ignore\-whitespace
223 .RS 4
224 When applying a patch, ignore changes in whitespace in context lines if necessary\&. Context lines will preserve their whitespace, and they will not undergo whitespace fixing regardless of the value of the
225 \fB\-\-whitespace\fR
226 option\&. New lines will still be fixed, though\&.
229 \-\-whitespace=<action>
230 .RS 4
231 When applying a patch, detect a new or modified line that has whitespace errors\&. What are considered whitespace errors is controlled by
232 \fBcore\&.whitespace\fR
233 configuration\&. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors\&.
235 By default, the command outputs warning messages but applies the patch\&. When
236 \fBgit\-apply\fR
237 is used for statistics and not applying a patch, it defaults to
238 \fBnowarn\fR\&.
240 You can use different
241 \fB<action>\fR
242 values to control this behavior:
244 .RS 4
245 .ie n \{\
246 \h'-04'\(bu\h'+03'\c
248 .el \{\
249 .sp -1
250 .IP \(bu 2.3
252 \fBnowarn\fR
253 turns off the trailing whitespace warning\&.
256 .RS 4
257 .ie n \{\
258 \h'-04'\(bu\h'+03'\c
260 .el \{\
261 .sp -1
262 .IP \(bu 2.3
264 \fBwarn\fR
265 outputs warnings for a few such errors, but applies the patch as\-is (default)\&.
268 .RS 4
269 .ie n \{\
270 \h'-04'\(bu\h'+03'\c
272 .el \{\
273 .sp -1
274 .IP \(bu 2.3
276 \fBfix\fR
277 outputs warnings for a few such errors, and applies the patch after fixing them (\fBstrip\fR
278 is a synonym \(em the tool used to consider only trailing whitespace characters as errors, and the fix involved
279 \fIstripping\fR
280 them, but modern Gits do more)\&.
283 .RS 4
284 .ie n \{\
285 \h'-04'\(bu\h'+03'\c
287 .el \{\
288 .sp -1
289 .IP \(bu 2.3
291 \fBerror\fR
292 outputs warnings for a few such errors, and refuses to apply the patch\&.
295 .RS 4
296 .ie n \{\
297 \h'-04'\(bu\h'+03'\c
299 .el \{\
300 .sp -1
301 .IP \(bu 2.3
303 \fBerror\-all\fR
304 is similar to
305 \fBerror\fR
306 but shows all errors\&.
310 \-\-inaccurate\-eof
311 .RS 4
312 Under certain circumstances, some versions of
313 \fIdiff\fR
314 do not correctly detect a missing new\-line at the end of the file\&. As a result, patches created by such
315 \fIdiff\fR
316 programs do not record incomplete lines correctly\&. This option adds support for applying such patches by working around this bug\&.
319 \-v, \-\-verbose
320 .RS 4
321 Report progress to stderr\&. By default, only a message about the current patch being applied will be printed\&. This option will cause additional information to be reported\&.
324 \-q, \-\-quiet
325 .RS 4
326 Suppress stderr output\&. Messages about patch status and progress will not be printed\&.
329 \-\-recount
330 .RS 4
331 Do not trust the line counts in the hunk headers, but infer them by inspecting the patch (e\&.g\&. after editing the patch without adjusting the hunk headers appropriately)\&.
334 \-\-directory=<root>
335 .RS 4
336 Prepend <root> to all filenames\&. If a "\-p" argument was also passed, it is applied before prepending the new root\&.
338 For example, a patch that talks about updating
339 \fBa/git\-gui\&.sh\fR
341 \fBb/git\-gui\&.sh\fR
342 can be applied to the file in the working tree
343 \fBmodules/git\-gui/git\-gui\&.sh\fR
344 by running
345 \fBgit apply \-\-directory=modules/git\-gui\fR\&.
348 \-\-unsafe\-paths
349 .RS 4
350 By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "git apply" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief)\&.
352 When
353 \fBgit apply\fR
354 is used as a "better GNU patch", the user can pass the
355 \fB\-\-unsafe\-paths\fR
356 option to override this safety check\&. This option has no effect when
357 \fB\-\-index\fR
359 \fB\-\-cached\fR
360 is in use\&.
363 \-\-allow\-empty
364 .RS 4
365 Don\(cqt return an error for patches containing no diff\&. This includes empty patches and patches with commit text only\&.
367 .SH "CONFIGURATION"
369 Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
371 apply\&.ignoreWhitespace
372 .RS 4
373 When set to
374 \fIchange\fR, tells
375 \fIgit apply\fR
376 to ignore changes in whitespace, in the same way as the
377 \fB\-\-ignore\-space\-change\fR
378 option\&. When set to one of: no, none, never, false, it tells
379 \fIgit apply\fR
380 to respect all whitespace differences\&. See
381 \fBgit-apply\fR(1)\&.
384 apply\&.whitespace
385 .RS 4
386 Tells
387 \fIgit apply\fR
388 how to handle whitespace, in the same way as the
389 \fB\-\-whitespace\fR
390 option\&. See
391 \fBgit-apply\fR(1)\&.
393 .SH "SUBMODULES"
395 If the patch contains any changes to submodules then \fIgit apply\fR treats these changes as follows\&.
397 If \fB\-\-index\fR is specified (explicitly or implicitly), then the submodule commits must match the index exactly for the patch to apply\&. If any of the submodules are checked\-out, then these check\-outs are completely ignored, i\&.e\&., they are not required to be up to date or clean and they are not updated\&.
399 If \fB\-\-index\fR is not specified, then the submodule commits in the patch are ignored and only the absence or presence of the corresponding subdirectory is checked and (if possible) updated\&.
400 .SH "SEE ALSO"
402 \fBgit-am\fR(1)\&.
403 .SH "GIT"
405 Part of the \fBgit\fR(1) suite