blob: 7cfa3d92ac8dc7a90068311c0047c667f98515a8 [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 Hamano1a4e8412005-12-27 08:17:2312
13DESCRIPTION
14-----------
Junio C Hamano89a57342010-06-22 23:22:5515
16Given one or more existing commits, apply the change each one
17introduces, recording a new commit for each. This requires your
18working tree to be clean (no modifications from the HEAD commit).
Junio C Hamano1a4e8412005-12-27 08:17:2319
Junio C Hamanoa8cc1d82011-03-10 01:18:1220When it is not obvious how to apply a change, the following
21happens:
22
231. The current branch and `HEAD` pointer stay at the last commit
24 successfully made.
252. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
26 introduced the change that is difficult to apply.
273. Paths in which the change applied cleanly are updated both
28 in the index file and in your working tree.
294. For conflicting paths, the index file records up to three
30 versions, as described in the "TRUE MERGE" section of
31 linkgit:git-merge[1]. The working tree files will include
32 a description of the conflict bracketed by the usual
33 conflict markers `<<<<<<<` and `>>>>>>>`.
345. No other modifications are made.
35
36See linkgit:git-merge[1] for some hints on resolving such
37conflicts.
38
Junio C Hamano1a4e8412005-12-27 08:17:2339OPTIONS
40-------
Junio C Hamano89a57342010-06-22 23:22:5541<commit>...::
42Commits to cherry-pick.
Junio C Hamano78e3a782010-07-15 22:24:4543For a more complete list of ways to spell commits, see
Junio C Hamanoc27b7332010-10-14 04:37:2844linkgit:gitrevisions[7].
Junio C Hamano89a57342010-06-22 23:22:5545Sets of commits can be passed but no traversal is done by
46default, as if the '--no-walk' option was specified, see
47linkgit:git-rev-list[1].
Junio C Hamano1a4e8412005-12-27 08:17:2348
Junio C Hamanoeb415992008-06-08 22:49:4749-e::
50--edit::
Junio C Hamano1aa40d22010-01-21 17:46:4351With this option, 'git cherry-pick' will let you edit the commit
Junio C Hamano0e661132008-01-21 02:37:4452message prior to committing.
Junio C Hamano1a4e8412005-12-27 08:17:2353
Junio C Hamanoaf2b8c52006-10-06 01:00:4054-x::
Junio C Hamanob77f8192011-05-05 01:30:3855When recording the commit, append a line that says
56"(cherry picked from commit ...)" to the original commit
57message in order to indicate which commit this change was
58cherry-picked from. This is done only for cherry
Junio C Hamano764a6672007-10-23 01:23:3159picks without conflicts. Do not use this option if
60you are cherry-picking from your private branch because
61the information is useless to the recipient. If on the
Junio C Hamanoaf2b8c52006-10-06 01:00:4062other hand you are cherry-picking between two publicly
63visible branches (e.g. backporting a fix to a
64maintenance branch for an older release from a
65development branch), adding this information can be
66useful.
67
Junio C Hamano81c711d2007-04-20 07:20:1468-r::
Junio C Hamanoaf2b8c52006-10-06 01:00:4069It used to be that the command defaulted to do `-x`
70described above, and `-r` was to disable it. Now the
71default is not to do `-x` so this option is a no-op.
Junio C Hamano1a4e8412005-12-27 08:17:2372
Junio C Hamanoeb415992008-06-08 22:49:4773-m parent-number::
74--mainline parent-number::
Junio C Hamano69a98582008-03-01 18:42:1875Usually you cannot cherry-pick a merge because you do not know which
Junio C Hamanod814b6d2007-11-04 11:13:4976side of the merge should be considered the mainline. This
77option specifies the parent number (starting from 1) of
78the mainline and allows cherry-pick to replay the change
79relative to the specified parent.
80
Junio C Hamanoeb415992008-06-08 22:49:4781-n::
82--no-commit::
Junio C Hamano89a57342010-06-22 23:22:5583Usually the command automatically creates a sequence of commits.
84This flag applies the changes necessary to cherry-pick
85each named commit to your working tree and the index,
86without making any commit. In addition, when this
Junio C Hamano8dae8cd2008-11-24 05:38:5587option is used, your index does not have to match the
88HEAD commit. The cherry-pick is done against the
Junio C Hamanof69a0a02008-07-17 08:08:4789beginning state of your index.
Junio C Hamano1a4e8412005-12-27 08:17:2390+
91This is useful when cherry-picking more than one commits'
Junio C Hamanof69a0a02008-07-17 08:08:4792effect to your index in a row.
Junio C Hamano1a4e8412005-12-27 08:17:2393
Junio C Hamanoeb415992008-06-08 22:49:4794-s::
95--signoff::
Junio C Hamano6d76d612008-05-09 05:46:0896Add Signed-off-by line at the end of the commit message.
97
Junio C Hamano961e0522010-03-29 07:49:2098--ff::
99If the current HEAD is the same as the parent of the
100cherry-pick'ed commit, then a fast forward to this commit will
101be performed.
Junio C Hamano1a4e8412005-12-27 08:17:23102
Junio C Hamano23e3f532011-02-10 02:05:29103--strategy=<strategy>::
104Use the given merge strategy. Should only be used once.
105See the MERGE STRATEGIES section in linkgit:git-merge[1]
106for details.
107
108-X<option>::
109--strategy-option=<option>::
110Pass the merge strategy-specific option through to the
111merge strategy. See linkgit:git-merge[1] for details.
112
Junio C Hamano89a57342010-06-22 23:22:55113EXAMPLES
114--------
Junio C Hamano16ebcd02011-08-05 00:05:45115`git cherry-pick master`::
Junio C Hamano89a57342010-06-22 23:22:55116
117Apply the change introduced by the commit at the tip of the
118master branch and create a new commit with this change.
119
Junio C Hamano16ebcd02011-08-05 00:05:45120`git cherry-pick ..master`::
121`git cherry-pick ^HEAD master`::
Junio C Hamano89a57342010-06-22 23:22:55122
123Apply the changes introduced by all commits that are ancestors
124of master but not of HEAD to produce new commits.
125
Junio C Hamano16ebcd02011-08-05 00:05:45126`git cherry-pick master{tilde}4 master{tilde}2`::
Junio C Hamano89a57342010-06-22 23:22:55127
128Apply the changes introduced by the fifth and third last
129commits pointed to by master and create 2 new commits with
130these changes.
131
Junio C Hamano16ebcd02011-08-05 00:05:45132`git cherry-pick -n master~1 next`::
Junio C Hamano89a57342010-06-22 23:22:55133
134Apply to the working tree and the index the changes introduced
135by the second last commit pointed to by master and by the last
136commit pointed to by next, but do not create any commit with
137these changes.
138
Junio C Hamano16ebcd02011-08-05 00:05:45139`git cherry-pick --ff ..next`::
Junio C Hamano89a57342010-06-22 23:22:55140
141If history is linear and HEAD is an ancestor of next, update
142the working tree and advance the HEAD pointer to match next.
143Otherwise, apply the changes introduced by those commits that
144are in next but not HEAD to the current branch, creating a new
145commit for each new change.
146
Junio C Hamano16ebcd02011-08-05 00:05:45147`git rev-list --reverse master \-- README | git cherry-pick -n --stdin`::
Junio C Hamano7d449522010-07-01 00:08:51148
149Apply the changes introduced by all commits on the master
150branch that touched README to the working tree and index,
151so the result can be inspected and made into a single new
152commit if suitable.
153
Junio C Hamano23e3f532011-02-10 02:05:29154The following sequence attempts to backport a patch, bails out because
155the code the patch applies to has changed too much, and then tries
156again, this time exercising more care about matching up context lines.
157
158------------
159$ git cherry-pick topic^ <1>
160$ git diff <2>
161$ git reset --merge ORIG_HEAD <3>
162$ git cherry-pick -Xpatience topic^ <4>
163------------
164<1> apply the change that would be shown by `git show topic^`.
165In this example, the patch does not apply cleanly, so
166information about the conflict is written to the index and
167working tree and no new commit results.
168<2> summarize changes to be reconciled
169<3> cancel the cherry-pick. In other words, return to the
170pre-cherry-pick state, preserving any local modifications you had in
171the working tree.
172<4> try to apply the change introduced by `topic^` again,
173spending extra time to avoid mistakes based on incorrectly matching
174context lines.
175
Junio C Hamano89a57342010-06-22 23:22:55176SEE ALSO
177--------
178linkgit:git-revert[1]
179
Junio C Hamano1a4e8412005-12-27 08:17:23180GIT
181---
Junio C Hamanof7c042d2008-06-06 22:50:53182Part of the linkgit:git[1] suite