1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.2.5" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-apply(
1)
</title>
312 git-apply(
1) Manual Page
315 <div class=
"sectionbody">
317 Apply a patch to files and/or to the index
322 <div class=
"sectionbody">
323 <div class=
"verseblock">
324 <div class=
"content"><em>git apply
</em> [--stat] [--numstat] [--summary] [--check] [--index]
325 [--apply] [--no-add] [--build-fake-ancestor=
<file
>] [-R | --reverse]
326 [--allow-binary-replacement | --binary] [--reject] [-z]
327 [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached]
328 [--ignore-space-change | --ignore-whitespace ]
329 [--whitespace=
<nowarn|warn|fix|error|error-all
>]
330 [--exclude=PATH] [--include=PATH] [--directory=
<root
>]
331 [--verbose] [
<patch
>…]
</div></div>
333 <h2 id=
"_description">DESCRIPTION
</h2>
334 <div class=
"sectionbody">
335 <div class=
"para"><p>Reads the supplied diff output (i.e.
"a patch") and applies it to files.
336 With the
<tt>--index
</tt> option the patch is also applied to the index, and
337 with the
<tt>--cache
</tt> option the patch is only applied to the index.
338 Without these options, the command applies the patch only to files,
339 and does not require them to be in a git repository.
</p></div>
341 <h2 id=
"_options">OPTIONS
</h2>
342 <div class=
"sectionbody">
343 <div class=
"vlist"><dl>
349 The files to read the patch from.
<em>-
</em> can be used to read
350 from the standard input.
358 Instead of applying the patch, output diffstat for the
359 input. Turns off
"apply".
367 Similar to
<tt>--stat
</tt>, but shows the number of added and
368 deleted lines in decimal notation and the pathname without
369 abbreviation, to make it more machine friendly. For
370 binary files, outputs two
<tt>-
</tt> instead of saying
371 <tt>0 0</tt>. Turns off
"apply".
379 Instead of applying the patch, output a condensed
380 summary of information obtained from git diff extended
381 headers, such as creations, renames and mode changes.
390 Instead of applying the patch, see if the patch is
391 applicable to the current working tree and/or the index
392 file and detects errors. Turns off
"apply".
400 When
<tt>--check
</tt> is in effect, or when applying the patch
401 (which is the default when none of the options that
402 disables it is in effect), make sure the patch is
403 applicable to what the current index file records. If
404 the file to be patched in the working tree is not
405 up-to-date, it is flagged as an error. This flag also
406 causes the index file to be updated.
414 Apply a patch without touching the working tree. Instead take the
415 cached data, apply the patch, and store the result in the index
416 without using the working tree. This implies
<tt>--index
</tt>.
420 --build-fake-ancestor=
<file
>
424 Newer
<em>git diff
</em> output has embedded
<em>index information
</em>
425 for each blob to help identify the original version that
426 the patch applies to. When this flag is given, and if
427 the original versions of the blobs are available locally,
428 builds a temporary index containing those blobs.
430 <div class=
"para"><p>When a pure mode change is encountered (which has no index information),
431 the information is read from the current index instead.
</p></div>
441 Apply the patch in reverse.
449 For atomicity,
<em>git apply
</em> by default fails the whole patch and
450 does not touch the working tree when some of the hunks
451 do not apply. This option makes it apply
452 the parts of the patch that are applicable, and leave the
453 rejected hunks in corresponding *.rej files.
461 When
<tt>--numstat
</tt> has been given, do not munge pathnames,
462 but use a NUL-terminated machine-readable format.
464 <div class=
"para"><p>Without this option, each pathname output will have TAB, LF, double quotes,
465 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
466 respectively, and the pathname will be enclosed in double quotes if
467 any of those replacements occurred.</p></div>
474 Remove <n> leading slashes from traditional diff paths. The
483 Ensure at least <n> lines of surrounding context match before
484 and after each change. When fewer lines of surrounding
485 context exist they all must match. By default no context is
494 By default, <em>git apply</em> expects that the patch being
495 applied is a unified diff with at least one line of context.
496 This provides good safety measures, but breaks down when
497 applying a diff generated with <tt>--unified=0</tt>. To bypass these
498 checks use <tt>--unidiff-zero</tt>.
500 <div class="para
"><p>Note, for the reasons stated above usage of context-free patches is
501 discouraged.</p></div>
508 If you use any of the options marked "Turns off
509 <em>apply
</em>" above, <em>git apply</em> reads and outputs the
510 requested information without actually applying the
511 patch. Give this flag after those flags to also apply
520 When applying a patch, ignore additions made by the
521 patch. This can be used to extract the common part between
522 two files by first running <em>diff</em> on them and applying
523 the result with this option, which would apply the
524 deletion part but not the addition part.
528 --allow-binary-replacement
535 Historically we did not allow binary patch applied
536 without an explicit permission from the user, and this
537 flag was the way to do so. Currently we always allow binary
538 patch application, so this is a no-op.
542 --exclude=<path-pattern>
546 Don't apply changes to files matching the given path pattern. This can
547 be useful when importing patchsets, where you want to exclude certain
548 files or directories.
552 --include=<path-pattern>
556 Apply changes to files matching the given path pattern. This can
557 be useful when importing patchsets, where you want to include certain
558 files or directories.
560 <div class="para
"><p>When <tt>--exclude</tt> and <tt>--include</tt> patterns are used, they are examined in the
561 order they appear on the command line, and the first match determines if a
562 patch to each path is used. A patch to a path that does not match any
563 include/exclude pattern is used by default if there is no include pattern
564 on the command line, and ignored if there is any include pattern.</p></div>
567 --ignore-space-change
574 When applying a patch, ignore changes in whitespace in context
576 Context lines will preserve their whitespace, and they will not
577 undergo whitespace fixing regardless of the value of the
578 <tt>--whitespace</tt> option. New lines will still be fixed, though.
582 --whitespace=<action>
586 When applying a patch, detect a new or modified line that has
587 whitespace errors. What are considered whitespace errors is
588 controlled by <tt>core.whitespace</tt> configuration. By default,
589 trailing whitespaces (including lines that solely consist of
590 whitespaces) and a space character that is immediately followed
591 by a tab character inside the initial indent of the line are
592 considered whitespace errors.
594 <div class="para
"><p>By default, the command outputs warning messages but applies the patch.
595 When <tt>git-apply</tt> is used for statistics and not applying a
596 patch, it defaults to <tt>nowarn</tt>.</p></div>
597 <div class="para
"><p>You can use different <tt><action></tt> values to control this
599 <div class="ilist
"><ul>
602 <tt>nowarn</tt> turns off the trailing whitespace warning.
607 <tt>warn</tt> outputs warnings for a few such errors, but applies the
608 patch as-is (default).
613 <tt>fix</tt> outputs warnings for a few such errors, and applies the
614 patch after fixing them (<tt>strip</tt> is a synonym --- the tool
615 used to consider only trailing whitespace characters as errors, and the
616 fix involved <em>stripping</em> them, but modern gits do more).
621 <tt>error</tt> outputs warnings for a few such errors, and refuses
627 <tt>error-all</tt> is similar to <tt>error</tt> but shows all errors.
637 Under certain circumstances, some versions of <em>diff</em> do not correctly
638 detect a missing new-line at the end of the file. As a result, patches
639 created by such <em>diff</em> programs do not record incomplete lines
640 correctly. This option adds support for applying such patches by
641 working around this bug.
652 Report progress to stderr. By default, only a message about the
653 current patch being applied will be printed. This option will cause
654 additional information to be reported.
662 Do not trust the line counts in the hunk headers, but infer them
663 by inspecting the patch (e.g. after editing the patch without
664 adjusting the hunk headers appropriately).
668 --directory=<root>
672 Prepend <root> to all filenames. If a "-p
" argument was also passed,
673 it is applied before prepending the new root.
675 <div class="para
"><p>For example, a patch that talks about updating <tt>a/git-gui.sh</tt> to <tt>b/git-gui.sh</tt>
676 can be applied to the file in the working tree <tt>modules/git-gui/git-gui.sh</tt> by
677 running <tt>git apply --directory=modules/git-gui</tt>.</p></div>
681 <h2 id="_configuration
">Configuration</h2>
682 <div class="sectionbody
">
683 <div class="vlist
"><dl>
685 apply.ignorewhitespace
689 Set to <em>change</em> if you want changes in whitespace to be ignored by default.
690 Set to one of: no, none, never, false if you want changes in
691 whitespace to be significant.
699 When no <tt>--whitespace</tt> flag is given from the command
700 line, this configuration item is used as the default.
705 <h2 id="_submodules
">Submodules</h2>
706 <div class="sectionbody
">
707 <div class="para
"><p>If the patch contains any changes to submodules then <em>git apply</em>
708 treats these changes as follows.</p></div>
709 <div class="para
"><p>If <tt>--index</tt> is specified (explicitly or implicitly), then the submodule
710 commits must match the index exactly for the patch to apply. If any
711 of the submodules are checked-out, then these check-outs are completely
712 ignored, i.e., they are not required to be up-to-date or clean and they
713 are not updated.</p></div>
714 <div class="para
"><p>If <tt>--index</tt> is not specified, then the submodule commits in the patch
715 are ignored and only the absence or presence of the corresponding
716 subdirectory is checked and (if possible) updated.</p></div>
718 <h2 id="_author
">Author</h2>
719 <div class="sectionbody
">
720 <div class="para
"><p>Written by Linus Torvalds <torvalds@osdl.org></p></div>
722 <h2 id="_documentation
">Documentation</h2>
723 <div class="sectionbody
">
724 <div class="para
"><p>Documentation by Junio C Hamano</p></div>
726 <h2 id="_git
">GIT</h2>
727 <div class="sectionbody
">
728 <div class="para
"><p>Part of the <a href="git.html
">git(1)</a> suite</p></div>
731 <div id="footer-text
">
732 Last updated 2010-01-21 17:44:21 UTC