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 a Signed-off-by trailer at the end of the commit message. See
94 the signoff option in git-commit(1) for more information.
95
96 -S[<keyid>], --gpg-sign[=<keyid>], --no-gpg-sign
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. --no-gpg-sign is useful to countermand
100 both commit.gpgSign configuration variable, and earlier --gpg-sign.
101
102 --ff
103 If the current HEAD is the same as the parent of the cherry-pickāed
104 commit, then a fast forward to this commit will be performed.
105
106 --allow-empty
107 By default, cherry-picking an empty commit will fail, indicating
108 that an explicit invocation of git commit --allow-empty is
109 required. This option overrides that behavior, allowing empty
110 commits to be preserved automatically in a cherry-pick. Note that
111 when "--ff" is in effect, empty commits that meet the
112 "fast-forward" requirement will be kept even without this option.
113 Note also, that use of this option only keeps commits that were
114 initially empty (i.e. the commit recorded the same tree as its
115 parent). Commits which are made empty due to a previous commit are
116 dropped. To force the inclusion of those commits use
117 --keep-redundant-commits.
118
119 --allow-empty-message
120 By default, cherry-picking a commit with an empty message will
121 fail. This option overrides that behavior, allowing commits with
122 empty messages to be cherry picked.
123
124 --keep-redundant-commits
125 If a commit being cherry picked duplicates a commit already in the
126 current history, it will become empty. By default these redundant
127 commits cause cherry-pick to stop so the user can examine the
128 commit. This option overrides that behavior and creates an empty
129 commit object. Implies --allow-empty.
130
131 --strategy=<strategy>
132 Use the given merge strategy. Should only be used once. See the
133 MERGE STRATEGIES section in git-merge(1) for details.
134
135 -X<option>, --strategy-option=<option>
136 Pass the merge strategy-specific option through to the merge
137 strategy. See git-merge(1) for details.
138
139 --rerere-autoupdate, --no-rerere-autoupdate
140 After the rerere mechanism reuses a recorded resolution on the
141 current conflict to update the files in the working tree, allow it
142 to also update the index with the result of resolution.
143 --no-rerere-autoupdate is a good way to double-check what rerere
144 did and catch potential mismerges, before committing the result to
145 the index with a separate git add.
146
148 --continue
149 Continue the operation in progress using the information in
150 .git/sequencer. Can be used to continue after resolving conflicts
151 in a failed cherry-pick or revert.
152
153 --skip
154 Skip the current commit and continue with the rest of the sequence.
155
156 --quit
157 Forget about the current operation in progress. Can be used to
158 clear the sequencer state after a failed cherry-pick or revert.
159
160 --abort
161 Cancel the operation and return to the pre-sequence state.
162
164 git cherry-pick master
165 Apply the change introduced by the commit at the tip of the master
166 branch and create a new commit with this change.
167
168 git cherry-pick ..master, git cherry-pick ^HEAD master
169 Apply the changes introduced by all commits that are ancestors of
170 master but not of HEAD to produce new commits.
171
172 git cherry-pick maint next ^master, git cherry-pick maint master..next
173 Apply the changes introduced by all commits that are ancestors of
174 maint or next, but not master or any of its ancestors. Note that
175 the latter does not mean maint and everything between master and
176 next; specifically, maint will not be used if it is included in
177 master.
178
179 git cherry-pick master~4 master~2
180 Apply the changes introduced by the fifth and third last commits
181 pointed to by master and create 2 new commits with these changes.
182
183 git cherry-pick -n master~1 next
184 Apply to the working tree and the index the changes introduced by
185 the second last commit pointed to by master and by the last commit
186 pointed to by next, but do not create any commit with these
187 changes.
188
189 git cherry-pick --ff ..next
190 If history is linear and HEAD is an ancestor of next, update the
191 working tree and advance the HEAD pointer to match next. Otherwise,
192 apply the changes introduced by those commits that are in next but
193 not HEAD to the current branch, creating a new commit for each new
194 change.
195
196 git rev-list --reverse master -- README | git cherry-pick -n --stdin
197 Apply the changes introduced by all commits on the master branch
198 that touched README to the working tree and index, so the result
199 can be inspected and made into a single new commit if suitable.
200
201 The following sequence attempts to backport a patch, bails out because
202 the code the patch applies to has changed too much, and then tries
203 again, this time exercising more care about matching up context lines.
204
205 $ git cherry-pick topic^ [1m(1)
206 $ git diff [1m(2)
207 $ git cherry-pick --abort [1m(3)
208 $ git cherry-pick -Xpatience topic^ [1m(4)
209
210 1. apply the change that would be shown by git show topic^.
211 In this example, the patch does not apply cleanly, so
212 information about the conflict is written to the index and
213 working tree and no new commit results.
214 2. summarize changes to be reconciled
215 3. cancel the cherry-pick. In other words, return to the
216 pre-cherry-pick state, preserving any local modifications
217 you had in the working tree.
218 4. try to apply the change introduced by topic^ again,
219 spending extra time to avoid mistakes based on incorrectly
220 matching context lines.
221
223 git-revert(1)
224
226 Part of the git(1) suite
227
228
229
230Git 2.43.0 11/20/2023 GIT-CHERRY-PICK(1)