blob: c205d2363e426ed6b1a91df2b8d9b4a3c576a5ea [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-cherry-pick(1)
2==================
3
4NAME
5----
Junio C Hamano89a57342010-06-22 23:22:556git-cherry-pick - Apply the changes introduced by some existing commits
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamano89a57342010-06-22 23:22:5511'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
Junio C Hamano8fb66e52011-10-05 20:59:5112'git cherry-pick' --continue
Junio C Hamanof0944d02011-11-30 20:46:2913'git cherry-pick' --quit
14'git cherry-pick' --abort
Junio C Hamano1a4e8412005-12-27 08:17:2315
16DESCRIPTION
17-----------
Junio C Hamano89a57342010-06-22 23:22:5518
19Given one or more existing commits, apply the change each one
20introduces, recording a new commit for each. This requires your
21working tree to be clean (no modifications from the HEAD commit).
Junio C Hamano1a4e8412005-12-27 08:17:2322
Junio C Hamanoa8cc1d82011-03-10 01:18:1223When it is not obvious how to apply a change, the following
24happens:
25
261. The current branch and `HEAD` pointer stay at the last commit
27 successfully made.
282. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
29 introduced the change that is difficult to apply.
303. Paths in which the change applied cleanly are updated both
31 in the index file and in your working tree.
324. For conflicting paths, the index file records up to three
33 versions, as described in the "TRUE MERGE" section of
34 linkgit:git-merge[1]. The working tree files will include
35 a description of the conflict bracketed by the usual
36 conflict markers `<<<<<<<` and `>>>>>>>`.
375. No other modifications are made.
38
39See linkgit:git-merge[1] for some hints on resolving such
40conflicts.
41
Junio C Hamano1a4e8412005-12-27 08:17:2342OPTIONS
43-------
Junio C Hamano89a57342010-06-22 23:22:5544<commit>...::
45Commits to cherry-pick.
Junio C Hamano78e3a782010-07-15 22:24:4546For a more complete list of ways to spell commits, see
Junio C Hamanoc27b7332010-10-14 04:37:2847linkgit:gitrevisions[7].
Junio C Hamano89a57342010-06-22 23:22:5548Sets of commits can be passed but no traversal is done by
49default, as if the '--no-walk' option was specified, see
Junio C Hamano9257a332012-06-25 20:01:0250linkgit:git-rev-list[1]. Note that specifying a range will
51feed all <commit>... arguments to a single revision walk
52(see a later example that uses 'maint master..next').
Junio C Hamano1a4e8412005-12-27 08:17:2353
Junio C Hamanoeb415992008-06-08 22:49:4754-e::
55--edit::
Junio C Hamano1aa40d22010-01-21 17:46:4356With this option, 'git cherry-pick' will let you edit the commit
Junio C Hamano0e661132008-01-21 02:37:4457message prior to committing.
Junio C Hamano1a4e8412005-12-27 08:17:2358
Junio C Hamanoaf2b8c52006-10-06 01:00:4059-x::
Junio C Hamanob77f8192011-05-05 01:30:3860When recording the commit, append a line that says
61"(cherry picked from commit ...)" to the original commit
62message in order to indicate which commit this change was
63cherry-picked from. This is done only for cherry
Junio C Hamano764a6672007-10-23 01:23:3164picks without conflicts. Do not use this option if
65you are cherry-picking from your private branch because
66the information is useless to the recipient. If on the
Junio C Hamanoaf2b8c52006-10-06 01:00:4067other hand you are cherry-picking between two publicly
68visible branches (e.g. backporting a fix to a
69maintenance branch for an older release from a
70development branch), adding this information can be
71useful.
72
Junio C Hamano81c711d2007-04-20 07:20:1473-r::
Junio C Hamanoaf2b8c52006-10-06 01:00:4074It used to be that the command defaulted to do `-x`
75described above, and `-r` was to disable it. Now the
76default is not to do `-x` so this option is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:2377
Junio C Hamanoeb415992008-06-08 22:49:4778-m parent-number::
79--mainline parent-number::
Junio C Hamano69a98582008-03-01 18:42:1880Usually you cannot cherry-pick a merge because you do not know which
Junio C Hamanod814b6d2007-11-04 11:13:4981side of the merge should be considered the mainline. This
82option specifies the parent number (starting from 1) of
83the mainline and allows cherry-pick to replay the change
84relative to the specified parent.
85
Junio C Hamanoeb415992008-06-08 22:49:4786-n::
87--no-commit::
Junio C Hamano89a57342010-06-22 23:22:5588Usually the command automatically creates a sequence of commits.
89This flag applies the changes necessary to cherry-pick
90each named commit to your working tree and the index,
91without making any commit. In addition, when this
Junio C Hamano8dae8cd2008-11-24 05:38:5592option is used, your index does not have to match the
93HEAD commit. The cherry-pick is done against the
Junio C Hamanof69a0a02008-07-17 08:08:4794beginning state of your index.
Junio C Hamano1a4e8412005-12-27 08:17:2395+
96This is useful when cherry-picking more than one commits'
Junio C Hamanof69a0a02008-07-17 08:08:4797effect to your index in a row.
Junio C Hamano1a4e8412005-12-27 08:17:2398
Junio C Hamanoeb415992008-06-08 22:49:4799-s::
100--signoff::
Junio C Hamano6d76d612008-05-09 05:46:08101Add Signed-off-by line at the end of the commit message.
102
Junio C Hamano961e0522010-03-29 07:49:20103--ff::
104If the current HEAD is the same as the parent of the
105cherry-pick'ed commit, then a fast forward to this commit will
106be performed.
Junio C Hamano1a4e8412005-12-27 08:17:23107
Junio C Hamano37e389e2012-04-30 22:36:09108--allow-empty::
109By default, cherry-picking an empty commit will fail,
110indicating that an explicit invocation of `git commit
111--allow-empty` is required. This option overrides that
112behavior, allowing empty commits to be preserved automatically
113in a cherry-pick. Note that when "--ff" is in effect, empty
114commits that meet the "fast-forward" requirement will be kept
115even without this option. Note also, that use of this option only
116keeps commits that were initially empty (i.e. the commit recorded the
117same tree as its parent). Commits which are made empty due to a
118previous commit are dropped. To force the inclusion of those commits
119use `--keep-redundant-commits`.
120
Junio C Hamanof3353932012-09-04 23:16:51121--allow-empty-message::
122By default, cherry-picking a commit with an empty message will fail.
123This option overrides that behaviour, allowing commits with empty
124messages to be cherry picked.
125
Junio C Hamano37e389e2012-04-30 22:36:09126--keep-redundant-commits::
127If a commit being cherry picked duplicates a commit already in the
128current history, it will become empty. By default these
129redundant commits are ignored. This option overrides that behavior and
130creates an empty commit object. Implies `--allow-empty`.
131
Junio C Hamano23e3f532011-02-10 02:05:29132--strategy=<strategy>::
133Use the given merge strategy. Should only be used once.
134See the MERGE STRATEGIES section in linkgit:git-merge[1]
135for details.
136
137-X<option>::
138--strategy-option=<option>::
139Pass the merge strategy-specific option through to the
140merge strategy. See linkgit:git-merge[1] for details.
141
Junio C Hamano8fb66e52011-10-05 20:59:51142SEQUENCER SUBCOMMANDS
143---------------------
144include::sequencer.txt[]
145
Junio C Hamano89a57342010-06-22 23:22:55146EXAMPLES
147--------
Junio C Hamano16ebcd02011-08-05 00:05:45148`git cherry-pick master`::
Junio C Hamano89a57342010-06-22 23:22:55149
150Apply the change introduced by the commit at the tip of the
151master branch and create a new commit with this change.
152
Junio C Hamano16ebcd02011-08-05 00:05:45153`git cherry-pick ..master`::
154`git cherry-pick ^HEAD master`::
Junio C Hamano89a57342010-06-22 23:22:55155
156Apply the changes introduced by all commits that are ancestors
157of master but not of HEAD to produce new commits.
158
Junio C Hamano9257a332012-06-25 20:01:02159`git cherry-pick maint next ^master`::
160`git cherry-pick maint master..next`::
161
162Apply the changes introduced by all commits that are
163ancestors of maint or next, but not master or any of its
164ancestors. Note that the latter does not mean `maint` and
165everything between `master` and `next`; specifically,
166`maint` will not be used if it is included in `master`.
167
Junio C Hamanob76a6862012-05-02 22:02:46168`git cherry-pick master~4 master~2`::
Junio C Hamano89a57342010-06-22 23:22:55169
170Apply the changes introduced by the fifth and third last
171commits pointed to by master and create 2 new commits with
172these changes.
173
Junio C Hamano16ebcd02011-08-05 00:05:45174`git cherry-pick -n master~1 next`::
Junio C Hamano89a57342010-06-22 23:22:55175
176Apply to the working tree and the index the changes introduced
177by the second last commit pointed to by master and by the last
178commit pointed to by next, but do not create any commit with
179these changes.
180
Junio C Hamano16ebcd02011-08-05 00:05:45181`git cherry-pick --ff ..next`::
Junio C Hamano89a57342010-06-22 23:22:55182
183If history is linear and HEAD is an ancestor of next, update
184the working tree and advance the HEAD pointer to match next.
185Otherwise, apply the changes introduced by those commits that
186are in next but not HEAD to the current branch, creating a new
187commit for each new change.
188
Junio C Hamanob76a6862012-05-02 22:02:46189`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
Junio C Hamano7d449522010-07-01 00:08:51190
191Apply the changes introduced by all commits on the master
192branch that touched README to the working tree and index,
193so the result can be inspected and made into a single new
194commit if suitable.
195
Junio C Hamano23e3f532011-02-10 02:05:29196The following sequence attempts to backport a patch, bails out because
197the code the patch applies to has changed too much, and then tries
198again, this time exercising more care about matching up context lines.
199
200------------
201$ git cherry-pick topic^ <1>
202$ git diff <2>
203$ git reset --merge ORIG_HEAD <3>
204$ git cherry-pick -Xpatience topic^ <4>
205------------
206<1> apply the change that would be shown by `git show topic^`.
207In this example, the patch does not apply cleanly, so
208information about the conflict is written to the index and
209working tree and no new commit results.
210<2> summarize changes to be reconciled
211<3> cancel the cherry-pick. In other words, return to the
212pre-cherry-pick state, preserving any local modifications you had in
213the working tree.
214<4> try to apply the change introduced by `topic^` again,
215spending extra time to avoid mistakes based on incorrectly matching
216context lines.
217
Junio C Hamano89a57342010-06-22 23:22:55218SEE ALSO
219--------
220linkgit:git-revert[1]
221
Junio C Hamano1a4e8412005-12-27 08:17:23222GIT
223---
Junio C Hamanof7c042d2008-06-06 22:50:53224Part of the linkgit:git[1] suite