updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-cherry-pick.xml
blobee43c3605b6fa36f79a0a33497071d742358af71
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-cherry-pick(1)">\r
5 <articleinfo>\r
6     <title>git-cherry-pick(1)</title>\r
7 <indexterm>\r
8 <primary>git-cherry-pick(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-cherry-pick - Apply the changes introduced by some existing commits</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git cherry-pick</emphasis> [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] &lt;commit&gt;&#8230;\r
19 <emphasis>git cherry-pick</emphasis> --continue\r
20 <emphasis>git cherry-pick</emphasis> --quit\r
21 <emphasis>git cherry-pick</emphasis> --abort</literallayout>\r
22 </blockquote>\r
23 </simplesect>\r
24 <simplesect id="_description">\r
25 <title>DESCRIPTION</title>\r
26 <simpara>Given one or more existing commits, apply the change each one\r
27 introduces, recording a new commit for each.  This requires your\r
28 working tree to be clean (no modifications from the HEAD commit).</simpara>\r
29 <simpara>When it is not obvious how to apply a change, the following\r
30 happens:</simpara>\r
31 <orderedlist numeration="arabic">\r
32 <listitem>\r
33 <simpara>\r
34 The current branch and <emphasis>HEAD</emphasis> pointer stay at the last commit\r
35    successfully made.\r
36 </simpara>\r
37 </listitem>\r
38 <listitem>\r
39 <simpara>\r
40 The <emphasis>CHERRY_PICK_HEAD</emphasis> ref is set to point at the commit that\r
41    introduced the change that is difficult to apply.\r
42 </simpara>\r
43 </listitem>\r
44 <listitem>\r
45 <simpara>\r
46 Paths in which the change applied cleanly are updated both\r
47    in the index file and in your working tree.\r
48 </simpara>\r
49 </listitem>\r
50 <listitem>\r
51 <simpara>\r
52 For conflicting paths, the index file records up to three\r
53    versions, as described in the "TRUE MERGE" section of\r
54    <xref linkend="git-merge(1)" />.  The working tree files will include\r
55    a description of the conflict bracketed by the usual\r
56    conflict markers <emphasis>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</emphasis> and <emphasis>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</emphasis>.\r
57 </simpara>\r
58 </listitem>\r
59 <listitem>\r
60 <simpara>\r
61 No other modifications are made.\r
62 </simpara>\r
63 </listitem>\r
64 </orderedlist>\r
65 <simpara>See <xref linkend="git-merge(1)" /> for some hints on resolving such\r
66 conflicts.</simpara>\r
67 </simplesect>\r
68 <simplesect id="_options">\r
69 <title>OPTIONS</title>\r
70 <variablelist>\r
71 <varlistentry>\r
72 <term>\r
73 &lt;commit&gt;&#8230;\r
74 </term>\r
75 <listitem>\r
76 <simpara>\r
77         Commits to cherry-pick.\r
78         For a more complete list of ways to spell commits, see\r
79         <xref linkend="gitrevisions(7)" />.\r
80         Sets of commits can be passed but no traversal is done by\r
81         default, as if the <emphasis>--no-walk</emphasis> option was specified, see\r
82         <xref linkend="git-rev-list(1)" />.\r
83 </simpara>\r
84 </listitem>\r
85 </varlistentry>\r
86 <varlistentry>\r
87 <term>\r
88 -e\r
89 </term>\r
90 <term>\r
91 --edit\r
92 </term>\r
93 <listitem>\r
94 <simpara>\r
95         With this option, <emphasis>git cherry-pick</emphasis> will let you edit the commit\r
96         message prior to committing.\r
97 </simpara>\r
98 </listitem>\r
99 </varlistentry>\r
100 <varlistentry>\r
101 <term>\r
102 -x\r
103 </term>\r
104 <listitem>\r
105 <simpara>\r
106         When recording the commit, append a line that says\r
107         "(cherry picked from commit &#8230;)" to the original commit\r
108         message in order to indicate which commit this change was\r
109         cherry-picked from.  This is done only for cherry\r
110         picks without conflicts.  Do not use this option if\r
111         you are cherry-picking from your private branch because\r
112         the information is useless to the recipient.  If on the\r
113         other hand you are cherry-picking between two publicly\r
114         visible branches (e.g. backporting a fix to a\r
115         maintenance branch for an older release from a\r
116         development branch), adding this information can be\r
117         useful.\r
118 </simpara>\r
119 </listitem>\r
120 </varlistentry>\r
121 <varlistentry>\r
122 <term>\r
123 -r\r
124 </term>\r
125 <listitem>\r
126 <simpara>\r
127         It used to be that the command defaulted to do <emphasis>-x</emphasis>\r
128         described above, and <emphasis>-r</emphasis> was to disable it.  Now the\r
129         default is not to do <emphasis>-x</emphasis> so this option is a no-op.\r
130 </simpara>\r
131 </listitem>\r
132 </varlistentry>\r
133 <varlistentry>\r
134 <term>\r
135 -m parent-number\r
136 </term>\r
137 <term>\r
138 --mainline parent-number\r
139 </term>\r
140 <listitem>\r
141 <simpara>\r
142         Usually you cannot cherry-pick a merge because you do not know which\r
143         side of the merge should be considered the mainline.  This\r
144         option specifies the parent number (starting from 1) of\r
145         the mainline and allows cherry-pick to replay the change\r
146         relative to the specified parent.\r
147 </simpara>\r
148 </listitem>\r
149 </varlistentry>\r
150 <varlistentry>\r
151 <term>\r
152 -n\r
153 </term>\r
154 <term>\r
155 --no-commit\r
156 </term>\r
157 <listitem>\r
158 <simpara>\r
159         Usually the command automatically creates a sequence of commits.\r
160         This flag applies the changes necessary to cherry-pick\r
161         each named commit to your working tree and the index,\r
162         without making any commit.  In addition, when this\r
163         option is used, your index does not have to match the\r
164         HEAD commit.  The cherry-pick is done against the\r
165         beginning state of your index.\r
166 </simpara>\r
167 <simpara>This is useful when cherry-picking more than one commits'\r
168 effect to your index in a row.</simpara>\r
169 </listitem>\r
170 </varlistentry>\r
171 <varlistentry>\r
172 <term>\r
173 -s\r
174 </term>\r
175 <term>\r
176 --signoff\r
177 </term>\r
178 <listitem>\r
179 <simpara>\r
180         Add Signed-off-by line at the end of the commit message.\r
181 </simpara>\r
182 </listitem>\r
183 </varlistentry>\r
184 <varlistentry>\r
185 <term>\r
186 --ff\r
187 </term>\r
188 <listitem>\r
189 <simpara>\r
190         If the current HEAD is the same as the parent of the\r
191         cherry-pick'ed commit, then a fast forward to this commit will\r
192         be performed.\r
193 </simpara>\r
194 </listitem>\r
195 </varlistentry>\r
196 <varlistentry>\r
197 <term>\r
198 --strategy=&lt;strategy&gt;\r
199 </term>\r
200 <listitem>\r
201 <simpara>\r
202         Use the given merge strategy.  Should only be used once.\r
203         See the MERGE STRATEGIES section in <xref linkend="git-merge(1)" />\r
204         for details.\r
205 </simpara>\r
206 </listitem>\r
207 </varlistentry>\r
208 <varlistentry>\r
209 <term>\r
210 -X&lt;option&gt;\r
211 </term>\r
212 <term>\r
213 --strategy-option=&lt;option&gt;\r
214 </term>\r
215 <listitem>\r
216 <simpara>\r
217         Pass the merge strategy-specific option through to the\r
218         merge strategy.  See <xref linkend="git-merge(1)" /> for details.\r
219 </simpara>\r
220 </listitem>\r
221 </varlistentry>\r
222 </variablelist>\r
223 </simplesect>\r
224 <simplesect id="_sequencer_subcommands">\r
225 <title>SEQUENCER SUBCOMMANDS</title>\r
226 <variablelist>\r
227 <varlistentry>\r
228 <term>\r
229 --continue\r
230 </term>\r
231 <listitem>\r
232 <simpara>\r
233         Continue the operation in progress using the information in\r
234         <emphasis>.git/sequencer</emphasis>.  Can be used to continue after resolving\r
235         conflicts in a failed cherry-pick or revert.\r
236 </simpara>\r
237 </listitem>\r
238 </varlistentry>\r
239 <varlistentry>\r
240 <term>\r
241 --quit\r
242 </term>\r
243 <listitem>\r
244 <simpara>\r
245         Forget about the current operation in progress.  Can be used\r
246         to clear the sequencer state after a failed cherry-pick or\r
247         revert.\r
248 </simpara>\r
249 </listitem>\r
250 </varlistentry>\r
251 <varlistentry>\r
252 <term>\r
253 --abort\r
254 </term>\r
255 <listitem>\r
256 <simpara>\r
257         Cancel the operation and return to the pre-sequence state.\r
258 </simpara>\r
259 </listitem>\r
260 </varlistentry>\r
261 </variablelist>\r
262 </simplesect>\r
263 <simplesect id="_examples">\r
264 <title>EXAMPLES</title>\r
265 <variablelist>\r
266 <varlistentry>\r
267 <term>\r
268 <emphasis>git cherry-pick master</emphasis>\r
269 </term>\r
270 <listitem>\r
271 <simpara>\r
272         Apply the change introduced by the commit at the tip of the\r
273         master branch and create a new commit with this change.\r
274 </simpara>\r
275 </listitem>\r
276 </varlistentry>\r
277 <varlistentry>\r
278 <term>\r
279 <emphasis>git cherry-pick ..master</emphasis>\r
280 </term>\r
281 <term>\r
282 <emphasis>git cherry-pick ^HEAD master</emphasis>\r
283 </term>\r
284 <listitem>\r
285 <simpara>\r
286         Apply the changes introduced by all commits that are ancestors\r
287         of master but not of HEAD to produce new commits.\r
288 </simpara>\r
289 </listitem>\r
290 </varlistentry>\r
291 <varlistentry>\r
292 <term>\r
293 <emphasis>git cherry-pick master~4 master~2</emphasis>\r
294 </term>\r
295 <listitem>\r
296 <simpara>\r
297         Apply the changes introduced by the fifth and third last\r
298         commits pointed to by master and create 2 new commits with\r
299         these changes.\r
300 </simpara>\r
301 </listitem>\r
302 </varlistentry>\r
303 <varlistentry>\r
304 <term>\r
305 <emphasis>git cherry-pick -n master~1 next</emphasis>\r
306 </term>\r
307 <listitem>\r
308 <simpara>\r
309         Apply to the working tree and the index the changes introduced\r
310         by the second last commit pointed to by master and by the last\r
311         commit pointed to by next, but do not create any commit with\r
312         these changes.\r
313 </simpara>\r
314 </listitem>\r
315 </varlistentry>\r
316 <varlistentry>\r
317 <term>\r
318 <emphasis>git cherry-pick --ff ..next</emphasis>\r
319 </term>\r
320 <listitem>\r
321 <simpara>\r
322         If history is linear and HEAD is an ancestor of next, update\r
323         the working tree and advance the HEAD pointer to match next.\r
324         Otherwise, apply the changes introduced by those commits that\r
325         are in next but not HEAD to the current branch, creating a new\r
326         commit for each new change.\r
327 </simpara>\r
328 </listitem>\r
329 </varlistentry>\r
330 <varlistentry>\r
331 <term>\r
332 <emphasis>git rev-list --reverse master -- README | git cherry-pick -n --stdin</emphasis>\r
333 </term>\r
334 <listitem>\r
335 <simpara>\r
336         Apply the changes introduced by all commits on the master\r
337         branch that touched README to the working tree and index,\r
338         so the result can be inspected and made into a single new\r
339         commit if suitable.\r
340 </simpara>\r
341 </listitem>\r
342 </varlistentry>\r
343 </variablelist>\r
344 <simpara>The following sequence attempts to backport a patch, bails out because\r
345 the code the patch applies to has changed too much, and then tries\r
346 again, this time exercising more care about matching up context lines.</simpara>\r
347 <screen>$ git cherry-pick topic^             <co id="CO1-1"/>\r
348 $ git diff                           <co id="CO1-2"/>\r
349 $ git reset --merge ORIG_HEAD        <co id="CO1-3"/>\r
350 $ git cherry-pick -Xpatience topic^  <co id="CO1-4"/></screen>\r
351 <calloutlist>\r
352 <callout arearefs="CO1-1">\r
353 <para>\r
354 apply the change that would be shown by <emphasis>git show topic^</emphasis>.\r
355 In this example, the patch does not apply cleanly, so\r
356 information about the conflict is written to the index and\r
357 working tree and no new commit results.\r
358 </para>\r
359 </callout>\r
360 <callout arearefs="CO1-2">\r
361 <para>\r
362 summarize changes to be reconciled\r
363 </para>\r
364 </callout>\r
365 <callout arearefs="CO1-3">\r
366 <para>\r
367 cancel the cherry-pick.  In other words, return to the\r
368 pre-cherry-pick state, preserving any local modifications you had in\r
369 the working tree.\r
370 </para>\r
371 </callout>\r
372 <callout arearefs="CO1-4">\r
373 <para>\r
374 try to apply the change introduced by <emphasis>topic^</emphasis> again,\r
375 spending extra time to avoid mistakes based on incorrectly matching\r
376 context lines.\r
377 </para>\r
378 </callout>\r
379 </calloutlist>\r
380 </simplesect>\r
381 <simplesect id="_see_also">\r
382 <title>SEE ALSO</title>\r
383 <simpara><xref linkend="git-revert(1)" /></simpara>\r
384 </simplesect>\r
385 <simplesect id="_git">\r
386 <title>GIT</title>\r
387 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
388 </simplesect>\r
389 </article>\r