at commit 81c1e0b3

1 git-cherry-pick(1)
2 ==================
3
4 NAME
5 ----
6 git-cherry-pick - Apply the changes introduced by some existing commits
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git cherry-pick' [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
12 [-S[<keyid>]] <commit>...
13 'git cherry-pick' (--continue | --skip | --abort | --quit)
14
15 DESCRIPTION
16 -----------
17
18 Given one or more existing commits, apply the change each one
19 introduces, recording a new commit for each. This requires your
20 working tree to be clean (no modifications from the HEAD commit).
21
22 When it is not obvious how to apply a change, the following
23 happens:
24
25 1. The current branch and `HEAD` pointer stay at the last commit
26 successfully made.
27 2. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
28 introduced the change that is difficult to apply, unless the
29 `--no-commit` option was given.
30 3. Paths in which the change applied cleanly are updated both
31 in the index file and in your working tree.
32 4. 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 `>>>>>>>`.
37 5. No other modifications are made.
38
39 See linkgit:git-merge[1] for some hints on resolving such
40 conflicts.
41
42 OPTIONS
43 -------
44 <commit>...::
45 Commits to cherry-pick.
46 For a more complete list of ways to spell commits, see
47 linkgit:gitrevisions[7].
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]. Note that specifying a range will
51 feed all <commit>... arguments to a single revision walk
52 (see a later example that uses 'maint master..next').
53
54 -e::
55 --edit::
56 With this option, 'git cherry-pick' will let you edit the commit
57 message prior to committing.
58
59 --cleanup=<mode>::
60 This option determines how the commit message will be cleaned up before
61 being passed on to the commit machinery. See linkgit:git-commit[1] for more
62 details. In particular, if the '<mode>' is given a value of `scissors`,
63 scissors will be appended to `MERGE_MSG` before being passed on in the case
64 of a conflict.
65
66 -x::
67 When recording the commit, append a line that says
68 "(cherry picked from commit ...)" to the original commit
69 message in order to indicate which commit this change was
70 cherry-picked from. This is done only for cherry
71 picks without conflicts. Do not use this option if
72 you are cherry-picking from your private branch because
73 the information is useless to the recipient. If on the
74 other hand you are cherry-picking between two publicly
75 visible branches (e.g. backporting a fix to a
76 maintenance branch for an older release from a
77 development branch), adding this information can be
78 useful.
79
80 -r::
81 It used to be that the command defaulted to do `-x`
82 described above, and `-r` was to disable it. Now the
83 default is not to do `-x` so this option is a no-op.
84
85 -m <parent-number>::
86 --mainline <parent-number>::
87 Usually you cannot cherry-pick a merge because you do not know which
88 side of the merge should be considered the mainline. This
89 option specifies the parent number (starting from 1) of
90 the mainline and allows cherry-pick to replay the change
91 relative to the specified parent.
92
93 -n::
94 --no-commit::
95 Usually the command automatically creates a sequence of commits.
96 This flag applies the changes necessary to cherry-pick
97 each named commit to your working tree and the index,
98 without making any commit. In addition, when this
99 option is used, your index does not have to match the
100 HEAD commit. The cherry-pick is done against the
101 beginning state of your index.
102 +
103 This is useful when cherry-picking more than one commits'
104 effect to your index in a row.
105 +
106 This option does not record `CHERRY_PICK_HEAD`, so a plain `git commit`
107 afterwards records you as the author. That is by design: what you are
108 building is your own work, which you keep changing before committing,
109 rather than a reproduction of the original commit.
110
111 -s::
112 --signoff::
113 Add a `Signed-off-by` trailer at the end of the commit message.
114 See the signoff option in linkgit:git-commit[1] for more information.
115
116 -S[<keyid>]::
117 --gpg-sign[=<keyid>]::
118 --no-gpg-sign::
119 GPG-sign commits. The `keyid` argument is optional and
120 defaults to the committer identity; if specified, it must be
121 stuck to the option without a space. `--no-gpg-sign` is useful to
122 countermand both `commit.gpgSign` configuration variable, and
123 earlier `--gpg-sign`.
124
125 --ff::
126 If the current HEAD is the same as the parent of the
127 cherry-pick'ed commit, then a fast forward to this commit will
128 be performed.
129
130 --allow-empty::
131 By default, cherry-picking an empty commit will fail,
132 indicating that an explicit invocation of `git commit
133 --allow-empty` is required. This option overrides that
134 behavior, allowing empty commits to be preserved automatically
135 in a cherry-pick. Note that when "--ff" is in effect, empty
136 commits that meet the "fast-forward" requirement will be kept
137 even without this option. Note also, that use of this option only
138 keeps commits that were initially empty (i.e. the commit recorded the
139 same tree as its parent). Commits which are made empty due to a
140 previous commit will cause the cherry-pick to fail. To force the
141 inclusion of those commits, use `--empty=keep`.
142
143 --allow-empty-message::
144 By default, cherry-picking a commit with an empty message will fail.
145 This option overrides that behavior, allowing commits with empty
146 messages to be cherry picked.
147
148 --empty=(drop|keep|stop)::
149 How to handle commits being cherry-picked that are redundant with
150 changes already in the current history.
151 +
152 --
153 `drop`;;
154 The commit will be dropped.
155 `keep`;;
156 The commit will be kept. Implies `--allow-empty`.
157 `stop`;;
158 The cherry-pick will stop when the commit is applied, allowing
159 you to examine the commit. This is the default behavior.
160 --
161 +
162 Note that `--empty=drop` and `--empty=stop` only specify how to handle a
163 commit that was not initially empty, but rather became empty due to a previous
164 commit. Commits that were initially empty will still cause the cherry-pick to
165 fail unless one of `--empty=keep` or `--allow-empty` are specified.
166 +
167
168 --keep-redundant-commits::
169 Deprecated synonym for `--empty=keep`.
170
171 --strategy=<strategy>::
172 Use the given merge strategy. Should only be used once.
173 See the MERGE STRATEGIES section in linkgit:git-merge[1]
174 for details.
175
176 -X<option>::
177 --strategy-option=<option>::
178 Pass the merge strategy-specific option through to the
179 merge strategy. See linkgit:git-merge[1] for details.
180
181 include::rerere-options.adoc[]
182
183 SEQUENCER SUBCOMMANDS
184 ---------------------
185 include::sequencer.adoc[]
186
187 EXAMPLES
188 --------
189 `git cherry-pick master`::
190
191 Apply the change introduced by the commit at the tip of the
192 master branch and create a new commit with this change.
193
194 `git cherry-pick ..master`::
195 `git cherry-pick ^HEAD master`::
196
197 Apply the changes introduced by all commits that are ancestors
198 of master but not of HEAD to produce new commits.
199
200 `git cherry-pick maint next ^master`::
201 `git cherry-pick maint master..next`::
202
203 Apply the changes introduced by all commits that are
204 ancestors of maint or next, but not master or any of its
205 ancestors. Note that the latter does not mean `maint` and
206 everything between `master` and `next`; specifically,
207 `maint` will not be used if it is included in `master`.
208
209 `git cherry-pick master~4 master~2`::
210
211 Apply the changes introduced by the fifth and third last
212 commits pointed to by master and create 2 new commits with
213 these changes.
214
215 `git cherry-pick -n master~1 next`::
216
217 Apply to the working tree and the index the changes introduced
218 by the second last commit pointed to by master and by the last
219 commit pointed to by next, but do not create any commit with
220 these changes.
221
222 `git cherry-pick --ff ..next`::
223
224 If history is linear and HEAD is an ancestor of next, update
225 the working tree and advance the HEAD pointer to match next.
226 Otherwise, apply the changes introduced by those commits that
227 are in next but not HEAD to the current branch, creating a new
228 commit for each new change.
229
230 `git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
231
232 Apply the changes introduced by all commits on the master
233 branch that touched README to the working tree and index,
234 so the result can be inspected and made into a single new
235 commit if suitable.
236
237 The following sequence attempts to backport a patch, bails out because
238 the code the patch applies to has changed too much, and then tries
239 again, this time exercising more care about matching up context lines.
240
241 ------------
242 $ git cherry-pick topic^ <1>
243 $ git diff <2>
244 $ git cherry-pick --abort <3>
245 $ git cherry-pick -Xpatience topic^ <4>
246 ------------
247 <1> apply the change that would be shown by `git show topic^`.
248 In this example, the patch does not apply cleanly, so
249 information about the conflict is written to the index and
250 working tree and no new commit results.
251 <2> summarize changes to be reconciled
252 <3> cancel the cherry-pick. In other words, return to the
253 pre-cherry-pick state, preserving any local modifications
254 you had in the working tree.
255 <4> try to apply the change introduced by `topic^` again,
256 spending extra time to avoid mistakes based on incorrectly
257 matching context lines.
258
259 SEE ALSO
260 --------
261 linkgit:git-revert[1]
262
263 GIT
264 ---
265 Part of the linkgit:git[1] suite