revert: Don't implicitly stomp pending sequencer operation
[git/git.git] / Documentation / git-cherry-pick.txt
CommitLineData
215a7ad1
JH
1git-cherry-pick(1)
2==================
de2b82c6
JH
3
4NAME
5----
89d32d33 6git-cherry-pick - Apply the changes introduced by some existing commits
de2b82c6
JH
7
8SYNOPSIS
9--------
89d32d33 10'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
26ae337b 11'git cherry-pick' --reset
de2b82c6
JH
12
13DESCRIPTION
14-----------
89d32d33
CC
15
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).
de2b82c6 19
d7e5c0cb
JS
20When 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
de2b82c6
JH
39OPTIONS
40-------
89d32d33
CC
41<commit>...::
42 Commits to cherry-pick.
f028cdae 43 For a more complete list of ways to spell commits, see
9d83e382 44 linkgit:gitrevisions[7].
89d32d33
CC
45 Sets of commits can be passed but no traversal is done by
46 default, as if the '--no-walk' option was specified, see
47 linkgit:git-rev-list[1].
de2b82c6 48
3240240f
SB
49-e::
50--edit::
0b444cdb 51 With this option, 'git cherry-pick' will let you edit the commit
233808db 52 message prior to committing.
8bf14d6e 53
abd6970a 54-x::
bea7d16e
SS
55 When recording the commit, append a line that says
56 "(cherry picked from commit ...)" to the original commit
57 message in order to indicate which commit this change was
58 cherry-picked from. This is done only for cherry
dd8175f8
RW
59 picks without conflicts. Do not use this option if
60 you are cherry-picking from your private branch because
61 the information is useless to the recipient. If on the
abd6970a
JH
62 other hand you are cherry-picking between two publicly
63 visible branches (e.g. backporting a fix to a
64 maintenance branch for an older release from a
65 development branch), adding this information can be
66 useful.
67
6b04600a 68-r::
abd6970a
JH
69 It used to be that the command defaulted to do `-x`
70 described above, and `-r` was to disable it. Now the
71 default is not to do `-x` so this option is a no-op.
de2b82c6 72
3240240f
SB
73-m parent-number::
74--mainline parent-number::
84989bd8 75 Usually you cannot cherry-pick a merge because you do not know which
7791ecbc
JH
76 side of the merge should be considered the mainline. This
77 option specifies the parent number (starting from 1) of
78 the mainline and allows cherry-pick to replay the change
79 relative to the specified parent.
80
3240240f
SB
81-n::
82--no-commit::
89d32d33
CC
83 Usually the command automatically creates a sequence of commits.
84 This flag applies the changes necessary to cherry-pick
85 each named commit to your working tree and the index,
86 without making any commit. In addition, when this
37a7744f
BD
87 option is used, your index does not have to match the
88 HEAD commit. The cherry-pick is done against the
8bd867ee 89 beginning state of your index.
df8baa42
JF
90+
91This is useful when cherry-picking more than one commits'
8bd867ee 92effect to your index in a row.
de2b82c6 93
3240240f
SB
94-s::
95--signoff::
cfd9c277
DM
96 Add Signed-off-by line at the end of the commit message.
97
ab7e63e8
CC
98--ff::
99 If the current HEAD is the same as the parent of the
100 cherry-pick'ed commit, then a fast forward to this commit will
101 be performed.
de2b82c6 102
67ac1e1d
JN
103--strategy=<strategy>::
104 Use the given merge strategy. Should only be used once.
105 See the MERGE STRATEGIES section in linkgit:git-merge[1]
106 for details.
107
108-X<option>::
109--strategy-option=<option>::
110 Pass the merge strategy-specific option through to the
111 merge strategy. See linkgit:git-merge[1] for details.
112
26ae337b
RR
113SEQUENCER SUBCOMMANDS
114---------------------
115include::sequencer.txt[]
116
89d32d33
CC
117EXAMPLES
118--------
119git cherry-pick master::
120
121 Apply the change introduced by the commit at the tip of the
122 master branch and create a new commit with this change.
123
124git cherry-pick ..master::
125git cherry-pick ^HEAD master::
126
127 Apply the changes introduced by all commits that are ancestors
128 of master but not of HEAD to produce new commits.
129
be1b0558 130git cherry-pick master{tilde}4 master{tilde}2::
89d32d33
CC
131
132 Apply the changes introduced by the fifth and third last
133 commits pointed to by master and create 2 new commits with
134 these changes.
135
136git cherry-pick -n master~1 next::
137
138 Apply to the working tree and the index the changes introduced
139 by the second last commit pointed to by master and by the last
140 commit pointed to by next, but do not create any commit with
141 these changes.
142
143git cherry-pick --ff ..next::
144
145 If history is linear and HEAD is an ancestor of next, update
146 the working tree and advance the HEAD pointer to match next.
147 Otherwise, apply the changes introduced by those commits that
148 are in next but not HEAD to the current branch, creating a new
149 commit for each new change.
150
f873a273
CC
151git rev-list --reverse master \-- README | git cherry-pick -n --stdin::
152
153 Apply the changes introduced by all commits on the master
154 branch that touched README to the working tree and index,
155 so the result can be inspected and made into a single new
156 commit if suitable.
157
67ac1e1d
JN
158The following sequence attempts to backport a patch, bails out because
159the code the patch applies to has changed too much, and then tries
160again, this time exercising more care about matching up context lines.
161
162------------
163$ git cherry-pick topic^ <1>
164$ git diff <2>
165$ git reset --merge ORIG_HEAD <3>
166$ git cherry-pick -Xpatience topic^ <4>
167------------
168<1> apply the change that would be shown by `git show topic^`.
169In this example, the patch does not apply cleanly, so
170information about the conflict is written to the index and
171working tree and no new commit results.
172<2> summarize changes to be reconciled
173<3> cancel the cherry-pick. In other words, return to the
174pre-cherry-pick state, preserving any local modifications you had in
175the working tree.
176<4> try to apply the change introduced by `topic^` again,
177spending extra time to avoid mistakes based on incorrectly matching
178context lines.
179
89d32d33
CC
180SEE ALSO
181--------
182linkgit:git-revert[1]
183
de2b82c6
JH
184GIT
185---
9e1f0a85 186Part of the linkgit:git[1] suite