Updated git_doc to git 1.8
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-apply.xml
blob537f29007aa3a6fb2d6dc37ce631a4bf4a172a28
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
3 \r
4 <sect2 lang="en" id="git-apply(1)">\r
5     <title>git-apply(1)</title>\r
6 <indexterm>\r
7 <primary>git-apply(1)</primary>\r
8 </indexterm>\r
9 <simplesect id="git-apply(1)__name">\r
10 <title>NAME</title>\r
11 <simpara>git-apply - Apply a patch to files and/or to the index</simpara>\r
12 </simplesect>\r
13 <simplesect id="git-apply(1)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <blockquote>\r
16 <literallayout><emphasis>git apply</emphasis> [--stat] [--numstat] [--summary] [--check] [--index] [--3way]\r
17           [--apply] [--no-add] [--build-fake-ancestor=&lt;file&gt;] [-R | --reverse]\r
18           [--allow-binary-replacement | --binary] [--reject] [-z]\r
19           [-p&lt;n&gt;] [-C&lt;n&gt;] [--inaccurate-eof] [--recount] [--cached]\r
20           [--ignore-space-change | --ignore-whitespace ]\r
21           [--whitespace=(nowarn|warn|fix|error|error-all)]\r
22           [--exclude=&lt;path&gt;] [--include=&lt;path&gt;] [--directory=&lt;root&gt;]\r
23           [--verbose] [&lt;patch&gt;&#8230;]</literallayout>\r
24 </blockquote>\r
25 </simplesect>\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
36 </simplesect>\r
37 <simplesect id="git-apply(1)__options">\r
38 <title>OPTIONS</title>\r
39 <variablelist>\r
40 <varlistentry>\r
41 <term>\r
42 &lt;patch&gt;&#8230;\r
43 </term>\r
44 <listitem>\r
45 <simpara>\r
46         The files to read the patch from.  <emphasis>-</emphasis> can be used to read\r
47         from the standard input.\r
48 </simpara>\r
49 </listitem>\r
50 </varlistentry>\r
51 <varlistentry>\r
52 <term>\r
53 --stat\r
54 </term>\r
55 <listitem>\r
56 <simpara>\r
57         Instead of applying the patch, output diffstat for the\r
58         input.  Turns off "apply".\r
59 </simpara>\r
60 </listitem>\r
61 </varlistentry>\r
62 <varlistentry>\r
63 <term>\r
64 --numstat\r
65 </term>\r
66 <listitem>\r
67 <simpara>\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
73 </simpara>\r
74 </listitem>\r
75 </varlistentry>\r
76 <varlistentry>\r
77 <term>\r
78 --summary\r
79 </term>\r
80 <listitem>\r
81 <simpara>\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
85         Turns off "apply".\r
86 </simpara>\r
87 </listitem>\r
88 </varlistentry>\r
89 <varlistentry>\r
90 <term>\r
91 --check\r
92 </term>\r
93 <listitem>\r
94 <simpara>\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
98 </simpara>\r
99 </listitem>\r
100 </varlistentry>\r
101 <varlistentry>\r
102 <term>\r
103 --index\r
104 </term>\r
105 <listitem>\r
106 <simpara>\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
114 </simpara>\r
115 </listitem>\r
116 </varlistentry>\r
117 <varlistentry>\r
118 <term>\r
119 --cached\r
120 </term>\r
121 <listitem>\r
122 <simpara>\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
126 </simpara>\r
127 </listitem>\r
128 </varlistentry>\r
129 <varlistentry>\r
130 <term>\r
131 -3\r
132 </term>\r
133 <term>\r
134 --3way\r
135 </term>\r
136 <listitem>\r
137 <simpara>\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
144 </simpara>\r
145 </listitem>\r
146 </varlistentry>\r
147 <varlistentry>\r
148 <term>\r
149 --build-fake-ancestor=&lt;file&gt;\r
150 </term>\r
151 <listitem>\r
152 <simpara>\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
158 </simpara>\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
161 </listitem>\r
162 </varlistentry>\r
163 <varlistentry>\r
164 <term>\r
165 -R\r
166 </term>\r
167 <term>\r
168 --reverse\r
169 </term>\r
170 <listitem>\r
171 <simpara>\r
172         Apply the patch in reverse.\r
173 </simpara>\r
174 </listitem>\r
175 </varlistentry>\r
176 <varlistentry>\r
177 <term>\r
178 --reject\r
179 </term>\r
180 <listitem>\r
181 <simpara>\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
187 </simpara>\r
188 </listitem>\r
189 </varlistentry>\r
190 <varlistentry>\r
191 <term>\r
192 -z\r
193 </term>\r
194 <listitem>\r
195 <simpara>\r
196         When <emphasis>--numstat</emphasis> has been given, do not munge pathnames,\r
197         but use a NUL-terminated machine-readable format.\r
198 </simpara>\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
203 </listitem>\r
204 </varlistentry>\r
205 <varlistentry>\r
206 <term>\r
207 -p&lt;n&gt;\r
208 </term>\r
209 <listitem>\r
210 <simpara>\r
211         Remove &lt;n&gt; leading slashes from traditional diff paths. The\r
212         default is 1.\r
213 </simpara>\r
214 </listitem>\r
215 </varlistentry>\r
216 <varlistentry>\r
217 <term>\r
218 -C&lt;n&gt;\r
219 </term>\r
220 <listitem>\r
221 <simpara>\r
222         Ensure at least &lt;n&gt; 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
225         ever ignored.\r
226 </simpara>\r
227 </listitem>\r
228 </varlistentry>\r
229 <varlistentry>\r
230 <term>\r
231 --unidiff-zero\r
232 </term>\r
233 <listitem>\r
234 <simpara>\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
240 </simpara>\r
241 <simpara>Note, for the reasons stated above usage of context-free patches is\r
242 discouraged.</simpara>\r
243 </listitem>\r
244 </varlistentry>\r
245 <varlistentry>\r
246 <term>\r
247 --apply\r
248 </term>\r
249 <listitem>\r
250 <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
255         the patch.\r
256 </simpara>\r
257 </listitem>\r
258 </varlistentry>\r
259 <varlistentry>\r
260 <term>\r
261 --no-add\r
262 </term>\r
263 <listitem>\r
264 <simpara>\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
270 </simpara>\r
271 </listitem>\r
272 </varlistentry>\r
273 <varlistentry>\r
274 <term>\r
275 --allow-binary-replacement\r
276 </term>\r
277 <term>\r
278 --binary\r
279 </term>\r
280 <listitem>\r
281 <simpara>\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
286 </simpara>\r
287 </listitem>\r
288 </varlistentry>\r
289 <varlistentry>\r
290 <term>\r
291 --exclude=&lt;path-pattern&gt;\r
292 </term>\r
293 <listitem>\r
294 <simpara>\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
298 </simpara>\r
299 </listitem>\r
300 </varlistentry>\r
301 <varlistentry>\r
302 <term>\r
303 --include=&lt;path-pattern&gt;\r
304 </term>\r
305 <listitem>\r
306 <simpara>\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
310 </simpara>\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
316 </listitem>\r
317 </varlistentry>\r
318 <varlistentry>\r
319 <term>\r
320 --ignore-space-change\r
321 </term>\r
322 <term>\r
323 --ignore-whitespace\r
324 </term>\r
325 <listitem>\r
326 <simpara>\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
332 </simpara>\r
333 </listitem>\r
334 </varlistentry>\r
335 <varlistentry>\r
336 <term>\r
337 --whitespace=&lt;action&gt;\r
338 </term>\r
339 <listitem>\r
340 <simpara>\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
348 </simpara>\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>&lt;action&gt;</emphasis> values to control this\r
353 behavior:</simpara>\r
354 <itemizedlist>\r
355 <listitem>\r
356 <simpara>\r
357 <emphasis>nowarn</emphasis> turns off the trailing whitespace warning.\r
358 </simpara>\r
359 </listitem>\r
360 <listitem>\r
361 <simpara>\r
362 <emphasis>warn</emphasis> outputs warnings for a few such errors, but applies the\r
363   patch as-is (default).\r
364 </simpara>\r
365 </listitem>\r
366 <listitem>\r
367 <simpara>\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
372 </simpara>\r
373 </listitem>\r
374 <listitem>\r
375 <simpara>\r
376 <emphasis>error</emphasis> outputs warnings for a few such errors, and refuses\r
377   to apply the patch.\r
378 </simpara>\r
379 </listitem>\r
380 <listitem>\r
381 <simpara>\r
382 <emphasis>error-all</emphasis> is similar to <emphasis>error</emphasis> but shows all errors.\r
383 </simpara>\r
384 </listitem>\r
385 </itemizedlist>\r
386 </listitem>\r
387 </varlistentry>\r
388 <varlistentry>\r
389 <term>\r
390 --inaccurate-eof\r
391 </term>\r
392 <listitem>\r
393 <simpara>\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
399 </simpara>\r
400 </listitem>\r
401 </varlistentry>\r
402 <varlistentry>\r
403 <term>\r
404 -v\r
405 </term>\r
406 <term>\r
407 --verbose\r
408 </term>\r
409 <listitem>\r
410 <simpara>\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
414 </simpara>\r
415 </listitem>\r
416 </varlistentry>\r
417 <varlistentry>\r
418 <term>\r
419 --recount\r
420 </term>\r
421 <listitem>\r
422 <simpara>\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
426 </simpara>\r
427 </listitem>\r
428 </varlistentry>\r
429 <varlistentry>\r
430 <term>\r
431 --directory=&lt;root&gt;\r
432 </term>\r
433 <listitem>\r
434 <simpara>\r
435         Prepend &lt;root&gt; to all filenames.  If a "-p" argument was also passed,\r
436         it is applied before prepending the new root.\r
437 </simpara>\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
441 </listitem>\r
442 </varlistentry>\r
443 </variablelist>\r
444 </simplesect>\r
445 <simplesect id="git-apply(1)__configuration">\r
446 <title>Configuration</title>\r
447 <variablelist>\r
448 <varlistentry>\r
449 <term>\r
450 apply.ignorewhitespace\r
451 </term>\r
452 <listitem>\r
453 <simpara>\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
457 </simpara>\r
458 </listitem>\r
459 </varlistentry>\r
460 <varlistentry>\r
461 <term>\r
462 apply.whitespace\r
463 </term>\r
464 <listitem>\r
465 <simpara>\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
468 </simpara>\r
469 </listitem>\r
470 </varlistentry>\r
471 </variablelist>\r
472 </simplesect>\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
485 </simplesect>\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
489 </simplesect>\r
490 <simplesect id="git-apply(1)__git">\r
491 <title>GIT</title>\r
492 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
493 </simplesect>\r
494 </sect2>\r