1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
\r
4 <article lang="en" id="git-apply(1)">
\r
6 <title>git-apply(1)</title>
\r
8 <primary>git-apply(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-apply - Apply a patch on a git index file and a working tree</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git apply</emphasis> [--stat] [--numstat] [--summary] [--check] [--index]
\r
19 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
\r
20 [--allow-binary-replacement | --binary] [--reject] [-z]
\r
21 [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached]
\r
22 [--whitespace=<nowarn|warn|fix|error|error-all>]
\r
23 [--exclude=PATH] [--include=PATH] [--directory=<root>]
\r
24 [--verbose] [<patch>…]</literallayout>
\r
27 <simplesect id="_description">
\r
28 <title>DESCRIPTION</title>
\r
29 <simpara>Reads supplied <emphasis>diff</emphasis> output and applies it on a git index file
\r
30 and a work tree.</simpara>
\r
32 <simplesect id="_options">
\r
33 <title>OPTIONS</title>
\r
37 <patch>…
\r
41 The files to read patch from. <emphasis>-</emphasis> can be used to read
\r
42 from the standard input.
\r
52 Instead of applying the patch, output diffstat for the
\r
53 input. Turns off "apply".
\r
63 Similar to --stat, but shows number of added and
\r
64 deleted lines in decimal notation and pathname without
\r
65 abbreviation, to make it more machine friendly. For
\r
66 binary files, outputs two <literal>-</literal> instead of saying
\r
67 <literal>0 0</literal>. Turns off "apply".
\r
77 Instead of applying the patch, output a condensed
\r
78 summary of information obtained from git diff extended
\r
79 headers, such as creations, renames and mode changes.
\r
90 Instead of applying the patch, see if the patch is
\r
91 applicable to the current work tree and/or the index
\r
92 file and detects errors. Turns off "apply".
\r
102 When --check is in effect, or when applying the patch
\r
103 (which is the default when none of the options that
\r
104 disables it is in effect), make sure the patch is
\r
105 applicable to what the current index file records. If
\r
106 the file to be patched in the work tree is not
\r
107 up-to-date, it is flagged as an error. This flag also
\r
108 causes the index file to be updated.
\r
118 Apply a patch without touching the working tree. Instead, take the
\r
119 cached data, apply the patch, and store the result in the index,
\r
120 without using the working tree. This implies <emphasis>--index</emphasis>.
\r
126 --build-fake-ancestor=<file>
\r
130 Newer <emphasis>git-diff</emphasis> output has embedded <emphasis>index information</emphasis>
\r
131 for each blob to help identify the original version that
\r
132 the patch applies to. When this flag is given, and if
\r
133 the original versions of the blobs is available locally,
\r
134 builds a temporary index containing those blobs.
\r
136 <simpara>When a pure mode change is encountered (which has no index information),
\r
137 the information is read from the current index instead.</simpara>
\r
149 Apply the patch in reverse.
\r
159 For atomicity, <emphasis>git-apply</emphasis> by default fails the whole patch and
\r
160 does not touch the working tree when some of the hunks
\r
161 do not apply. This option makes it apply
\r
162 the parts of the patch that are applicable, and leave the
\r
163 rejected hunks in corresponding *.rej files.
\r
173 When showing the index information, do not munge paths,
\r
174 but use NUL terminated machine readable format. Without
\r
175 this flag, the pathnames output will have TAB, LF, and
\r
176 backslash characters replaced with <literal>\t</literal>, <literal>\n</literal>, and <literal>\\</literal>,
\r
187 Remove <n> leading slashes from traditional diff paths. The
\r
198 Ensure at least <n> lines of surrounding context match before
\r
199 and after each change. When fewer lines of surrounding
\r
200 context exist they all must match. By default no context is
\r
211 By default, <emphasis>git-apply</emphasis> expects that the patch being
\r
212 applied is a unified diff with at least one line of context.
\r
213 This provides good safety measures, but breaks down when
\r
214 applying a diff generated with --unified=0. To bypass these
\r
215 checks use <emphasis>--unidiff-zero</emphasis>.
\r
217 <simpara>Note, for the reasons stated above usage of context-free patches are
\r
218 discouraged.</simpara>
\r
227 If you use any of the options marked "Turns off
\r
228 <emphasis>apply</emphasis>" above, <emphasis>git-apply</emphasis> reads and outputs the
\r
229 information you asked without actually applying the
\r
230 patch. Give this flag after those flags to also apply
\r
241 When applying a patch, ignore additions made by the
\r
242 patch. This can be used to extract the common part between
\r
243 two files by first running <emphasis>diff</emphasis> on them and applying
\r
244 the result with this option, which would apply the
\r
245 deletion part but not addition part.
\r
251 --allow-binary-replacement
\r
258 Historically we did not allow binary patch applied
\r
259 without an explicit permission from the user, and this
\r
260 flag was the way to do so. Currently we always allow binary
\r
261 patch application, so this is a no-op.
\r
267 --exclude=<path-pattern>
\r
271 Don’t apply changes to files matching the given path pattern. This can
\r
272 be useful when importing patchsets, where you want to exclude certain
\r
273 files or directories.
\r
279 --include=<path-pattern>
\r
283 Apply changes to files matching the given path pattern. This can
\r
284 be useful when importing patchsets, where you want to include certain
\r
285 files or directories.
\r
287 <simpara>When --exclude and --include patterns are used, they are examined in the
\r
288 order they appear on the command line, and the first match determines if a
\r
289 patch to each path is used. A patch to a path that does not match any
\r
290 include/exclude pattern is used by default if there is no include pattern
\r
291 on the command line, and ignored if there is any include pattern.</simpara>
\r
296 --whitespace=<action>
\r
300 When applying a patch, detect a new or modified line that has
\r
301 whitespace errors. What are considered whitespace errors is
\r
302 controlled by <literal>core.whitespace</literal> configuration. By default,
\r
303 trailing whitespaces (including lines that solely consist of
\r
304 whitespaces) and a space character that is immediately followed
\r
305 by a tab character inside the initial indent of the line are
\r
306 considered whitespace errors.
\r
308 <simpara>By default, the command outputs warning messages but applies the patch.
\r
309 When <literal>git-apply is used for statistics and not applying a
\r
310 patch, it defaults to `nowarn</literal>.</simpara>
\r
311 <simpara>You can use different <literal><action></literal> to control this
\r
312 behavior:</simpara>
\r
316 <literal>nowarn</literal> turns off the trailing whitespace warning.
\r
321 <literal>warn</literal> outputs warnings for a few such errors, but applies the
\r
322 patch as-is (default).
\r
327 <literal>fix</literal> outputs warnings for a few such errors, and applies the
\r
328 patch after fixing them (<literal>strip</literal> is a synonym --- the tool
\r
329 used to consider only trailing whitespaces as errors, and the
\r
330 fix involved <emphasis>stripping</emphasis> them, but modern gits do more).
\r
335 <literal>error</literal> outputs warnings for a few such errors, and refuses
\r
336 to apply the patch.
\r
341 <literal>error-all</literal> is similar to <literal>error</literal> but shows all errors.
\r
353 Under certain circumstances, some versions of <emphasis>diff</emphasis> do not correctly
\r
354 detect a missing new-line at the end of the file. As a result, patches
\r
355 created by such <emphasis>diff</emphasis> programs do not record incomplete lines
\r
356 correctly. This option adds support for applying such patches by
\r
357 working around this bug.
\r
370 Report progress to stderr. By default, only a message about the
\r
371 current patch being applied will be printed. This option will cause
\r
372 additional information to be reported.
\r
382 Do not trust the line counts in the hunk headers, but infer them
\r
383 by inspecting the patch (e.g. after editing the patch without
\r
384 adjusting the hunk headers appropriately).
\r
390 --directory=<root>
\r
394 Prepend <root> to all filenames. If a "-p" argument was passed, too,
\r
395 it is applied before prepending the new root.
\r
397 <simpara>For example, a patch that talks about updating <literal>a/git-gui.sh</literal> to <literal>b/git-gui.sh</literal>
\r
398 can be applied to the file in the working tree <literal>modules/git-gui/git-gui.sh</literal> by
\r
399 running <literal>git apply --directory=modules/git-gui</literal>.</simpara>
\r
404 <simplesect id="_configuration">
\r
405 <title>Configuration</title>
\r
413 When no <literal>--whitespace</literal> flag is given from the command
\r
414 line, this configuration item is used as the default.
\r
420 <simplesect id="_submodules">
\r
421 <title>Submodules</title>
\r
422 <simpara>If the patch contains any changes to submodules then <emphasis>git-apply</emphasis>
\r
423 treats these changes as follows.</simpara>
\r
424 <simpara>If --index is specified (explicitly or implicitly), then the submodule
\r
425 commits must match the index exactly for the patch to apply. If any
\r
426 of the submodules are checked-out, then these check-outs are completely
\r
427 ignored, i.e., they are not required to be up-to-date or clean and they
\r
428 are not updated.</simpara>
\r
429 <simpara>If --index is not specified, then the submodule commits in the patch
\r
430 are ignored and only the absence of presence of the corresponding
\r
431 subdirectory is checked and (if possible) updated.</simpara>
\r
433 <simplesect id="_author">
\r
434 <title>Author</title>
\r
435 <simpara>Written by Linus Torvalds <<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>></simpara>
\r
437 <simplesect id="_documentation">
\r
438 <title>Documentation</title>
\r
439 <simpara>Documentation by Junio C Hamano</simpara>
\r
441 <simplesect id="_git">
\r
443 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
\r