Autogenerated manpages for v2.48.0
[git-manpages.git] / man1 / git-apply.1
blob483fddd1efae86b17b12ac839375615755c91a22
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: 2025-01-10
6 .\"    Manual: Git Manual
7 .\"    Source: Git 2.48.0
8 .\"  Language: English
9 .\"
10 .TH "GIT\-APPLY" "1" "2025-01-10" "Git 2\&.48\&.0" "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]
36           [\-\-index | \-\-intent\-to\-add] [\-\-3way] [\-\-ours | \-\-theirs | \-\-union]
37           [\-\-apply] [\-\-no\-add] [\-\-build\-fake\-ancestor=<file>] [\-R | \-\-reverse]
38           [\-\-allow\-binary\-replacement | \-\-binary] [\-\-reject] [\-z]
39           [\-p<n>] [\-C<n>] [\-\-inaccurate\-eof] [\-\-recount] [\-\-cached]
40           [\-\-ignore\-space\-change | \-\-ignore\-whitespace]
41           [\-\-whitespace=(nowarn|warn|fix|error|error\-all)]
42           [\-\-exclude=<path>] [\-\-include=<path>] [\-\-directory=<root>]
43           [\-\-verbose | \-\-quiet] [\-\-unsafe\-paths] [\-\-allow\-empty] [<patch>\&...\:]
44 .fi
45 .SH "DESCRIPTION"
46 .sp
47 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\&.
48 .sp
49 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\&.
50 .SH "OPTIONS"
51 .PP
52 <patch>\&...\:
53 .RS 4
54 The files to read the patch from\&.
55 \fI\-\fR
56 can be used to read from the standard input\&.
57 .RE
58 .PP
59 \-\-stat
60 .RS 4
61 Instead of applying the patch, output diffstat for the input\&. Turns off "apply"\&.
62 .RE
63 .PP
64 \-\-numstat
65 .RS 4
66 Similar to
67 \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
68 \fB\-\fR
69 instead of saying
70 \fB0\fR
71 \fB0\fR\&. Turns off "apply"\&.
72 .RE
73 .PP
74 \-\-summary
75 .RS 4
76 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"\&.
77 .RE
78 .PP
79 \-\-check
80 .RS 4
81 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"\&.
82 .RE
83 .PP
84 \-\-index
85 .RS 4
86 Apply the patch to both the index and the working tree (or merely check that it would apply cleanly to both if
87 \fB\-\-check\fR
88 is in effect)\&. Note that
89 \fB\-\-index\fR
90 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\&.
91 .RE
92 .PP
93 \-\-cached
94 .RS 4
95 Apply the patch to just the index, without touching the working tree\&. If
96 \fB\-\-check\fR
97 is in effect, merely check that it would apply cleanly to the index entry\&.
98 .RE
99 .PP
100 \-\-intent\-to\-add
101 .RS 4
102 When applying the patch only to the working tree, mark new files to be added to the index later (see
103 \fB\-\-intent\-to\-add\fR
104 option in
105 \fBgit-add\fR(1))\&. This option is ignored unless running in a Git repository and
106 \fB\-\-index\fR
107 is not specified\&. Note that
108 \fB\-\-index\fR
109 could be implied by other options such as
110 \fB\-\-cached\fR
112 \fB\-\-3way\fR\&.
115 \-3, \-\-3way
116 .RS 4
117 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
118 \fB\-\-index\fR
119 option unless the
120 \fB\-\-cached\fR
121 option is used, and is incompatible with the
122 \fB\-\-reject\fR
123 option\&. When used with the
124 \fB\-\-cached\fR
125 option, any conflicts are left at higher stages in the cache\&.
128 \-\-ours, \-\-theirs, \-\-union
129 .RS 4
130 Instead of leaving conflicts in the file, resolve conflicts favouring our (or their or both) side of the lines\&. Requires \-\-3way\&.
133 \-\-build\-fake\-ancestor=<file>
134 .RS 4
135 Newer
136 \fIgit diff\fR
137 output has embedded
138 \fIindex information\fR
139 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\&.
141 When a pure mode change is encountered (which has no index information), the information is read from the current index instead\&.
144 \-R, \-\-reverse
145 .RS 4
146 Apply the patch in reverse\&.
149 \-\-reject
150 .RS 4
151 For atomicity,
152 \fIgit apply\fR
153 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\&.
157 .RS 4
158 When
159 \fB\-\-numstat\fR
160 has been given, do not munge pathnames, but use a NUL\-terminated machine\-readable format\&.
162 Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable
163 \fBcore\&.quotePath\fR
164 (see
165 \fBgit-config\fR(1))\&.
168 \-p<n>
169 .RS 4
170 Remove <n> leading path components (separated by slashes) from traditional diff paths\&. E\&.g\&., with
171 \fB\-p2\fR, a patch against
172 \fBa/dir/file\fR
173 will be applied directly to
174 \fBfile\fR\&. The default is 1\&.
177 \-C<n>
178 .RS 4
179 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\&.
182 \-\-unidiff\-zero
183 .RS 4
184 By default,
185 \fIgit apply\fR
186 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
187 \fB\-\-unified=0\fR\&. To bypass these checks use
188 \fB\-\-unidiff\-zero\fR\&.
190 Note, for the reasons stated above, the usage of context\-free patches is discouraged\&.
193 \-\-apply
194 .RS 4
195 If you use any of the options marked "Turns off
196 \fIapply\fR" above,
197 \fIgit apply\fR
198 reads and outputs the requested information without actually applying the patch\&. Give this flag after those flags to also apply the patch\&.
201 \-\-no\-add
202 .RS 4
203 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
204 \fIdiff\fR
205 on them and applying the result with this option, which would apply the deletion part but not the addition part\&.
208 \-\-allow\-binary\-replacement, \-\-binary
209 .RS 4
210 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\&.
213 \-\-exclude=<path\-pattern>
214 .RS 4
215 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\&.
218 \-\-include=<path\-pattern>
219 .RS 4
220 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\&.
222 When
223 \fB\-\-exclude\fR
225 \fB\-\-include\fR
226 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\&.
229 \-\-ignore\-space\-change, \-\-ignore\-whitespace
230 .RS 4
231 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
232 \fB\-\-whitespace\fR
233 option\&. New lines will still be fixed, though\&.
236 \-\-whitespace=<action>
237 .RS 4
238 When applying a patch, detect a new or modified line that has whitespace errors\&. What are considered whitespace errors is controlled by
239 \fBcore\&.whitespace\fR
240 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\&.
242 By default, the command outputs warning messages but applies the patch\&. When
243 \fBgit\-apply\fR
244 is used for statistics and not applying a patch, it defaults to
245 \fBnowarn\fR\&.
247 You can use different
248 \fI<action>\fR
249 values to control this behavior:
251 .RS 4
252 .ie n \{\
253 \h'-04'\(bu\h'+03'\c
255 .el \{\
256 .sp -1
257 .IP \(bu 2.3
259 \fBnowarn\fR
260 turns off the trailing whitespace warning\&.
263 .RS 4
264 .ie n \{\
265 \h'-04'\(bu\h'+03'\c
267 .el \{\
268 .sp -1
269 .IP \(bu 2.3
271 \fBwarn\fR
272 outputs warnings for a few such errors, but applies the patch as\-is (default)\&.
275 .RS 4
276 .ie n \{\
277 \h'-04'\(bu\h'+03'\c
279 .el \{\
280 .sp -1
281 .IP \(bu 2.3
283 \fBfix\fR
284 outputs warnings for a few such errors, and applies the patch after fixing them (\fBstrip\fR
285 is a synonym \(em the tool used to consider only trailing whitespace characters as errors, and the fix involved
286 \fIstripping\fR
287 them, but modern Gits do more)\&.
290 .RS 4
291 .ie n \{\
292 \h'-04'\(bu\h'+03'\c
294 .el \{\
295 .sp -1
296 .IP \(bu 2.3
298 \fBerror\fR
299 outputs warnings for a few such errors, and refuses to apply the patch\&.
302 .RS 4
303 .ie n \{\
304 \h'-04'\(bu\h'+03'\c
306 .el \{\
307 .sp -1
308 .IP \(bu 2.3
310 \fBerror\-all\fR
311 is similar to
312 \fBerror\fR
313 but shows all errors\&.
317 \-\-inaccurate\-eof
318 .RS 4
319 Under certain circumstances, some versions of
320 \fIdiff\fR
321 do not correctly detect a missing new\-line at the end of the file\&. As a result, patches created by such
322 \fIdiff\fR
323 programs do not record incomplete lines correctly\&. This option adds support for applying such patches by working around this bug\&.
326 \-v, \-\-verbose
327 .RS 4
328 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\&.
331 \-q, \-\-quiet
332 .RS 4
333 Suppress stderr output\&. Messages about patch status and progress will not be printed\&.
336 \-\-recount
337 .RS 4
338 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)\&.
341 \-\-directory=<root>
342 .RS 4
343 Prepend <root> to all filenames\&. If a "\-p" argument was also passed, it is applied before prepending the new root\&.
345 For example, a patch that talks about updating
346 \fBa/git\-gui\&.sh\fR
348 \fBb/git\-gui\&.sh\fR
349 can be applied to the file in the working tree
350 \fBmodules/git\-gui/git\-gui\&.sh\fR
351 by running
352 \fBgit\fR
353 \fBapply\fR
354 \fB\-\-directory=modules/git\-gui\fR\&.
357 \-\-unsafe\-paths
358 .RS 4
359 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)\&.
361 When
362 \fBgit\fR
363 \fBapply\fR
364 is used as a "better GNU patch", the user can pass the
365 \fB\-\-unsafe\-paths\fR
366 option to override this safety check\&. This option has no effect when
367 \fB\-\-index\fR
369 \fB\-\-cached\fR
370 is in use\&.
373 \-\-allow\-empty
374 .RS 4
375 Don\(cqt return an error for patches containing no diff\&. This includes empty patches and patches with commit text only\&.
377 .SH "CONFIGURATION"
379 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:
381 apply\&.ignoreWhitespace
382 .RS 4
383 When set to
384 \fIchange\fR, tells
385 \fIgit apply\fR
386 to ignore changes in whitespace, in the same way as the
387 \fB\-\-ignore\-space\-change\fR
388 option\&. When set to one of: no, none, never, false, it tells
389 \fIgit apply\fR
390 to respect all whitespace differences\&. See
391 \fBgit-apply\fR(1)\&.
394 apply\&.whitespace
395 .RS 4
396 Tells
397 \fIgit apply\fR
398 how to handle whitespace, in the same way as the
399 \fB\-\-whitespace\fR
400 option\&. See
401 \fBgit-apply\fR(1)\&.
403 .SH "SUBMODULES"
405 If the patch contains any changes to submodules then \fIgit apply\fR treats these changes as follows\&.
407 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\&.
409 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\&.
410 .SH "SEE ALSO"
412 \fBgit-am\fR(1)\&.
413 .SH "GIT"
415 Part of the \fBgit\fR(1) suite