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