]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-cherry-pick.txt
The fifth batch
[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]
49cbad0e 11'git cherry-pick' [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
340f2c5e 12 [-S[<keyid>]] <commit>...
de81ca3f 13'git cherry-pick' (--continue | --skip | --abort | --quit)
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 47 Sets of commits can be passed but no traversal is done by
bcf9626a 48 default, as if the `--no-walk` option was specified, see
b98878ed
CMN
49 linkgit:git-rev-list[1]. Note that specifying a range will
50 feed all <commit>... arguments to a single revision walk
51 (see a later example that uses 'maint master..next').
de2b82c6 52
3240240f
SB
53-e::
54--edit::
0b444cdb 55 With this option, 'git cherry-pick' will let you edit the commit
233808db 56 message prior to committing.
8bf14d6e 57
1a2b985f
DL
58--cleanup=<mode>::
59 This option determines how the commit message will be cleaned up before
60 being passed on to the commit machinery. See linkgit:git-commit[1] for more
61 details. In particular, if the '<mode>' is given a value of `scissors`,
62 scissors will be appended to `MERGE_MSG` before being passed on in the case
63 of a conflict.
64
abd6970a 65-x::
bea7d16e
SS
66 When recording the commit, append a line that says
67 "(cherry picked from commit ...)" to the original commit
68 message in order to indicate which commit this change was
69 cherry-picked from. This is done only for cherry
dd8175f8
RW
70 picks without conflicts. Do not use this option if
71 you are cherry-picking from your private branch because
72 the information is useless to the recipient. If on the
abd6970a
JH
73 other hand you are cherry-picking between two publicly
74 visible branches (e.g. backporting a fix to a
75 maintenance branch for an older release from a
76 development branch), adding this information can be
77 useful.
78
6b04600a 79-r::
abd6970a
JH
80 It used to be that the command defaulted to do `-x`
81 described above, and `-r` was to disable it. Now the
82 default is not to do `-x` so this option is a no-op.
de2b82c6 83
49cbad0e
JNA
84-m <parent-number>::
85--mainline <parent-number>::
84989bd8 86 Usually you cannot cherry-pick a merge because you do not know which
7791ecbc
JH
87 side of the merge should be considered the mainline. This
88 option specifies the parent number (starting from 1) of
89 the mainline and allows cherry-pick to replay the change
90 relative to the specified parent.
91
3240240f
SB
92-n::
93--no-commit::
89d32d33
CC
94 Usually the command automatically creates a sequence of commits.
95 This flag applies the changes necessary to cherry-pick
96 each named commit to your working tree and the index,
97 without making any commit. In addition, when this
37a7744f
BD
98 option is used, your index does not have to match the
99 HEAD commit. The cherry-pick is done against the
8bd867ee 100 beginning state of your index.
df8baa42
JF
101+
102This is useful when cherry-picking more than one commits'
8bd867ee 103effect to your index in a row.
de2b82c6 104
3240240f
SB
105-s::
106--signoff::
3abd4a67 107 Add a `Signed-off-by` trailer at the end of the commit message.
b2c150d3 108 See the signoff option in linkgit:git-commit[1] for more information.
cfd9c277 109
340f2c5e
MM
110-S[<keyid>]::
111--gpg-sign[=<keyid>]::
cf0ad4d1 112--no-gpg-sign::
2b594bf9
MM
113 GPG-sign commits. The `keyid` argument is optional and
114 defaults to the committer identity; if specified, it must be
cf0ad4d1
ĐTCD
115 stuck to the option without a space. `--no-gpg-sign` is useful to
116 countermand both `commit.gpgSign` configuration variable, and
117 earlier `--gpg-sign`.
3253553e 118
ab7e63e8
CC
119--ff::
120 If the current HEAD is the same as the parent of the
121 cherry-pick'ed commit, then a fast forward to this commit will
122 be performed.
de2b82c6 123
df478b74
NH
124--allow-empty::
125 By default, cherry-picking an empty commit will fail,
126 indicating that an explicit invocation of `git commit
127 --allow-empty` is required. This option overrides that
128 behavior, allowing empty commits to be preserved automatically
129 in a cherry-pick. Note that when "--ff" is in effect, empty
130 commits that meet the "fast-forward" requirement will be kept
b27cfb0d
NH
131 even without this option. Note also, that use of this option only
132 keeps commits that were initially empty (i.e. the commit recorded the
133 same tree as its parent). Commits which are made empty due to a
ec79d763
BL
134 previous commit will cause the cherry-pick to fail. To force the
135 inclusion of those commits, use `--empty=keep`.
b27cfb0d 136
4bee9584
CW
137--allow-empty-message::
138 By default, cherry-picking a commit with an empty message will fail.
cd82b7a0 139 This option overrides that behavior, allowing commits with empty
4bee9584
CW
140 messages to be cherry picked.
141
ec79d763
BL
142--empty=(drop|keep|stop)::
143 How to handle commits being cherry-picked that are redundant with
144 changes already in the current history.
145+
146--
147`drop`;;
148 The commit will be dropped.
149`keep`;;
150 The commit will be kept. Implies `--allow-empty`.
151`stop`;;
152 The cherry-pick will stop when the commit is applied, allowing
153 you to examine the commit. This is the default behavior.
154--
155+
156Note that `--empty=drop` and `--empty=stop` only specify how to handle a
157commit that was not initially empty, but rather became empty due to a previous
158commit. Commits that were initially empty will still cause the cherry-pick to
159fail unless one of `--empty=keep` or `--allow-empty` are specified.
160+
161
b27cfb0d 162--keep-redundant-commits::
ec79d763 163 Deprecated synonym for `--empty=keep`.
df478b74 164
67ac1e1d
JN
165--strategy=<strategy>::
166 Use the given merge strategy. Should only be used once.
167 See the MERGE STRATEGIES section in linkgit:git-merge[1]
168 for details.
169
170-X<option>::
171--strategy-option=<option>::
172 Pass the merge strategy-specific option through to the
173 merge strategy. See linkgit:git-merge[1] for details.
174
0dbc715a 175include::rerere-options.txt[]
aba4954c 176
26ae337b
RR
177SEQUENCER SUBCOMMANDS
178---------------------
179include::sequencer.txt[]
180
89d32d33
CC
181EXAMPLES
182--------
5d2fc913 183`git cherry-pick master`::
89d32d33
CC
184
185 Apply the change introduced by the commit at the tip of the
186 master branch and create a new commit with this change.
187
5d2fc913
JK
188`git cherry-pick ..master`::
189`git cherry-pick ^HEAD master`::
89d32d33
CC
190
191 Apply the changes introduced by all commits that are ancestors
192 of master but not of HEAD to produce new commits.
193
b98878ed
CMN
194`git cherry-pick maint next ^master`::
195`git cherry-pick maint master..next`::
196
197 Apply the changes introduced by all commits that are
198 ancestors of maint or next, but not master or any of its
199 ancestors. Note that the latter does not mean `maint` and
200 everything between `master` and `next`; specifically,
201 `maint` will not be used if it is included in `master`.
202
6cf378f0 203`git cherry-pick master~4 master~2`::
89d32d33
CC
204
205 Apply the changes introduced by the fifth and third last
206 commits pointed to by master and create 2 new commits with
207 these changes.
208
5d2fc913 209`git cherry-pick -n master~1 next`::
89d32d33
CC
210
211 Apply to the working tree and the index the changes introduced
212 by the second last commit pointed to by master and by the last
213 commit pointed to by next, but do not create any commit with
214 these changes.
215
5d2fc913 216`git cherry-pick --ff ..next`::
89d32d33
CC
217
218 If history is linear and HEAD is an ancestor of next, update
219 the working tree and advance the HEAD pointer to match next.
220 Otherwise, apply the changes introduced by those commits that
221 are in next but not HEAD to the current branch, creating a new
222 commit for each new change.
223
6cf378f0 224`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
f873a273
CC
225
226 Apply the changes introduced by all commits on the master
227 branch that touched README to the working tree and index,
228 so the result can be inspected and made into a single new
229 commit if suitable.
230
67ac1e1d
JN
231The following sequence attempts to backport a patch, bails out because
232the code the patch applies to has changed too much, and then tries
233again, this time exercising more care about matching up context lines.
234
235------------
236$ git cherry-pick topic^ <1>
237$ git diff <2>
e29678bb 238$ git cherry-pick --abort <3>
67ac1e1d
JN
239$ git cherry-pick -Xpatience topic^ <4>
240------------
241<1> apply the change that would be shown by `git show topic^`.
ba170517
JNA
242 In this example, the patch does not apply cleanly, so
243 information about the conflict is written to the index and
244 working tree and no new commit results.
67ac1e1d
JN
245<2> summarize changes to be reconciled
246<3> cancel the cherry-pick. In other words, return to the
ba170517
JNA
247 pre-cherry-pick state, preserving any local modifications
248 you had in the working tree.
67ac1e1d 249<4> try to apply the change introduced by `topic^` again,
ba170517
JNA
250 spending extra time to avoid mistakes based on incorrectly
251 matching context lines.
67ac1e1d 252
89d32d33
CC
253SEE ALSO
254--------
255linkgit:git-revert[1]
256
de2b82c6
JH
257GIT
258---
9e1f0a85 259Part of the linkgit:git[1] suite