blob: f1e6b2fd6d15809f5180fe705c3d571bf247ff1d [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]
12 [-S[<keyid>]] <commit>...
Junio C Hamano8fb66e52011-10-05 20:59:5113'git cherry-pick' --continue
Junio C Hamanof0944d02011-11-30 20:46:2914'git cherry-pick' --quit
15'git cherry-pick' --abort
Junio C Hamano1a4e8412005-12-27 08:17:2316
17DESCRIPTION
18-----------
Junio C Hamano89a57342010-06-22 23:22:5519
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 Hamano1a4e8412005-12-27 08:17:2323
Junio C Hamanoa8cc1d82011-03-10 01:18:1224When 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 Hamano1a4e8412005-12-27 08:17:2343OPTIONS
44-------
Junio C Hamano89a57342010-06-22 23:22:5545<commit>...::
46Commits to cherry-pick.
Junio C Hamano78e3a782010-07-15 22:24:4547For a more complete list of ways to spell commits, see
Junio C Hamanoc27b7332010-10-14 04:37:2848linkgit:gitrevisions[7].
Junio C Hamano89a57342010-06-22 23:22:5549Sets of commits can be passed but no traversal is done by
50default, as if the '--no-walk' option was specified, see
Junio C Hamano9257a332012-06-25 20:01:0251linkgit:git-rev-list[1]. Note that specifying a range will
52feed all <commit>... arguments to a single revision walk
53(see a later example that uses 'maint master..next').
Junio C Hamano1a4e8412005-12-27 08:17:2354
Junio C Hamanoeb415992008-06-08 22:49:4755-e::
56--edit::
Junio C Hamano1aa40d22010-01-21 17:46:4357With this option, 'git cherry-pick' will let you edit the commit
Junio C Hamano0e661132008-01-21 02:37:4458message prior to committing.
Junio C Hamano1a4e8412005-12-27 08:17:2359
Junio C Hamanoaf2b8c52006-10-06 01:00:4060-x::
Junio C Hamanob77f8192011-05-05 01:30:3861When recording the commit, append a line that says
62"(cherry picked from commit ...)" to the original commit
63message in order to indicate which commit this change was
64cherry-picked from. This is done only for cherry
Junio C Hamano764a6672007-10-23 01:23:3165picks without conflicts. Do not use this option if
66you are cherry-picking from your private branch because
67the information is useless to the recipient. If on the
Junio C Hamanoaf2b8c52006-10-06 01:00:4068other hand you are cherry-picking between two publicly
69visible branches (e.g. backporting a fix to a
70maintenance branch for an older release from a
71development branch), adding this information can be
72useful.
73
Junio C Hamano81c711d2007-04-20 07:20:1474-r::
Junio C Hamanoaf2b8c52006-10-06 01:00:4075It used to be that the command defaulted to do `-x`
76described above, and `-r` was to disable it. Now the
77default is not to do `-x` so this option is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:2378
Junio C Hamanoeb415992008-06-08 22:49:4779-m parent-number::
80--mainline parent-number::
Junio C Hamano69a98582008-03-01 18:42:1881Usually you cannot cherry-pick a merge because you do not know which
Junio C Hamanod814b6d2007-11-04 11:13:4982side of the merge should be considered the mainline. This
83option specifies the parent number (starting from 1) of
84the mainline and allows cherry-pick to replay the change
85relative to the specified parent.
86
Junio C Hamanoeb415992008-06-08 22:49:4787-n::
88--no-commit::
Junio C Hamano89a57342010-06-22 23:22:5589Usually the command automatically creates a sequence of commits.
90This flag applies the changes necessary to cherry-pick
91each named commit to your working tree and the index,
92without making any commit. In addition, when this
Junio C Hamano8dae8cd2008-11-24 05:38:5593option is used, your index does not have to match the
94HEAD commit. The cherry-pick is done against the
Junio C Hamanof69a0a02008-07-17 08:08:4795beginning state of your index.
Junio C Hamano1a4e8412005-12-27 08:17:2396+
97This is useful when cherry-picking more than one commits'
Junio C Hamanof69a0a02008-07-17 08:08:4798effect to your index in a row.
Junio C Hamano1a4e8412005-12-27 08:17:2399
Junio C Hamanoeb415992008-06-08 22:49:47100-s::
101--signoff::
Junio C Hamano6d76d612008-05-09 05:46:08102Add Signed-off-by line at the end of the commit message.
103
Junio C Hamano5b3533d2014-02-27 23:07:15104-S[<keyid>]::
105--gpg-sign[=<keyid>]::
106GPG-sign commits.
107
Junio C Hamano961e0522010-03-29 07:49:20108--ff::
109If the current HEAD is the same as the parent of the
110cherry-pick'ed commit, then a fast forward to this commit will
111be performed.
Junio C Hamano1a4e8412005-12-27 08:17:23112
Junio C Hamano37e389e2012-04-30 22:36:09113--allow-empty::
114By default, cherry-picking an empty commit will fail,
115indicating that an explicit invocation of `git commit
116--allow-empty` is required. This option overrides that
117behavior, allowing empty commits to be preserved automatically
118in a cherry-pick. Note that when "--ff" is in effect, empty
119commits that meet the "fast-forward" requirement will be kept
120even without this option. Note also, that use of this option only
121keeps commits that were initially empty (i.e. the commit recorded the
122same tree as its parent). Commits which are made empty due to a
123previous commit are dropped. To force the inclusion of those commits
124use `--keep-redundant-commits`.
125
Junio C Hamanof3353932012-09-04 23:16:51126--allow-empty-message::
127By default, cherry-picking a commit with an empty message will fail.
128This option overrides that behaviour, allowing commits with empty
129messages to be cherry picked.
130
Junio C Hamano37e389e2012-04-30 22:36:09131--keep-redundant-commits::
132If a commit being cherry picked duplicates a commit already in the
133current history, it will become empty. By default these
134redundant commits are ignored. This option overrides that behavior and
135creates an empty commit object. Implies `--allow-empty`.
136
Junio C Hamano23e3f532011-02-10 02:05:29137--strategy=<strategy>::
138Use the given merge strategy. Should only be used once.
139See the MERGE STRATEGIES section in linkgit:git-merge[1]
140for details.
141
142-X<option>::
143--strategy-option=<option>::
144Pass the merge strategy-specific option through to the
145merge strategy. See linkgit:git-merge[1] for details.
146
Junio C Hamano8fb66e52011-10-05 20:59:51147SEQUENCER SUBCOMMANDS
148---------------------
149include::sequencer.txt[]
150
Junio C Hamano89a57342010-06-22 23:22:55151EXAMPLES
152--------
Junio C Hamano16ebcd02011-08-05 00:05:45153`git cherry-pick master`::
Junio C Hamano89a57342010-06-22 23:22:55154
155Apply the change introduced by the commit at the tip of the
156master branch and create a new commit with this change.
157
Junio C Hamano16ebcd02011-08-05 00:05:45158`git cherry-pick ..master`::
159`git cherry-pick ^HEAD master`::
Junio C Hamano89a57342010-06-22 23:22:55160
161Apply the changes introduced by all commits that are ancestors
162of master but not of HEAD to produce new commits.
163
Junio C Hamano9257a332012-06-25 20:01:02164`git cherry-pick maint next ^master`::
165`git cherry-pick maint master..next`::
166
167Apply the changes introduced by all commits that are
168ancestors of maint or next, but not master or any of its
169ancestors. Note that the latter does not mean `maint` and
170everything between `master` and `next`; specifically,
171`maint` will not be used if it is included in `master`.
172
Junio C Hamanob76a6862012-05-02 22:02:46173`git cherry-pick master~4 master~2`::
Junio C Hamano89a57342010-06-22 23:22:55174
175Apply the changes introduced by the fifth and third last
176commits pointed to by master and create 2 new commits with
177these changes.
178
Junio C Hamano16ebcd02011-08-05 00:05:45179`git cherry-pick -n master~1 next`::
Junio C Hamano89a57342010-06-22 23:22:55180
181Apply to the working tree and the index the changes introduced
182by the second last commit pointed to by master and by the last
183commit pointed to by next, but do not create any commit with
184these changes.
185
Junio C Hamano16ebcd02011-08-05 00:05:45186`git cherry-pick --ff ..next`::
Junio C Hamano89a57342010-06-22 23:22:55187
188If history is linear and HEAD is an ancestor of next, update
189the working tree and advance the HEAD pointer to match next.
190Otherwise, apply the changes introduced by those commits that
191are in next but not HEAD to the current branch, creating a new
192commit for each new change.
193
Junio C Hamanob76a6862012-05-02 22:02:46194`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
Junio C Hamano7d449522010-07-01 00:08:51195
196Apply the changes introduced by all commits on the master
197branch that touched README to the working tree and index,
198so the result can be inspected and made into a single new
199commit if suitable.
200
Junio C Hamano23e3f532011-02-10 02:05:29201The following sequence attempts to backport a patch, bails out because
202the code the patch applies to has changed too much, and then tries
203again, this time exercising more care about matching up context lines.
204
205------------
206$ git cherry-pick topic^ <1>
207$ git diff <2>
208$ git reset --merge ORIG_HEAD <3>
209$ git cherry-pick -Xpatience topic^ <4>
210------------
211<1> apply the change that would be shown by `git show topic^`.
212In this example, the patch does not apply cleanly, so
213information about the conflict is written to the index and
214working tree and no new commit results.
215<2> summarize changes to be reconciled
216<3> cancel the cherry-pick. In other words, return to the
217pre-cherry-pick state, preserving any local modifications you had in
218the working tree.
219<4> try to apply the change introduced by `topic^` again,
220spending extra time to avoid mistakes based on incorrectly matching
221context lines.
222
Junio C Hamano89a57342010-06-22 23:22:55223SEE ALSO
224--------
225linkgit:git-revert[1]
226
Junio C Hamano1a4e8412005-12-27 08:17:23227GIT
228---
Junio C Hamanof7c042d2008-06-06 22:50:53229Part of the linkgit:git[1] suite