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.4.5" />
7 <title>git-apply(
1)
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.5em;
116 margin-bottom: 1.5em;
118 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
119 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
120 div
.admonitionblock
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-apply(
1) Manual Page
409 <div class=
"sectionbody">
411 Apply a patch to files and/or to the index
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"verseblock">
418 <div class=
"verseblock-content"><em>git apply
</em> [--stat] [--numstat] [--summary] [--check] [--index]
419 [--apply] [--no-add] [--build-fake-ancestor=
<file
>] [-R | --reverse]
420 [--allow-binary-replacement | --binary] [--reject] [-z]
421 [-p
<n
>] [-C
<n
>] [--inaccurate-eof] [--recount] [--cached]
422 [--ignore-space-change | --ignore-whitespace ]
423 [--whitespace=(nowarn|warn|fix|error|error-all)]
424 [--exclude=
<path
>] [--include=
<path
>] [--directory=
<root
>]
425 [--verbose] [
<patch
>…]
</div>
426 <div class=
"verseblock-attribution">
429 <h2 id=
"_description">DESCRIPTION
</h2>
430 <div class=
"sectionbody">
431 <div class=
"paragraph"><p>Reads the supplied diff output (i.e.
"a patch") and applies it to files.
432 With the
<tt>--index
</tt> option the patch is also applied to the index, and
433 with the
<tt>--cached
</tt> option the patch is only applied to the index.
434 Without these options, the command applies the patch only to files,
435 and does not require them to be in a git repository.
</p></div>
436 <div class=
"paragraph"><p>This command applies the patch but does not create a commit. Use
437 <a href=
"git-am.html">git-am(
1)
</a> to create commits from patches generated by
438 <a href=
"git-format-patch.html">git-format-patch(
1)
</a> and/or received by email.
</p></div>
440 <h2 id=
"_options">OPTIONS
</h2>
441 <div class=
"sectionbody">
442 <div class=
"dlist"><dl>
448 The files to read the patch from.
<em>-
</em> can be used to read
449 from the standard input.
457 Instead of applying the patch, output diffstat for the
458 input. Turns off
"apply".
466 Similar to
<tt>--stat
</tt>, but shows the number of added and
467 deleted lines in decimal notation and the pathname without
468 abbreviation, to make it more machine friendly. For
469 binary files, outputs two
<tt>-
</tt> instead of saying
470 <tt>0 0</tt>. Turns off
"apply".
478 Instead of applying the patch, output a condensed
479 summary of information obtained from git diff extended
480 headers, such as creations, renames and mode changes.
489 Instead of applying the patch, see if the patch is
490 applicable to the current working tree and/or the index
491 file and detects errors. Turns off
"apply".
499 When
<tt>--check
</tt> is in effect, or when applying the patch
500 (which is the default when none of the options that
501 disables it is in effect), make sure the patch is
502 applicable to what the current index file records. If
503 the file to be patched in the working tree is not
504 up-to-date, it is flagged as an error. This flag also
505 causes the index file to be updated.
513 Apply a patch without touching the working tree. Instead take the
514 cached data, apply the patch, and store the result in the index
515 without using the working tree. This implies
<tt>--index
</tt>.
519 --build-fake-ancestor=
<file
>
523 Newer
<em>git diff
</em> output has embedded
<em>index information
</em>
524 for each blob to help identify the original version that
525 the patch applies to. When this flag is given, and if
526 the original versions of the blobs are available locally,
527 builds a temporary index containing those blobs.
529 <div class=
"paragraph"><p>When a pure mode change is encountered (which has no index information),
530 the information is read from the current index instead.
</p></div>
540 Apply the patch in reverse.
548 For atomicity,
<em>git apply
</em> by default fails the whole patch and
549 does not touch the working tree when some of the hunks
550 do not apply. This option makes it apply
551 the parts of the patch that are applicable, and leave the
552 rejected hunks in corresponding *.rej files.
560 When
<tt>--numstat
</tt> has been given, do not munge pathnames,
561 but use a NUL-terminated machine-readable format.
563 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
564 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
565 respectively, and the pathname will be enclosed in double quotes if
566 any of those replacements occurred.</p></div>
573 Remove <n> leading slashes from traditional diff paths. The
582 Ensure at least <n> lines of surrounding context match before
583 and after each change. When fewer lines of surrounding
584 context exist they all must match. By default no context is
593 By default, <em>git apply</em> expects that the patch being
594 applied is a unified diff with at least one line of context.
595 This provides good safety measures, but breaks down when
596 applying a diff generated with <tt>--unified=0</tt>. To bypass these
597 checks use <tt>--unidiff-zero</tt>.
599 <div class="paragraph
"><p>Note, for the reasons stated above usage of context-free patches is
600 discouraged.</p></div>
607 If you use any of the options marked "Turns off
608 <em>apply
</em>" above, <em>git apply</em> reads and outputs the
609 requested information without actually applying the
610 patch. Give this flag after those flags to also apply
619 When applying a patch, ignore additions made by the
620 patch. This can be used to extract the common part between
621 two files by first running <em>diff</em> on them and applying
622 the result with this option, which would apply the
623 deletion part but not the addition part.
627 --allow-binary-replacement
634 Historically we did not allow binary patch applied
635 without an explicit permission from the user, and this
636 flag was the way to do so. Currently we always allow binary
637 patch application, so this is a no-op.
641 --exclude=<path-pattern>
645 Don’t apply changes to files matching the given path pattern. This can
646 be useful when importing patchsets, where you want to exclude certain
647 files or directories.
651 --include=<path-pattern>
655 Apply changes to files matching the given path pattern. This can
656 be useful when importing patchsets, where you want to include certain
657 files or directories.
659 <div class="paragraph
"><p>When <tt>--exclude</tt> and <tt>--include</tt> patterns are used, they are examined in the
660 order they appear on the command line, and the first match determines if a
661 patch to each path is used. A patch to a path that does not match any
662 include/exclude pattern is used by default if there is no include pattern
663 on the command line, and ignored if there is any include pattern.</p></div>
666 --ignore-space-change
673 When applying a patch, ignore changes in whitespace in context
675 Context lines will preserve their whitespace, and they will not
676 undergo whitespace fixing regardless of the value of the
677 <tt>--whitespace</tt> option. New lines will still be fixed, though.
681 --whitespace=<action>
685 When applying a patch, detect a new or modified line that has
686 whitespace errors. What are considered whitespace errors is
687 controlled by <tt>core.whitespace</tt> configuration. By default,
688 trailing whitespaces (including lines that solely consist of
689 whitespaces) and a space character that is immediately followed
690 by a tab character inside the initial indent of the line are
691 considered whitespace errors.
693 <div class="paragraph
"><p>By default, the command outputs warning messages but applies the patch.
694 When <tt>git-apply</tt> is used for statistics and not applying a
695 patch, it defaults to <tt>nowarn</tt>.</p></div>
696 <div class="paragraph
"><p>You can use different <tt><action></tt> values to control this
698 <div class="ulist
"><ul>
701 <tt>nowarn</tt> turns off the trailing whitespace warning.
706 <tt>warn</tt> outputs warnings for a few such errors, but applies the
707 patch as-is (default).
712 <tt>fix</tt> outputs warnings for a few such errors, and applies the
713 patch after fixing them (<tt>strip</tt> is a synonym --- the tool
714 used to consider only trailing whitespace characters as errors, and the
715 fix involved <em>stripping</em> them, but modern gits do more).
720 <tt>error</tt> outputs warnings for a few such errors, and refuses
726 <tt>error-all</tt> is similar to <tt>error</tt> but shows all errors.
736 Under certain circumstances, some versions of <em>diff</em> do not correctly
737 detect a missing new-line at the end of the file. As a result, patches
738 created by such <em>diff</em> programs do not record incomplete lines
739 correctly. This option adds support for applying such patches by
740 working around this bug.
751 Report progress to stderr. By default, only a message about the
752 current patch being applied will be printed. This option will cause
753 additional information to be reported.
761 Do not trust the line counts in the hunk headers, but infer them
762 by inspecting the patch (e.g. after editing the patch without
763 adjusting the hunk headers appropriately).
767 --directory=<root>
771 Prepend <root> to all filenames. If a "-p
" argument was also passed,
772 it is applied before prepending the new root.
774 <div class="paragraph
"><p>For example, a patch that talks about updating <tt>a/git-gui.sh</tt> to <tt>b/git-gui.sh</tt>
775 can be applied to the file in the working tree <tt>modules/git-gui/git-gui.sh</tt> by
776 running <tt>git apply --directory=modules/git-gui</tt>.</p></div>
780 <h2 id="_configuration
">Configuration</h2>
781 <div class="sectionbody
">
782 <div class="dlist
"><dl>
784 apply.ignorewhitespace
788 Set to <em>change</em> if you want changes in whitespace to be ignored by default.
789 Set to one of: no, none, never, false if you want changes in
790 whitespace to be significant.
798 When no <tt>--whitespace</tt> flag is given from the command
799 line, this configuration item is used as the default.
804 <h2 id="_submodules
">Submodules</h2>
805 <div class="sectionbody
">
806 <div class="paragraph
"><p>If the patch contains any changes to submodules then <em>git apply</em>
807 treats these changes as follows.</p></div>
808 <div class="paragraph
"><p>If <tt>--index</tt> is specified (explicitly or implicitly), then the submodule
809 commits must match the index exactly for the patch to apply. If any
810 of the submodules are checked-out, then these check-outs are completely
811 ignored, i.e., they are not required to be up-to-date or clean and they
812 are not updated.</p></div>
813 <div class="paragraph
"><p>If <tt>--index</tt> is not specified, then the submodule commits in the patch
814 are ignored and only the absence or presence of the corresponding
815 subdirectory is checked and (if possible) updated.</p></div>
817 <h2 id="_see_also
">SEE ALSO</h2>
818 <div class="sectionbody
">
819 <div class="paragraph
"><p><a href="git-am.html
">git-am(1)</a>.</p></div>
821 <h2 id="_git
">GIT</h2>
822 <div class="sectionbody
">
823 <div class="paragraph
"><p>Part of the <a href="git.html
">git(1)</a> suite</p></div>
826 <div id="footer-text
">
827 Last updated 2011-03-15 23:30:13 UTC