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