1GIT-CHERRY-PICK(1)                Git Manual                GIT-CHERRY-PICK(1)
2
3
4

NAME

6       git-cherry-pick - Apply the changes introduced by some existing commits
7

SYNOPSIS

9       git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
10                         [-S[<keyid>]] <commit>...
11       git cherry-pick --continue
12       git cherry-pick --quit
13       git cherry-pick --abort
14
15

DESCRIPTION

17       Given one or more existing commits, apply the change each one
18       introduces, recording a new commit for each. This requires your working
19       tree to be clean (no modifications from the HEAD commit).
20
21       When it is not obvious how to apply a change, the following happens:
22
23        1. The current branch and HEAD pointer stay at the last commit
24           successfully made.
25
26        2. The CHERRY_PICK_HEAD ref is set to point at the commit that
27           introduced the change that is difficult to apply.
28
29        3. Paths in which the change applied cleanly are updated both in the
30           index file and in your working tree.
31
32        4. For conflicting paths, the index file records up to three versions,
33           as described in the "TRUE MERGE" section of git-merge(1). The
34           working tree files will include a description of the conflict
35           bracketed by the usual conflict markers <<<<<<< and >>>>>>>.
36
37        5. No other modifications are made.
38
39       See git-merge(1) for some hints on resolving such conflicts.
40

OPTIONS

42       <commit>...
43           Commits to cherry-pick. For a more complete list of ways to spell
44           commits, see gitrevisions(7). Sets of commits can be passed but no
45           traversal is done by default, as if the --no-walk option was
46           specified, see git-rev-list(1). Note that specifying a range will
47           feed all <commit>... arguments to a single revision walk (see a
48           later example that uses maint master..next).
49
50       -e, --edit
51           With this option, git cherry-pick will let you edit the commit
52           message prior to committing.
53
54       -x
55           When recording the commit, append a line that says "(cherry picked
56           from commit ...)" to the original commit message in order to
57           indicate which commit this change was cherry-picked from. This is
58           done only for cherry picks without conflicts. Do not use this
59           option if you are cherry-picking from your private branch because
60           the information is useless to the recipient. If on the other hand
61           you are cherry-picking between two publicly visible branches (e.g.
62           backporting a fix to a maintenance branch for an older release from
63           a development branch), adding this information can be useful.
64
65       -r
66           It used to be that the command defaulted to do -x described above,
67           and -r was to disable it. Now the default is not to do -x so this
68           option is a no-op.
69
70       -m parent-number, --mainline parent-number
71           Usually you cannot cherry-pick a merge because you do not know
72           which side of the merge should be considered the mainline. This
73           option specifies the parent number (starting from 1) of the
74           mainline and allows cherry-pick to replay the change relative to
75           the specified parent.
76
77       -n, --no-commit
78           Usually the command automatically creates a sequence of commits.
79           This flag applies the changes necessary to cherry-pick each named
80           commit to your working tree and the index, without making any
81           commit. In addition, when this option is used, your index does not
82           have to match the HEAD commit. The cherry-pick is done against the
83           beginning state of your index.
84
85           This is useful when cherry-picking more than one commits' effect to
86           your index in a row.
87
88       -s, --signoff
89           Add Signed-off-by line at the end of the commit message. See the
90           signoff option in git-commit(1) for more information.
91
92       -S[<keyid>], --gpg-sign[=<keyid>]
93           GPG-sign commits. The keyid argument is optional and defaults to
94           the committer identity; if specified, it must be stuck to the
95           option without a space.
96
97       --ff
98           If the current HEAD is the same as the parent of the cherry-pickā€™ed
99           commit, then a fast forward to this commit will be performed.
100
101       --allow-empty
102           By default, cherry-picking an empty commit will fail, indicating
103           that an explicit invocation of git commit --allow-empty is
104           required. This option overrides that behavior, allowing empty
105           commits to be preserved automatically in a cherry-pick. Note that
106           when "--ff" is in effect, empty commits that meet the
107           "fast-forward" requirement will be kept even without this option.
108           Note also, that use of this option only keeps commits that were
109           initially empty (i.e. the commit recorded the same tree as its
110           parent). Commits which are made empty due to a previous commit are
111           dropped. To force the inclusion of those commits use
112           --keep-redundant-commits.
113
114       --allow-empty-message
115           By default, cherry-picking a commit with an empty message will
116           fail. This option overrides that behavior, allowing commits with
117           empty messages to be cherry picked.
118
119       --keep-redundant-commits
120           If a commit being cherry picked duplicates a commit already in the
121           current history, it will become empty. By default these redundant
122           commits cause cherry-pick to stop so the user can examine the
123           commit. This option overrides that behavior and creates an empty
124           commit object. Implies --allow-empty.
125
126       --strategy=<strategy>
127           Use the given merge strategy. Should only be used once. See the
128           MERGE STRATEGIES section in git-merge(1) for details.
129
130       -X<option>, --strategy-option=<option>
131           Pass the merge strategy-specific option through to the merge
132           strategy. See git-merge(1) for details.
133

SEQUENCER SUBCOMMANDS

135       --continue
136           Continue the operation in progress using the information in
137           .git/sequencer. Can be used to continue after resolving conflicts
138           in a failed cherry-pick or revert.
139
140       --quit
141           Forget about the current operation in progress. Can be used to
142           clear the sequencer state after a failed cherry-pick or revert.
143
144       --abort
145           Cancel the operation and return to the pre-sequence state.
146

EXAMPLES

148       git cherry-pick master
149           Apply the change introduced by the commit at the tip of the master
150           branch and create a new commit with this change.
151
152       git cherry-pick ..master, git cherry-pick ^HEAD master
153           Apply the changes introduced by all commits that are ancestors of
154           master but not of HEAD to produce new commits.
155
156       git cherry-pick maint next ^master, git cherry-pick maint master..next
157           Apply the changes introduced by all commits that are ancestors of
158           maint or next, but not master or any of its ancestors. Note that
159           the latter does not mean maint and everything between master and
160           next; specifically, maint will not be used if it is included in
161           master.
162
163       git cherry-pick master~4 master~2
164           Apply the changes introduced by the fifth and third last commits
165           pointed to by master and create 2 new commits with these changes.
166
167       git cherry-pick -n master~1 next
168           Apply to the working tree and the index the changes introduced by
169           the second last commit pointed to by master and by the last commit
170           pointed to by next, but do not create any commit with these
171           changes.
172
173       git cherry-pick --ff ..next
174           If history is linear and HEAD is an ancestor of next, update the
175           working tree and advance the HEAD pointer to match next. Otherwise,
176           apply the changes introduced by those commits that are in next but
177           not HEAD to the current branch, creating a new commit for each new
178           change.
179
180       git rev-list --reverse master -- README | git cherry-pick -n --stdin
181           Apply the changes introduced by all commits on the master branch
182           that touched README to the working tree and index, so the result
183           can be inspected and made into a single new commit if suitable.
184
185       The following sequence attempts to backport a patch, bails out because
186       the code the patch applies to has changed too much, and then tries
187       again, this time exercising more care about matching up context lines.
188
189           $ git cherry-pick topic^             (1)
190           $ git diff                           (2)
191           $ git reset --merge ORIG_HEAD        (3)
192           $ git cherry-pick -Xpatience topic^  (4)
193
194
195       1. apply the change that would be shown by git show topic^. In this
196       example, the patch does not apply cleanly, so information about the
197       conflict is written to the index and working tree and no new commit
198       results.
199       2. summarize changes to be reconciled
200       3. cancel the cherry-pick. In other words, return to the
201       pre-cherry-pick state, preserving any local modifications you had in
202       the working tree.
203       4. try to apply the change introduced by topic^ again, spending extra
204       time to avoid mistakes based on incorrectly matching context lines.
205

SEE ALSO

207       git-revert(1)
208

GIT

210       Part of the git(1) suite
211
212
213
214Git 2.18.1                        05/14/2019                GIT-CHERRY-PICK(1)
Impressum