Update Git docs to 2.29.2
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-cherry-pick.xml
blob1d352806a3f21d52de305d5a6b59a71f67e94bff
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">\r
3 \r
4 <sect2 lang="en" id="git-cherry-pick(1)">\r
5     <title>git-cherry-pick(1)</title>\r
6 <indexterm>\r
7 <primary>git-cherry-pick(1)</primary>\r
8 </indexterm>\r
9 <simplesect id="git-cherry-pick(1)__name">\r
10 <title>NAME</title>\r
11 <simpara>git-cherry-pick - Apply the changes introduced by some existing commits</simpara>\r
12 </simplesect>\r
13 <simplesect id="git-cherry-pick(1)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <blockquote>\r
16 <literallayout><emphasis>git cherry-pick</emphasis> [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]\r
17                   [-S[&lt;keyid&gt;]] &lt;commit&gt;&#8230;\r
18 <emphasis>git cherry-pick</emphasis> (--continue | --skip | --abort | --quit)</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="git-cherry-pick(1)__description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Given one or more existing commits, apply the change each one\r
24 introduces, recording a new commit for each.  This requires your\r
25 working tree to be clean (no modifications from the HEAD commit).</simpara>\r
26 <simpara>When it is not obvious how to apply a change, the following\r
27 happens:</simpara>\r
28 <orderedlist numeration="arabic">\r
29 <listitem>\r
30 <simpara>\r
31 The current branch and <emphasis>HEAD</emphasis> pointer stay at the last commit\r
32    successfully made.\r
33 </simpara>\r
34 </listitem>\r
35 <listitem>\r
36 <simpara>\r
37 The <emphasis>CHERRY_PICK_HEAD</emphasis> ref is set to point at the commit that\r
38    introduced the change that is difficult to apply.\r
39 </simpara>\r
40 </listitem>\r
41 <listitem>\r
42 <simpara>\r
43 Paths in which the change applied cleanly are updated both\r
44    in the index file and in your working tree.\r
45 </simpara>\r
46 </listitem>\r
47 <listitem>\r
48 <simpara>\r
49 For conflicting paths, the index file records up to three\r
50    versions, as described in the "TRUE MERGE" section of\r
51    <xref linkend="git-merge(1)" />.  The working tree files will include\r
52    a description of the conflict bracketed by the usual\r
53    conflict markers <emphasis>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</emphasis> and <emphasis>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</emphasis>.\r
54 </simpara>\r
55 </listitem>\r
56 <listitem>\r
57 <simpara>\r
58 No other modifications are made.\r
59 </simpara>\r
60 </listitem>\r
61 </orderedlist>\r
62 <simpara>See <xref linkend="git-merge(1)" /> for some hints on resolving such\r
63 conflicts.</simpara>\r
64 </simplesect>\r
65 <simplesect id="git-cherry-pick(1)__options">\r
66 <title>OPTIONS</title>\r
67 <variablelist>\r
68 <varlistentry>\r
69 <term>\r
70 &lt;commit&gt;&#8230;\r
71 </term>\r
72 <listitem>\r
73 <simpara>\r
74         Commits to cherry-pick.\r
75         For a more complete list of ways to spell commits, see\r
76         <xref linkend="gitrevisions(7)" />.\r
77         Sets of commits can be passed but no traversal is done by\r
78         default, as if the <emphasis>--no-walk</emphasis> option was specified, see\r
79         <xref linkend="git-rev-list(1)" />. Note that specifying a range will\r
80         feed all &lt;commit&gt;&#8230; arguments to a single revision walk\r
81         (see a later example that uses <emphasis>maint master..next</emphasis>).\r
82 </simpara>\r
83 </listitem>\r
84 </varlistentry>\r
85 <varlistentry>\r
86 <term>\r
87 -e\r
88 </term>\r
89 <term>\r
90 --edit\r
91 </term>\r
92 <listitem>\r
93 <simpara>\r
94         With this option, <emphasis>git cherry-pick</emphasis> will let you edit the commit\r
95         message prior to committing.\r
96 </simpara>\r
97 </listitem>\r
98 </varlistentry>\r
99 <varlistentry>\r
100 <term>\r
101 --cleanup=&lt;mode&gt;\r
102 </term>\r
103 <listitem>\r
104 <simpara>\r
105         This option determines how the commit message will be cleaned up before\r
106         being passed on to the commit machinery. See <xref linkend="git-commit(1)" /> for more\r
107         details. In particular, if the <emphasis>&lt;mode&gt;</emphasis> is given a value of <emphasis>scissors</emphasis>,\r
108         scissors will be appended to <emphasis>MERGE_MSG</emphasis> before being passed on in the case\r
109         of a conflict.\r
110 </simpara>\r
111 </listitem>\r
112 </varlistentry>\r
113 <varlistentry>\r
114 <term>\r
115 -x\r
116 </term>\r
117 <listitem>\r
118 <simpara>\r
119         When recording the commit, append a line that says\r
120         "(cherry picked from commit &#8230;)" to the original commit\r
121         message in order to indicate which commit this change was\r
122         cherry-picked from.  This is done only for cherry\r
123         picks without conflicts.  Do not use this option if\r
124         you are cherry-picking from your private branch because\r
125         the information is useless to the recipient.  If on the\r
126         other hand you are cherry-picking between two publicly\r
127         visible branches (e.g. backporting a fix to a\r
128         maintenance branch for an older release from a\r
129         development branch), adding this information can be\r
130         useful.\r
131 </simpara>\r
132 </listitem>\r
133 </varlistentry>\r
134 <varlistentry>\r
135 <term>\r
136 -r\r
137 </term>\r
138 <listitem>\r
139 <simpara>\r
140         It used to be that the command defaulted to do <emphasis>-x</emphasis>\r
141         described above, and <emphasis>-r</emphasis> was to disable it.  Now the\r
142         default is not to do <emphasis>-x</emphasis> so this option is a no-op.\r
143 </simpara>\r
144 </listitem>\r
145 </varlistentry>\r
146 <varlistentry>\r
147 <term>\r
148 -m parent-number\r
149 </term>\r
150 <term>\r
151 --mainline parent-number\r
152 </term>\r
153 <listitem>\r
154 <simpara>\r
155         Usually you cannot cherry-pick a merge because you do not know which\r
156         side of the merge should be considered the mainline.  This\r
157         option specifies the parent number (starting from 1) of\r
158         the mainline and allows cherry-pick to replay the change\r
159         relative to the specified parent.\r
160 </simpara>\r
161 </listitem>\r
162 </varlistentry>\r
163 <varlistentry>\r
164 <term>\r
165 -n\r
166 </term>\r
167 <term>\r
168 --no-commit\r
169 </term>\r
170 <listitem>\r
171 <simpara>\r
172         Usually the command automatically creates a sequence of commits.\r
173         This flag applies the changes necessary to cherry-pick\r
174         each named commit to your working tree and the index,\r
175         without making any commit.  In addition, when this\r
176         option is used, your index does not have to match the\r
177         HEAD commit.  The cherry-pick is done against the\r
178         beginning state of your index.\r
179 </simpara>\r
180 <simpara>This is useful when cherry-picking more than one commits'\r
181 effect to your index in a row.</simpara>\r
182 </listitem>\r
183 </varlistentry>\r
184 <varlistentry>\r
185 <term>\r
186 -s\r
187 </term>\r
188 <term>\r
189 --signoff\r
190 </term>\r
191 <listitem>\r
192 <simpara>\r
193         Add Signed-off-by line at the end of the commit message.\r
194         See the signoff option in <xref linkend="git-commit(1)" /> for more information.\r
195 </simpara>\r
196 </listitem>\r
197 </varlistentry>\r
198 <varlistentry>\r
199 <term>\r
200 -S[&lt;keyid&gt;]\r
201 </term>\r
202 <term>\r
203 --gpg-sign[=&lt;keyid&gt;]\r
204 </term>\r
205 <term>\r
206 --no-gpg-sign\r
207 </term>\r
208 <listitem>\r
209 <simpara>\r
210         GPG-sign commits. The <emphasis>keyid</emphasis> argument is optional and\r
211         defaults to the committer identity; if specified, it must be\r
212         stuck to the option without a space. <emphasis>--no-gpg-sign</emphasis> is useful to\r
213         countermand both <emphasis>commit.gpgSign</emphasis> configuration variable, and\r
214         earlier <emphasis>--gpg-sign</emphasis>.\r
215 </simpara>\r
216 </listitem>\r
217 </varlistentry>\r
218 <varlistentry>\r
219 <term>\r
220 --ff\r
221 </term>\r
222 <listitem>\r
223 <simpara>\r
224         If the current HEAD is the same as the parent of the\r
225         cherry-pick'ed commit, then a fast forward to this commit will\r
226         be performed.\r
227 </simpara>\r
228 </listitem>\r
229 </varlistentry>\r
230 <varlistentry>\r
231 <term>\r
232 --allow-empty\r
233 </term>\r
234 <listitem>\r
235 <simpara>\r
236         By default, cherry-picking an empty commit will fail,\r
237         indicating that an explicit invocation of <emphasis>git commit\r
238         --allow-empty</emphasis> is required. This option overrides that\r
239         behavior, allowing empty commits to be preserved automatically\r
240         in a cherry-pick. Note that when "--ff" is in effect, empty\r
241         commits that meet the "fast-forward" requirement will be kept\r
242         even without this option.  Note also, that use of this option only\r
243         keeps commits that were initially empty (i.e. the commit recorded the\r
244         same tree as its parent).  Commits which are made empty due to a\r
245         previous commit are dropped.  To force the inclusion of those commits\r
246         use <emphasis>--keep-redundant-commits</emphasis>.\r
247 </simpara>\r
248 </listitem>\r
249 </varlistentry>\r
250 <varlistentry>\r
251 <term>\r
252 --allow-empty-message\r
253 </term>\r
254 <listitem>\r
255 <simpara>\r
256         By default, cherry-picking a commit with an empty message will fail.\r
257         This option overrides that behavior, allowing commits with empty\r
258         messages to be cherry picked.\r
259 </simpara>\r
260 </listitem>\r
261 </varlistentry>\r
262 <varlistentry>\r
263 <term>\r
264 --keep-redundant-commits\r
265 </term>\r
266 <listitem>\r
267 <simpara>\r
268         If a commit being cherry picked duplicates a commit already in the\r
269         current history, it will become empty.  By default these\r
270         redundant commits cause <emphasis>cherry-pick</emphasis> to stop so the user can\r
271         examine the commit. This option overrides that behavior and\r
272         creates an empty commit object.  Implies <emphasis>--allow-empty</emphasis>.\r
273 </simpara>\r
274 </listitem>\r
275 </varlistentry>\r
276 <varlistentry>\r
277 <term>\r
278 --strategy=&lt;strategy&gt;\r
279 </term>\r
280 <listitem>\r
281 <simpara>\r
282         Use the given merge strategy.  Should only be used once.\r
283         See the MERGE STRATEGIES section in <xref linkend="git-merge(1)" />\r
284         for details.\r
285 </simpara>\r
286 </listitem>\r
287 </varlistentry>\r
288 <varlistentry>\r
289 <term>\r
290 -X&lt;option&gt;\r
291 </term>\r
292 <term>\r
293 --strategy-option=&lt;option&gt;\r
294 </term>\r
295 <listitem>\r
296 <simpara>\r
297         Pass the merge strategy-specific option through to the\r
298         merge strategy.  See <xref linkend="git-merge(1)" /> for details.\r
299 </simpara>\r
300 </listitem>\r
301 </varlistentry>\r
302 <varlistentry>\r
303 <term>\r
304 --rerere-autoupdate\r
305 </term>\r
306 <term>\r
307 --no-rerere-autoupdate\r
308 </term>\r
309 <listitem>\r
310 <simpara>\r
311         Allow the rerere mechanism to update the index with the\r
312         result of auto-conflict resolution if possible.\r
313 </simpara>\r
314 </listitem>\r
315 </varlistentry>\r
316 </variablelist>\r
317 </simplesect>\r
318 <simplesect id="git-cherry-pick(1)__sequencer_subcommands">\r
319 <title>SEQUENCER SUBCOMMANDS</title>\r
320 <variablelist>\r
321 <varlistentry>\r
322 <term>\r
323 --continue\r
324 </term>\r
325 <listitem>\r
326 <simpara>\r
327         Continue the operation in progress using the information in\r
328         <emphasis>.git/sequencer</emphasis>.  Can be used to continue after resolving\r
329         conflicts in a failed cherry-pick or revert.\r
330 </simpara>\r
331 </listitem>\r
332 </varlistentry>\r
333 <varlistentry>\r
334 <term>\r
335 --skip\r
336 </term>\r
337 <listitem>\r
338 <simpara>\r
339         Skip the current commit and continue with the rest of the\r
340         sequence.\r
341 </simpara>\r
342 </listitem>\r
343 </varlistentry>\r
344 <varlistentry>\r
345 <term>\r
346 --quit\r
347 </term>\r
348 <listitem>\r
349 <simpara>\r
350         Forget about the current operation in progress.  Can be used\r
351         to clear the sequencer state after a failed cherry-pick or\r
352         revert.\r
353 </simpara>\r
354 </listitem>\r
355 </varlistentry>\r
356 <varlistentry>\r
357 <term>\r
358 --abort\r
359 </term>\r
360 <listitem>\r
361 <simpara>\r
362         Cancel the operation and return to the pre-sequence state.\r
363 </simpara>\r
364 </listitem>\r
365 </varlistentry>\r
366 </variablelist>\r
367 </simplesect>\r
368 <simplesect id="git-cherry-pick(1)__examples">\r
369 <title>EXAMPLES</title>\r
370 <variablelist>\r
371 <varlistentry>\r
372 <term>\r
373 <emphasis>git cherry-pick master</emphasis>\r
374 </term>\r
375 <listitem>\r
376 <simpara>\r
377         Apply the change introduced by the commit at the tip of the\r
378         master branch and create a new commit with this change.\r
379 </simpara>\r
380 </listitem>\r
381 </varlistentry>\r
382 <varlistentry>\r
383 <term>\r
384 <emphasis>git cherry-pick ..master</emphasis>\r
385 </term>\r
386 <term>\r
387 <emphasis>git cherry-pick ^HEAD master</emphasis>\r
388 </term>\r
389 <listitem>\r
390 <simpara>\r
391         Apply the changes introduced by all commits that are ancestors\r
392         of master but not of HEAD to produce new commits.\r
393 </simpara>\r
394 </listitem>\r
395 </varlistentry>\r
396 <varlistentry>\r
397 <term>\r
398 <emphasis>git cherry-pick maint next ^master</emphasis>\r
399 </term>\r
400 <term>\r
401 <emphasis>git cherry-pick maint master..next</emphasis>\r
402 </term>\r
403 <listitem>\r
404 <simpara>\r
405         Apply the changes introduced by all commits that are\r
406         ancestors of maint or next, but not master or any of its\r
407         ancestors.  Note that the latter does not mean <emphasis>maint</emphasis> and\r
408         everything between <emphasis>master</emphasis> and <emphasis>next</emphasis>; specifically,\r
409         <emphasis>maint</emphasis> will not be used if it is included in <emphasis>master</emphasis>.\r
410 </simpara>\r
411 </listitem>\r
412 </varlistentry>\r
413 <varlistentry>\r
414 <term>\r
415 <emphasis>git cherry-pick master~4 master~2</emphasis>\r
416 </term>\r
417 <listitem>\r
418 <simpara>\r
419         Apply the changes introduced by the fifth and third last\r
420         commits pointed to by master and create 2 new commits with\r
421         these changes.\r
422 </simpara>\r
423 </listitem>\r
424 </varlistentry>\r
425 <varlistentry>\r
426 <term>\r
427 <emphasis>git cherry-pick -n master~1 next</emphasis>\r
428 </term>\r
429 <listitem>\r
430 <simpara>\r
431         Apply to the working tree and the index the changes introduced\r
432         by the second last commit pointed to by master and by the last\r
433         commit pointed to by next, but do not create any commit with\r
434         these changes.\r
435 </simpara>\r
436 </listitem>\r
437 </varlistentry>\r
438 <varlistentry>\r
439 <term>\r
440 <emphasis>git cherry-pick --ff ..next</emphasis>\r
441 </term>\r
442 <listitem>\r
443 <simpara>\r
444         If history is linear and HEAD is an ancestor of next, update\r
445         the working tree and advance the HEAD pointer to match next.\r
446         Otherwise, apply the changes introduced by those commits that\r
447         are in next but not HEAD to the current branch, creating a new\r
448         commit for each new change.\r
449 </simpara>\r
450 </listitem>\r
451 </varlistentry>\r
452 <varlistentry>\r
453 <term>\r
454 <emphasis>git rev-list --reverse master -- README | git cherry-pick -n --stdin</emphasis>\r
455 </term>\r
456 <listitem>\r
457 <simpara>\r
458         Apply the changes introduced by all commits on the master\r
459         branch that touched README to the working tree and index,\r
460         so the result can be inspected and made into a single new\r
461         commit if suitable.\r
462 </simpara>\r
463 </listitem>\r
464 </varlistentry>\r
465 </variablelist>\r
466 <simpara>The following sequence attempts to backport a patch, bails out because\r
467 the code the patch applies to has changed too much, and then tries\r
468 again, this time exercising more care about matching up context lines.</simpara>\r
469 <screen>$ git cherry-pick topic^             <co id="git-cherry-pick_CO1-1"/>\r
470 $ git diff                           <co id="git-cherry-pick_CO1-2"/>\r
471 $ git reset --merge ORIG_HEAD        <co id="git-cherry-pick_CO1-3"/>\r
472 $ git cherry-pick -Xpatience topic^  <co id="git-cherry-pick_CO1-4"/></screen>\r
473 <calloutlist>\r
474 <callout arearefs="git-cherry-pick_CO1-1">\r
475 <para>\r
476 apply the change that would be shown by <emphasis>git show topic^</emphasis>.\r
477     In this example, the patch does not apply cleanly, so\r
478     information about the conflict is written to the index and\r
479     working tree and no new commit results.\r
480 </para>\r
481 </callout>\r
482 <callout arearefs="git-cherry-pick_CO1-2">\r
483 <para>\r
484 summarize changes to be reconciled\r
485 </para>\r
486 </callout>\r
487 <callout arearefs="git-cherry-pick_CO1-3">\r
488 <para>\r
489 cancel the cherry-pick.  In other words, return to the\r
490     pre-cherry-pick state, preserving any local modifications\r
491     you had in the working tree.\r
492 </para>\r
493 </callout>\r
494 <callout arearefs="git-cherry-pick_CO1-4">\r
495 <para>\r
496 try to apply the change introduced by <emphasis>topic^</emphasis> again,\r
497     spending extra time to avoid mistakes based on incorrectly\r
498     matching context lines.\r
499 </para>\r
500 </callout>\r
501 </calloutlist>\r
502 </simplesect>\r
503 <simplesect id="git-cherry-pick(1)__see_also">\r
504 <title>SEE ALSO</title>\r
505 <simpara><xref linkend="git-revert(1)" /></simpara>\r
506 </simplesect>\r
507 <simplesect id="git-cherry-pick(1)__git">\r
508 <title>GIT</title>\r
509 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
510 </simplesect>\r
511 </sect2>\r