blob: d35d771fc8172e12958b4a9521c51a5f65cddebe [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-cherry-pick(1)
2==================
Junio C Hamanode2b82c2005-08-28 03:01:09 -07003
4NAME
5----
Christian Couder89d32d32010-06-02 07:58:40 +02006git-cherry-pick - Apply the changes introduced by some existing commits
Junio C Hamanode2b82c2005-08-28 03:01:09 -07007
8SYNOPSIS
9--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040010[verse]
Nicolas Vigier32535532014-01-24 00:50:58 +000011'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
Matthieu Moy340f2c52015-09-19 09:47:48 +020012 [-S[<keyid>]] <commit>...
Ramkumar Ramachandra5a5d80f2011-08-04 16:09:15 +053013'git cherry-pick' --continue
Jonathan Niederf80a8722011-11-22 05:14:29 -060014'git cherry-pick' --quit
Jonathan Nieder539047c2011-11-22 19:27:21 -060015'git cherry-pick' --abort
Junio C Hamanode2b82c2005-08-28 03:01:09 -070016
17DESCRIPTION
18-----------
Christian Couder89d32d32010-06-02 07:58:40 +020019
20Given one or more existing commits, apply the change each one
21introduces, recording a new commit for each. This requires your
22working tree to be clean (no modifications from the HEAD commit).
Junio C Hamanode2b82c2005-08-28 03:01:09 -070023
Jay Soffiand7e5c0c2011-02-19 23:12:27 -050024When it is not obvious how to apply a change, the following
25happens:
26
271. The current branch and `HEAD` pointer stay at the last commit
28 successfully made.
292. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
30 introduced the change that is difficult to apply.
313. Paths in which the change applied cleanly are updated both
32 in the index file and in your working tree.
334. For conflicting paths, the index file records up to three
34 versions, as described in the "TRUE MERGE" section of
35 linkgit:git-merge[1]. The working tree files will include
36 a description of the conflict bracketed by the usual
37 conflict markers `<<<<<<<` and `>>>>>>>`.
385. No other modifications are made.
39
40See linkgit:git-merge[1] for some hints on resolving such
41conflicts.
42
Junio C Hamanode2b82c2005-08-28 03:01:09 -070043OPTIONS
44-------
Christian Couder89d32d32010-06-02 07:58:40 +020045<commit>...::
46 Commits to cherry-pick.
Michael J Gruberf028cda2010-07-05 18:11:41 +020047 For a more complete list of ways to spell commits, see
Jonathan Nieder9d83e382010-10-11 11:03:32 -050048 linkgit:gitrevisions[7].
Christian Couder89d32d32010-06-02 07:58:40 +020049 Sets of commits can be passed but no traversal is done by
Matthieu Moybcf96262016-06-28 13:40:11 +020050 default, as if the `--no-walk` option was specified, see
Carlos Martín Nietob98878e2012-06-15 16:33:16 +020051 linkgit:git-rev-list[1]. Note that specifying a range will
52 feed all <commit>... arguments to a single revision walk
53 (see a later example that uses 'maint master..next').
Junio C Hamanode2b82c2005-08-28 03:01:09 -070054
Stephan Beyer32402402008-06-08 03:36:09 +020055-e::
56--edit::
Thomas Rast0b444cd2010-01-10 00:33:00 +010057 With this option, 'git cherry-pick' will let you edit the commit
Jim Meyering233808d2008-01-19 16:23:32 +010058 message prior to committing.
Petr Baudis8bf14d62005-11-26 23:12:44 +010059
Junio C Hamanoabd69702006-10-05 17:54:14 -070060-x::
Sebastian Schuberthbea7d162011-04-15 19:53:51 +020061 When recording the commit, append a line that says
62 "(cherry picked from commit ...)" to the original commit
63 message in order to indicate which commit this change was
64 cherry-picked from. This is done only for cherry
Ralf Wildenhuesdd8175f2007-10-21 11:36:19 +020065 picks without conflicts. Do not use this option if
66 you are cherry-picking from your private branch because
67 the information is useless to the recipient. If on the
Junio C Hamanoabd69702006-10-05 17:54:14 -070068 other hand you are cherry-picking between two publicly
69 visible branches (e.g. backporting a fix to a
70 maintenance branch for an older release from a
71 development branch), adding this information can be
72 useful.
73
Andrew Ruder6b046002007-04-18 22:03:26 -050074-r::
Junio C Hamanoabd69702006-10-05 17:54:14 -070075 It used to be that the command defaulted to do `-x`
76 described above, and `-r` was to disable it. Now the
77 default is not to do `-x` so this option is a no-op.
Junio C Hamanode2b82c2005-08-28 03:01:09 -070078
Stephan Beyer32402402008-06-08 03:36:09 +020079-m parent-number::
80--mainline parent-number::
Mike Ralphson84989bd2008-02-29 17:00:38 +000081 Usually you cannot cherry-pick a merge because you do not know which
Junio C Hamano7791ecb2007-10-23 13:33:26 -070082 side of the merge should be considered the mainline. This
83 option specifies the parent number (starting from 1) of
84 the mainline and allows cherry-pick to replay the change
85 relative to the specified parent.
86
Stephan Beyer32402402008-06-08 03:36:09 +020087-n::
88--no-commit::
Christian Couder89d32d32010-06-02 07:58:40 +020089 Usually the command automatically creates a sequence of commits.
90 This flag applies the changes necessary to cherry-pick
91 each named commit to your working tree and the index,
92 without making any commit. In addition, when this
Bryan Drewery37a77442008-11-19 23:11:42 -060093 option is used, your index does not have to match the
94 HEAD commit. The cherry-pick is done against the
Petr Baudis8bd867e2008-07-16 14:35:22 +020095 beginning state of your index.
Jonas Fonsecadf8baa42005-10-03 19:16:30 +020096+
97This is useful when cherry-picking more than one commits'
Petr Baudis8bd867e2008-07-16 14:35:22 +020098effect to your index in a row.
Junio C Hamanode2b82c2005-08-28 03:01:09 -070099
Stephan Beyer32402402008-06-08 03:36:09 +0200100-s::
101--signoff::
Dan McGeecfd9c272008-04-26 15:14:28 -0500102 Add Signed-off-by line at the end of the commit message.
David A. Wheelerb2c150d2016-01-05 14:20:26 -0500103 See the signoff option in linkgit:git-commit[1] for more information.
Dan McGeecfd9c272008-04-26 15:14:28 -0500104
Matthieu Moy340f2c52015-09-19 09:47:48 +0200105-S[<keyid>]::
106--gpg-sign[=<keyid>]::
Matthieu Moy2b594bf2015-09-19 09:47:50 +0200107 GPG-sign commits. The `keyid` argument is optional and
108 defaults to the committer identity; if specified, it must be
109 stuck to the option without a space.
Nicolas Vigier32535532014-01-24 00:50:58 +0000110
Christian Couderab7e63e2010-03-06 21:34:44 +0100111--ff::
112 If the current HEAD is the same as the parent of the
113 cherry-pick'ed commit, then a fast forward to this commit will
114 be performed.
Junio C Hamanode2b82c2005-08-28 03:01:09 -0700115
Neil Hormandf478b72012-04-11 16:21:53 -0400116--allow-empty::
117 By default, cherry-picking an empty commit will fail,
118 indicating that an explicit invocation of `git commit
119 --allow-empty` is required. This option overrides that
120 behavior, allowing empty commits to be preserved automatically
121 in a cherry-pick. Note that when "--ff" is in effect, empty
122 commits that meet the "fast-forward" requirement will be kept
Neil Hormanb27cfb02012-04-20 10:36:15 -0400123 even without this option. Note also, that use of this option only
124 keeps commits that were initially empty (i.e. the commit recorded the
125 same tree as its parent). Commits which are made empty due to a
126 previous commit are dropped. To force the inclusion of those commits
127 use `--keep-redundant-commits`.
128
Chris Webb4bee9582012-08-02 11:38:51 +0100129--allow-empty-message::
130 By default, cherry-picking a commit with an empty message will fail.
Pablo Santiago Blum de Aguiarcd82b7a2016-05-29 16:29:29 -0300131 This option overrides that behavior, allowing commits with empty
Chris Webb4bee9582012-08-02 11:38:51 +0100132 messages to be cherry picked.
133
Neil Hormanb27cfb02012-04-20 10:36:15 -0400134--keep-redundant-commits::
135 If a commit being cherry picked duplicates a commit already in the
136 current history, it will become empty. By default these
Jeff Kingf9072822015-03-30 21:08:54 -0400137 redundant commits cause `cherry-pick` to stop so the user can
138 examine the commit. This option overrides that behavior and
Neil Hormanb27cfb02012-04-20 10:36:15 -0400139 creates an empty commit object. Implies `--allow-empty`.
Neil Hormandf478b72012-04-11 16:21:53 -0400140
Jonathan Nieder67ac1e12010-12-10 18:51:44 -0600141--strategy=<strategy>::
142 Use the given merge strategy. Should only be used once.
143 See the MERGE STRATEGIES section in linkgit:git-merge[1]
144 for details.
145
146-X<option>::
147--strategy-option=<option>::
148 Pass the merge strategy-specific option through to the
149 merge strategy. See linkgit:git-merge[1] for details.
150
Ramkumar Ramachandra26ae3372011-08-04 16:09:11 +0530151SEQUENCER SUBCOMMANDS
152---------------------
153include::sequencer.txt[]
154
Christian Couder89d32d32010-06-02 07:58:40 +0200155EXAMPLES
156--------
Jeff King5d2fc912011-08-03 20:13:29 -0600157`git cherry-pick master`::
Christian Couder89d32d32010-06-02 07:58:40 +0200158
159 Apply the change introduced by the commit at the tip of the
160 master branch and create a new commit with this change.
161
Jeff King5d2fc912011-08-03 20:13:29 -0600162`git cherry-pick ..master`::
163`git cherry-pick ^HEAD master`::
Christian Couder89d32d32010-06-02 07:58:40 +0200164
165 Apply the changes introduced by all commits that are ancestors
166 of master but not of HEAD to produce new commits.
167
Carlos Martín Nietob98878e2012-06-15 16:33:16 +0200168`git cherry-pick maint next ^master`::
169`git cherry-pick maint master..next`::
170
171 Apply the changes introduced by all commits that are
172 ancestors of maint or next, but not master or any of its
173 ancestors. Note that the latter does not mean `maint` and
174 everything between `master` and `next`; specifically,
175 `maint` will not be used if it is included in `master`.
176
Jeff King6cf378f2012-04-26 04:51:57 -0400177`git cherry-pick master~4 master~2`::
Christian Couder89d32d32010-06-02 07:58:40 +0200178
179 Apply the changes introduced by the fifth and third last
180 commits pointed to by master and create 2 new commits with
181 these changes.
182
Jeff King5d2fc912011-08-03 20:13:29 -0600183`git cherry-pick -n master~1 next`::
Christian Couder89d32d32010-06-02 07:58:40 +0200184
185 Apply to the working tree and the index the changes introduced
186 by the second last commit pointed to by master and by the last
187 commit pointed to by next, but do not create any commit with
188 these changes.
189
Jeff King5d2fc912011-08-03 20:13:29 -0600190`git cherry-pick --ff ..next`::
Christian Couder89d32d32010-06-02 07:58:40 +0200191
192 If history is linear and HEAD is an ancestor of next, update
193 the working tree and advance the HEAD pointer to match next.
194 Otherwise, apply the changes introduced by those commits that
195 are in next but not HEAD to the current branch, creating a new
196 commit for each new change.
197
Jeff King6cf378f2012-04-26 04:51:57 -0400198`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
Christian Couderf873a272010-06-14 00:29:38 -0500199
200 Apply the changes introduced by all commits on the master
201 branch that touched README to the working tree and index,
202 so the result can be inspected and made into a single new
203 commit if suitable.
204
Jonathan Nieder67ac1e12010-12-10 18:51:44 -0600205The following sequence attempts to backport a patch, bails out because
206the code the patch applies to has changed too much, and then tries
207again, this time exercising more care about matching up context lines.
208
209------------
210$ git cherry-pick topic^ <1>
211$ git diff <2>
212$ git reset --merge ORIG_HEAD <3>
213$ git cherry-pick -Xpatience topic^ <4>
214------------
215<1> apply the change that would be shown by `git show topic^`.
216In this example, the patch does not apply cleanly, so
217information about the conflict is written to the index and
218working tree and no new commit results.
219<2> summarize changes to be reconciled
220<3> cancel the cherry-pick. In other words, return to the
221pre-cherry-pick state, preserving any local modifications you had in
222the working tree.
223<4> try to apply the change introduced by `topic^` again,
224spending extra time to avoid mistakes based on incorrectly matching
225context lines.
226
Christian Couder89d32d32010-06-02 07:58:40 +0200227SEE ALSO
228--------
229linkgit:git-revert[1]
230
Junio C Hamanode2b82c2005-08-28 03:01:09 -0700231GIT
232---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200233Part of the linkgit:git[1] suite