blob: 5d750314b299cc7157034b9bffd6a5aa3afe51d4 [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 Hamano5b3533d2014-02-27 23:07:1511'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
Junio C Hamano1eb56092015-10-05 20:39:5312 [-S[<keyid>]] <commit>...
Junio C Hamanoa42e0332019-07-19 19:49:3713'git cherry-pick' (--continue | --skip | --abort | --quit)
Junio C Hamano1a4e8412005-12-27 08:17:2314
15DESCRIPTION
16-----------
Junio C Hamano89a57342010-06-22 23:22:5517
18Given one or more existing commits, apply the change each one
19introduces, recording a new commit for each. This requires your
20working tree to be clean (no modifications from the HEAD commit).
Junio C Hamano1a4e8412005-12-27 08:17:2321
Junio C Hamanoa8cc1d82011-03-10 01:18:1222When it is not obvious how to apply a change, the following
23happens:
24
251. The current branch and `HEAD` pointer stay at the last commit
26 successfully made.
272. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
28 introduced the change that is difficult to apply.
293. Paths in which the change applied cleanly are updated both
30 in the index file and in your working tree.
314. For conflicting paths, the index file records up to three
32 versions, as described in the "TRUE MERGE" section of
33 linkgit:git-merge[1]. The working tree files will include
34 a description of the conflict bracketed by the usual
35 conflict markers `<<<<<<<` and `>>>>>>>`.
365. No other modifications are made.
37
38See linkgit:git-merge[1] for some hints on resolving such
39conflicts.
40
Junio C Hamano1a4e8412005-12-27 08:17:2341OPTIONS
42-------
Junio C Hamano89a57342010-06-22 23:22:5543<commit>...::
44Commits to cherry-pick.
Junio C Hamano78e3a782010-07-15 22:24:4545For a more complete list of ways to spell commits, see
Junio C Hamanoc27b7332010-10-14 04:37:2846linkgit:gitrevisions[7].
Junio C Hamano89a57342010-06-22 23:22:5547Sets of commits can be passed but no traversal is done by
Junio C Hamano92d80372016-07-13 22:00:0548default, as if the `--no-walk` option was specified, see
Junio C Hamano9257a332012-06-25 20:01:0249linkgit:git-rev-list[1]. Note that specifying a range will
50feed all <commit>... arguments to a single revision walk
51(see a later example that uses 'maint master..next').
Junio C Hamano1a4e8412005-12-27 08:17:2352
Junio C Hamanoeb415992008-06-08 22:49:4753-e::
54--edit::
Junio C Hamano1aa40d22010-01-21 17:46:4355With this option, 'git cherry-pick' will let you edit the commit
Junio C Hamano0e661132008-01-21 02:37:4456message prior to committing.
Junio C Hamano1a4e8412005-12-27 08:17:2357
Junio C Hamanod1063b12019-05-08 17:18:0758--cleanup=<mode>::
59This option determines how the commit message will be cleaned up before
60being passed on to the commit machinery. See linkgit:git-commit[1] for more
61details. In particular, if the '<mode>' is given a value of `scissors`,
62scissors will be appended to `MERGE_MSG` before being passed on in the case
63of a conflict.
64
Junio C Hamanoaf2b8c52006-10-06 01:00:4065-x::
Junio C Hamanob77f8192011-05-05 01:30:3866When recording the commit, append a line that says
67"(cherry picked from commit ...)" to the original commit
68message in order to indicate which commit this change was
69cherry-picked from. This is done only for cherry
Junio C Hamano764a6672007-10-23 01:23:3170picks without conflicts. Do not use this option if
71you are cherry-picking from your private branch because
72the information is useless to the recipient. If on the
Junio C Hamanoaf2b8c52006-10-06 01:00:4073other hand you are cherry-picking between two publicly
74visible branches (e.g. backporting a fix to a
75maintenance branch for an older release from a
76development branch), adding this information can be
77useful.
78
Junio C Hamano81c711d2007-04-20 07:20:1479-r::
Junio C Hamanoaf2b8c52006-10-06 01:00:4080It used to be that the command defaulted to do `-x`
81described above, and `-r` was to disable it. Now the
82default is not to do `-x` so this option is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:2383
Junio C Hamanoeb415992008-06-08 22:49:4784-m parent-number::
85--mainline parent-number::
Junio C Hamano69a98582008-03-01 18:42:1886Usually you cannot cherry-pick a merge because you do not know which
Junio C Hamanod814b6d2007-11-04 11:13:4987side of the merge should be considered the mainline. This
88option specifies the parent number (starting from 1) of
89the mainline and allows cherry-pick to replay the change
90relative to the specified parent.
91
Junio C Hamanoeb415992008-06-08 22:49:4792-n::
93--no-commit::
Junio C Hamano89a57342010-06-22 23:22:5594Usually the command automatically creates a sequence of commits.
95This flag applies the changes necessary to cherry-pick
96each named commit to your working tree and the index,
97without making any commit. In addition, when this
Junio C Hamano8dae8cd2008-11-24 05:38:5598option is used, your index does not have to match the
99HEAD commit. The cherry-pick is done against the
Junio C Hamanof69a0a02008-07-17 08:08:47100beginning state of your index.
Junio C Hamano1a4e8412005-12-27 08:17:23101+
102This is useful when cherry-picking more than one commits'
Junio C Hamanof69a0a02008-07-17 08:08:47103effect to your index in a row.
Junio C Hamano1a4e8412005-12-27 08:17:23104
Junio C Hamanoeb415992008-06-08 22:49:47105-s::
106--signoff::
Junio C Hamanodf3d3cd2020-11-02 22:05:05107Add a `Signed-off-by` trailer at the end of the commit message.
Junio C Hamano4e6ba272016-01-20 23:23:19108See the signoff option in linkgit:git-commit[1] for more information.
Junio C Hamano6d76d612008-05-09 05:46:08109
Junio C Hamano1eb56092015-10-05 20:39:53110-S[<keyid>]::
111--gpg-sign[=<keyid>]::
Junio C Hamano67bf2242020-04-22 21:41:44112--no-gpg-sign::
Junio C Hamano1eb56092015-10-05 20:39:53113GPG-sign commits. The `keyid` argument is optional and
114defaults to the committer identity; if specified, it must be
Junio C Hamano67bf2242020-04-22 21:41:44115stuck to the option without a space. `--no-gpg-sign` is useful to
116countermand both `commit.gpgSign` configuration variable, and
117earlier `--gpg-sign`.
Junio C Hamano5b3533d2014-02-27 23:07:15118
Junio C Hamano961e0522010-03-29 07:49:20119--ff::
120If the current HEAD is the same as the parent of the
121cherry-pick'ed commit, then a fast forward to this commit will
122be performed.
Junio C Hamano1a4e8412005-12-27 08:17:23123
Junio C Hamano37e389e2012-04-30 22:36:09124--allow-empty::
125By default, cherry-picking an empty commit will fail,
126indicating that an explicit invocation of `git commit
127--allow-empty` is required. This option overrides that
128behavior, allowing empty commits to be preserved automatically
129in a cherry-pick. Note that when "--ff" is in effect, empty
130commits that meet the "fast-forward" requirement will be kept
131even without this option. Note also, that use of this option only
132keeps commits that were initially empty (i.e. the commit recorded the
133same tree as its parent). Commits which are made empty due to a
134previous commit are dropped. To force the inclusion of those commits
135use `--keep-redundant-commits`.
136
Junio C Hamanof3353932012-09-04 23:16:51137--allow-empty-message::
138By default, cherry-picking a commit with an empty message will fail.
Junio C Hamano5213c3b2016-06-03 23:34:40139This option overrides that behavior, allowing commits with empty
Junio C Hamanof3353932012-09-04 23:16:51140messages to be cherry picked.
141
Junio C Hamano37e389e2012-04-30 22:36:09142--keep-redundant-commits::
143If a commit being cherry picked duplicates a commit already in the
144current history, it will become empty. By default these
Junio C Hamanoe35ff422015-04-14 21:45:21145redundant commits cause `cherry-pick` to stop so the user can
146examine the commit. This option overrides that behavior and
Junio C Hamano37e389e2012-04-30 22:36:09147creates an empty commit object. Implies `--allow-empty`.
148
Junio C Hamano23e3f532011-02-10 02:05:29149--strategy=<strategy>::
150Use the given merge strategy. Should only be used once.
151See the MERGE STRATEGIES section in linkgit:git-merge[1]
152for details.
153
154-X<option>::
155--strategy-option=<option>::
156Pass the merge strategy-specific option through to the
157merge strategy. See linkgit:git-merge[1] for details.
158
Junio C Hamano6b7d2152019-04-16 12:51:15159--rerere-autoupdate::
160--no-rerere-autoupdate::
161Allow the rerere mechanism to update the index with the
162result of auto-conflict resolution if possible.
163
Junio C Hamano8fb66e52011-10-05 20:59:51164SEQUENCER SUBCOMMANDS
165---------------------
166include::sequencer.txt[]
167
Junio C Hamano89a57342010-06-22 23:22:55168EXAMPLES
169--------
Junio C Hamano16ebcd02011-08-05 00:05:45170`git cherry-pick master`::
Junio C Hamano89a57342010-06-22 23:22:55171
172Apply the change introduced by the commit at the tip of the
173master branch and create a new commit with this change.
174
Junio C Hamano16ebcd02011-08-05 00:05:45175`git cherry-pick ..master`::
176`git cherry-pick ^HEAD master`::
Junio C Hamano89a57342010-06-22 23:22:55177
178Apply the changes introduced by all commits that are ancestors
179of master but not of HEAD to produce new commits.
180
Junio C Hamano9257a332012-06-25 20:01:02181`git cherry-pick maint next ^master`::
182`git cherry-pick maint master..next`::
183
184Apply the changes introduced by all commits that are
185ancestors of maint or next, but not master or any of its
186ancestors. Note that the latter does not mean `maint` and
187everything between `master` and `next`; specifically,
188`maint` will not be used if it is included in `master`.
189
Junio C Hamanob76a6862012-05-02 22:02:46190`git cherry-pick master~4 master~2`::
Junio C Hamano89a57342010-06-22 23:22:55191
192Apply the changes introduced by the fifth and third last
193commits pointed to by master and create 2 new commits with
194these changes.
195
Junio C Hamano16ebcd02011-08-05 00:05:45196`git cherry-pick -n master~1 next`::
Junio C Hamano89a57342010-06-22 23:22:55197
198Apply to the working tree and the index the changes introduced
199by the second last commit pointed to by master and by the last
200commit pointed to by next, but do not create any commit with
201these changes.
202
Junio C Hamano16ebcd02011-08-05 00:05:45203`git cherry-pick --ff ..next`::
Junio C Hamano89a57342010-06-22 23:22:55204
205If history is linear and HEAD is an ancestor of next, update
206the working tree and advance the HEAD pointer to match next.
207Otherwise, apply the changes introduced by those commits that
208are in next but not HEAD to the current branch, creating a new
209commit for each new change.
210
Junio C Hamanob76a6862012-05-02 22:02:46211`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
Junio C Hamano7d449522010-07-01 00:08:51212
213Apply the changes introduced by all commits on the master
214branch that touched README to the working tree and index,
215so the result can be inspected and made into a single new
216commit if suitable.
217
Junio C Hamano23e3f532011-02-10 02:05:29218The following sequence attempts to backport a patch, bails out because
219the code the patch applies to has changed too much, and then tries
220again, this time exercising more care about matching up context lines.
221
222------------
223$ git cherry-pick topic^ <1>
224$ git diff <2>
225$ git reset --merge ORIG_HEAD <3>
226$ git cherry-pick -Xpatience topic^ <4>
227------------
228<1> apply the change that would be shown by `git show topic^`.
Junio C Hamano2567b322019-02-05 23:33:56229 In this example, the patch does not apply cleanly, so
230 information about the conflict is written to the index and
231 working tree and no new commit results.
Junio C Hamano23e3f532011-02-10 02:05:29232<2> summarize changes to be reconciled
233<3> cancel the cherry-pick. In other words, return to the
Junio C Hamano2567b322019-02-05 23:33:56234 pre-cherry-pick state, preserving any local modifications
235 you had in the working tree.
Junio C Hamano23e3f532011-02-10 02:05:29236<4> try to apply the change introduced by `topic^` again,
Junio C Hamano2567b322019-02-05 23:33:56237 spending extra time to avoid mistakes based on incorrectly
238 matching context lines.
Junio C Hamano23e3f532011-02-10 02:05:29239
Junio C Hamano89a57342010-06-22 23:22:55240SEE ALSO
241--------
242linkgit:git-revert[1]
243
Junio C Hamano1a4e8412005-12-27 08:17:23244GIT
245---
Junio C Hamanof7c042d2008-06-06 22:50:53246Part of the linkgit:git[1] suite