1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="git-apply(1)">
\r
5 <title>git-apply(1)</title>
\r
7 <primary>git-apply(1)</primary>
\r
9 <simplesect id="git-apply(1)__name">
\r
11 <simpara>git-apply - Apply a patch to files and/or to the index</simpara>
\r
13 <simplesect id="git-apply(1)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
16 <literallayout><emphasis>git apply</emphasis> [--stat] [--numstat] [--summary] [--check] [--index] [--3way]
\r
17 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
\r
18 [--allow-binary-replacement | --binary] [--reject] [-z]
\r
19 [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
\r
20 [--ignore-space-change | --ignore-whitespace ]
\r
21 [--whitespace=(nowarn|warn|fix|error|error-all)]
\r
22 [--exclude=<path>] [--include=<path>] [--directory=<root>]
\r
23 [--verbose] [<patch>…]</literallayout>
\r
26 <simplesect id="git-apply(1)__description">
\r
27 <title>DESCRIPTION</title>
\r
28 <simpara>Reads the supplied diff output (i.e. "a patch") and applies it to files.
\r
29 With the <emphasis>--index</emphasis> option the patch is also applied to the index, and
\r
30 with the <emphasis>--cached</emphasis> option the patch is only applied to the index.
\r
31 Without these options, the command applies the patch only to files,
\r
32 and does not require them to be in a git repository.</simpara>
\r
33 <simpara>This command applies the patch but does not create a commit. Use
\r
34 <xref linkend="git-am(1)" /> to create commits from patches generated by
\r
35 <xref linkend="git-format-patch(1)" /> and/or received by email.</simpara>
\r
37 <simplesect id="git-apply(1)__options">
\r
38 <title>OPTIONS</title>
\r
42 <patch>…
\r
46 The files to read the patch from. <emphasis>-</emphasis> can be used to read
\r
47 from the standard input.
\r
57 Instead of applying the patch, output diffstat for the
\r
58 input. Turns off "apply".
\r
68 Similar to <emphasis>--stat</emphasis>, but shows the number of added and
\r
69 deleted lines in decimal notation and the pathname without
\r
70 abbreviation, to make it more machine friendly. For
\r
71 binary files, outputs two <emphasis>-</emphasis> instead of saying
\r
72 <emphasis>0 0</emphasis>. Turns off "apply".
\r
82 Instead of applying the patch, output a condensed
\r
83 summary of information obtained from git diff extended
\r
84 headers, such as creations, renames and mode changes.
\r
95 Instead of applying the patch, see if the patch is
\r
96 applicable to the current working tree and/or the index
\r
97 file and detects errors. Turns off "apply".
\r
107 When <emphasis>--check</emphasis> is in effect, or when applying the patch
\r
108 (which is the default when none of the options that
\r
109 disables it is in effect), make sure the patch is
\r
110 applicable to what the current index file records. If
\r
111 the file to be patched in the working tree is not
\r
112 up-to-date, it is flagged as an error. This flag also
\r
113 causes the index file to be updated.
\r
123 Apply a patch without touching the working tree. Instead take the
\r
124 cached data, apply the patch, and store the result in the index
\r
125 without using the working tree. This implies <emphasis>--index</emphasis>.
\r
138 When the patch does not apply cleanly, fall back on 3-way merge if
\r
139 the patch records the identity of blobs it is supposed to apply to,
\r
140 and we have those blobs available locally, possibly leaving the
\r
141 conflict markers in the files in the working tree for the user to
\r
142 resolve. This option implies the <emphasis>--index</emphasis> option, and is incompatible
\r
143 with the <emphasis>--reject</emphasis> and the <emphasis>--cached</emphasis> options.
\r
149 --build-fake-ancestor=<file>
\r
153 Newer <emphasis>git diff</emphasis> output has embedded <emphasis>index information</emphasis>
\r
154 for each blob to help identify the original version that
\r
155 the patch applies to. When this flag is given, and if
\r
156 the original versions of the blobs are available locally,
\r
157 builds a temporary index containing those blobs.
\r
159 <simpara>When a pure mode change is encountered (which has no index information),
\r
160 the information is read from the current index instead.</simpara>
\r
172 Apply the patch in reverse.
\r
182 For atomicity, <emphasis>git apply</emphasis> by default fails the whole patch and
\r
183 does not touch the working tree when some of the hunks
\r
184 do not apply. This option makes it apply
\r
185 the parts of the patch that are applicable, and leave the
\r
186 rejected hunks in corresponding *.rej files.
\r
196 When <emphasis>--numstat</emphasis> has been given, do not munge pathnames,
\r
197 but use a NUL-terminated machine-readable format.
\r
199 <simpara>Without this option, each pathname output will have TAB, LF, double quotes,
\r
200 and backslash characters replaced with <emphasis>\t</emphasis>, <emphasis>\n</emphasis>, <emphasis>\"</emphasis>, and <emphasis>\\</emphasis>,
\r
201 respectively, and the pathname will be enclosed in double quotes if
\r
202 any of those replacements occurred.</simpara>
\r
211 Remove <n> leading slashes from traditional diff paths. The
\r
222 Ensure at least <n> lines of surrounding context match before
\r
223 and after each change. When fewer lines of surrounding
\r
224 context exist they all must match. By default no context is
\r
235 By default, <emphasis>git apply</emphasis> expects that the patch being
\r
236 applied is a unified diff with at least one line of context.
\r
237 This provides good safety measures, but breaks down when
\r
238 applying a diff generated with <emphasis>--unified=0</emphasis>. To bypass these
\r
239 checks use <emphasis>--unidiff-zero</emphasis>.
\r
241 <simpara>Note, for the reasons stated above usage of context-free patches is
\r
242 discouraged.</simpara>
\r
251 If you use any of the options marked "Turns off
\r
252 <emphasis>apply</emphasis>" above, <emphasis>git apply</emphasis> reads and outputs the
\r
253 requested information without actually applying the
\r
254 patch. Give this flag after those flags to also apply
\r
265 When applying a patch, ignore additions made by the
\r
266 patch. This can be used to extract the common part between
\r
267 two files by first running <emphasis>diff</emphasis> on them and applying
\r
268 the result with this option, which would apply the
\r
269 deletion part but not the addition part.
\r
275 --allow-binary-replacement
\r
282 Historically we did not allow binary patch applied
\r
283 without an explicit permission from the user, and this
\r
284 flag was the way to do so. Currently we always allow binary
\r
285 patch application, so this is a no-op.
\r
291 --exclude=<path-pattern>
\r
295 Don't apply changes to files matching the given path pattern. This can
\r
296 be useful when importing patchsets, where you want to exclude certain
\r
297 files or directories.
\r
303 --include=<path-pattern>
\r
307 Apply changes to files matching the given path pattern. This can
\r
308 be useful when importing patchsets, where you want to include certain
\r
309 files or directories.
\r
311 <simpara>When <emphasis>--exclude</emphasis> and <emphasis>--include</emphasis> patterns are used, they are examined in the
\r
312 order they appear on the command line, and the first match determines if a
\r
313 patch to each path is used. A patch to a path that does not match any
\r
314 include/exclude pattern is used by default if there is no include pattern
\r
315 on the command line, and ignored if there is any include pattern.</simpara>
\r
320 --ignore-space-change
\r
323 --ignore-whitespace
\r
327 When applying a patch, ignore changes in whitespace in context
\r
328 lines if necessary.
\r
329 Context lines will preserve their whitespace, and they will not
\r
330 undergo whitespace fixing regardless of the value of the
\r
331 <emphasis>--whitespace</emphasis> option. New lines will still be fixed, though.
\r
337 --whitespace=<action>
\r
341 When applying a patch, detect a new or modified line that has
\r
342 whitespace errors. What are considered whitespace errors is
\r
343 controlled by <emphasis>core.whitespace</emphasis> configuration. By default,
\r
344 trailing whitespaces (including lines that solely consist of
\r
345 whitespaces) and a space character that is immediately followed
\r
346 by a tab character inside the initial indent of the line are
\r
347 considered whitespace errors.
\r
349 <simpara>By default, the command outputs warning messages but applies the patch.
\r
350 When <emphasis>git-apply</emphasis> is used for statistics and not applying a
\r
351 patch, it defaults to <emphasis>nowarn</emphasis>.</simpara>
\r
352 <simpara>You can use different <emphasis><action></emphasis> values to control this
\r
353 behavior:</simpara>
\r
357 <emphasis>nowarn</emphasis> turns off the trailing whitespace warning.
\r
362 <emphasis>warn</emphasis> outputs warnings for a few such errors, but applies the
\r
363 patch as-is (default).
\r
368 <emphasis>fix</emphasis> outputs warnings for a few such errors, and applies the
\r
369 patch after fixing them (<emphasis>strip</emphasis> is a synonym --- the tool
\r
370 used to consider only trailing whitespace characters as errors, and the
\r
371 fix involved <emphasis>stripping</emphasis> them, but modern gits do more).
\r
376 <emphasis>error</emphasis> outputs warnings for a few such errors, and refuses
\r
377 to apply the patch.
\r
382 <emphasis>error-all</emphasis> is similar to <emphasis>error</emphasis> but shows all errors.
\r
394 Under certain circumstances, some versions of <emphasis>diff</emphasis> do not correctly
\r
395 detect a missing new-line at the end of the file. As a result, patches
\r
396 created by such <emphasis>diff</emphasis> programs do not record incomplete lines
\r
397 correctly. This option adds support for applying such patches by
\r
398 working around this bug.
\r
411 Report progress to stderr. By default, only a message about the
\r
412 current patch being applied will be printed. This option will cause
\r
413 additional information to be reported.
\r
423 Do not trust the line counts in the hunk headers, but infer them
\r
424 by inspecting the patch (e.g. after editing the patch without
\r
425 adjusting the hunk headers appropriately).
\r
431 --directory=<root>
\r
435 Prepend <root> to all filenames. If a "-p" argument was also passed,
\r
436 it is applied before prepending the new root.
\r
438 <simpara>For example, a patch that talks about updating <emphasis>a/git-gui.sh</emphasis> to <emphasis>b/git-gui.sh</emphasis>
\r
439 can be applied to the file in the working tree <emphasis>modules/git-gui/git-gui.sh</emphasis> by
\r
440 running <emphasis>git apply --directory=modules/git-gui</emphasis>.</simpara>
\r
445 <simplesect id="git-apply(1)__configuration">
\r
446 <title>Configuration</title>
\r
450 apply.ignorewhitespace
\r
454 Set to <emphasis>change</emphasis> if you want changes in whitespace to be ignored by default.
\r
455 Set to one of: no, none, never, false if you want changes in
\r
456 whitespace to be significant.
\r
466 When no <emphasis>--whitespace</emphasis> flag is given from the command
\r
467 line, this configuration item is used as the default.
\r
473 <simplesect id="git-apply(1)__submodules">
\r
474 <title>Submodules</title>
\r
475 <simpara>If the patch contains any changes to submodules then <emphasis>git apply</emphasis>
\r
476 treats these changes as follows.</simpara>
\r
477 <simpara>If <emphasis>--index</emphasis> is specified (explicitly or implicitly), then the submodule
\r
478 commits must match the index exactly for the patch to apply. If any
\r
479 of the submodules are checked-out, then these check-outs are completely
\r
480 ignored, i.e., they are not required to be up-to-date or clean and they
\r
481 are not updated.</simpara>
\r
482 <simpara>If <emphasis>--index</emphasis> is not specified, then the submodule commits in the patch
\r
483 are ignored and only the absence or presence of the corresponding
\r
484 subdirectory is checked and (if possible) updated.</simpara>
\r
486 <simplesect id="git-apply(1)__see_also">
\r
487 <title>SEE ALSO</title>
\r
488 <simpara><xref linkend="git-am(1)" />.</simpara>
\r
490 <simplesect id="git-apply(1)__git">
\r
492 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r