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