Autogenerated HTML docs for v1.7.4.1-176-g501cc
[git/jnareb-git.git] / git-apply.html
blob1be859cdfde70ab1c85b5af9c73af0762ddceb5d
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">
4 <head>
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">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.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 {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
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 {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
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;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 git-apply(1) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>git-apply -
411 Apply a patch to files and/or to the index
412 </p>
413 </div>
414 </div>
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=&lt;file&gt;] [-R | --reverse]
420 [--allow-binary-replacement | --binary] [--reject] [-z]
421 [-p&lt;n&gt;] [-C&lt;n&gt;] [--inaccurate-eof] [--recount] [--cached]
422 [--ignore-space-change | --ignore-whitespace ]
423 [--whitespace=(nowarn|warn|fix|error|error-all)]
424 [--exclude=&lt;path&gt;] [--include=&lt;path&gt;] [--directory=&lt;root&gt;]
425 [--verbose] [&lt;patch&gt;&#8230;]</div>
426 <div class="verseblock-attribution">
427 </div></div>
428 </div>
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>--cache</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>
439 </div>
440 <h2 id="_options">OPTIONS</h2>
441 <div class="sectionbody">
442 <div class="dlist"><dl>
443 <dt class="hdlist1">
444 &lt;patch&gt;&#8230;
445 </dt>
446 <dd>
448 The files to read the patch from. <em>-</em> can be used to read
449 from the standard input.
450 </p>
451 </dd>
452 <dt class="hdlist1">
453 --stat
454 </dt>
455 <dd>
457 Instead of applying the patch, output diffstat for the
458 input. Turns off "apply".
459 </p>
460 </dd>
461 <dt class="hdlist1">
462 --numstat
463 </dt>
464 <dd>
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".
471 </p>
472 </dd>
473 <dt class="hdlist1">
474 --summary
475 </dt>
476 <dd>
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.
481 Turns off "apply".
482 </p>
483 </dd>
484 <dt class="hdlist1">
485 --check
486 </dt>
487 <dd>
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".
492 </p>
493 </dd>
494 <dt class="hdlist1">
495 --index
496 </dt>
497 <dd>
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.
506 </p>
507 </dd>
508 <dt class="hdlist1">
509 --cached
510 </dt>
511 <dd>
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>.
516 </p>
517 </dd>
518 <dt class="hdlist1">
519 --build-fake-ancestor=&lt;file&gt;
520 </dt>
521 <dd>
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.
528 </p>
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>
531 </dd>
532 <dt class="hdlist1">
534 </dt>
535 <dt class="hdlist1">
536 --reverse
537 </dt>
538 <dd>
540 Apply the patch in reverse.
541 </p>
542 </dd>
543 <dt class="hdlist1">
544 --reject
545 </dt>
546 <dd>
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.
553 </p>
554 </dd>
555 <dt class="hdlist1">
557 </dt>
558 <dd>
560 When <tt>--numstat</tt> has been given, do not munge pathnames,
561 but use a NUL-terminated machine-readable format.
562 </p>
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>
567 </dd>
568 <dt class="hdlist1">
569 -p&lt;n&gt;
570 </dt>
571 <dd>
573 Remove &lt;n&gt; leading slashes from traditional diff paths. The
574 default is 1.
575 </p>
576 </dd>
577 <dt class="hdlist1">
578 -C&lt;n&gt;
579 </dt>
580 <dd>
582 Ensure at least &lt;n&gt; 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
585 ever ignored.
586 </p>
587 </dd>
588 <dt class="hdlist1">
589 --unidiff-zero
590 </dt>
591 <dd>
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>.
598 </p>
599 <div class="paragraph"><p>Note, for the reasons stated above usage of context-free patches is
600 discouraged.</p></div>
601 </dd>
602 <dt class="hdlist1">
603 --apply
604 </dt>
605 <dd>
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
611 the patch.
612 </p>
613 </dd>
614 <dt class="hdlist1">
615 --no-add
616 </dt>
617 <dd>
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.
624 </p>
625 </dd>
626 <dt class="hdlist1">
627 --allow-binary-replacement
628 </dt>
629 <dt class="hdlist1">
630 --binary
631 </dt>
632 <dd>
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.
638 </p>
639 </dd>
640 <dt class="hdlist1">
641 --exclude=&lt;path-pattern&gt;
642 </dt>
643 <dd>
645 Don&#8217;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.
648 </p>
649 </dd>
650 <dt class="hdlist1">
651 --include=&lt;path-pattern&gt;
652 </dt>
653 <dd>
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.
658 </p>
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>
664 </dd>
665 <dt class="hdlist1">
666 --ignore-space-change
667 </dt>
668 <dt class="hdlist1">
669 --ignore-whitespace
670 </dt>
671 <dd>
673 When applying a patch, ignore changes in whitespace in context
674 lines if necessary.
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.
678 </p>
679 </dd>
680 <dt class="hdlist1">
681 --whitespace=&lt;action&gt;
682 </dt>
683 <dd>
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.
692 </p>
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>&lt;action&gt;</tt> values to control this
697 behavior:</p></div>
698 <div class="ulist"><ul>
699 <li>
701 <tt>nowarn</tt> turns off the trailing whitespace warning.
702 </p>
703 </li>
704 <li>
706 <tt>warn</tt> outputs warnings for a few such errors, but applies the
707 patch as-is (default).
708 </p>
709 </li>
710 <li>
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).
716 </p>
717 </li>
718 <li>
720 <tt>error</tt> outputs warnings for a few such errors, and refuses
721 to apply the patch.
722 </p>
723 </li>
724 <li>
726 <tt>error-all</tt> is similar to <tt>error</tt> but shows all errors.
727 </p>
728 </li>
729 </ul></div>
730 </dd>
731 <dt class="hdlist1">
732 --inaccurate-eof
733 </dt>
734 <dd>
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.
741 </p>
742 </dd>
743 <dt class="hdlist1">
745 </dt>
746 <dt class="hdlist1">
747 --verbose
748 </dt>
749 <dd>
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.
754 </p>
755 </dd>
756 <dt class="hdlist1">
757 --recount
758 </dt>
759 <dd>
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).
764 </p>
765 </dd>
766 <dt class="hdlist1">
767 --directory=&lt;root&gt;
768 </dt>
769 <dd>
771 Prepend &lt;root&gt; to all filenames. If a "-p" argument was also passed,
772 it is applied before prepending the new root.
773 </p>
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>
777 </dd>
778 </dl></div>
779 </div>
780 <h2 id="_configuration">Configuration</h2>
781 <div class="sectionbody">
782 <div class="dlist"><dl>
783 <dt class="hdlist1">
784 apply.ignorewhitespace
785 </dt>
786 <dd>
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.
791 </p>
792 </dd>
793 <dt class="hdlist1">
794 apply.whitespace
795 </dt>
796 <dd>
798 When no <tt>--whitespace</tt> flag is given from the command
799 line, this configuration item is used as the default.
800 </p>
801 </dd>
802 </dl></div>
803 </div>
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>
816 </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>
820 </div>
821 <h2 id="_author">Author</h2>
822 <div class="sectionbody">
823 <div class="paragraph"><p>Written by Linus Torvalds &lt;<a href="mailto:torvalds@osdl.org">torvalds@osdl.org</a>&gt;</p></div>
824 </div>
825 <h2 id="_documentation">Documentation</h2>
826 <div class="sectionbody">
827 <div class="paragraph"><p>Documentation by Junio C Hamano</p></div>
828 </div>
829 <h2 id="_git">GIT</h2>
830 <div class="sectionbody">
831 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
832 </div>
833 <div id="footer">
834 <div id="footer-text">
835 Last updated 2010-11-06 00:41:57 UTC
836 </div>
837 </div>
838 </body>
839 </html>