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