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 Allow the rerere mechanism to update the index with the result of
141 auto-conflict resolution if possible.
142
144 --continue
145 Continue the operation in progress using the information in
146 .git/sequencer. Can be used to continue after resolving conflicts
147 in a failed cherry-pick or revert.
148
149 --skip
150 Skip the current commit and continue with the rest of the sequence.
151
152 --quit
153 Forget about the current operation in progress. Can be used to
154 clear the sequencer state after a failed cherry-pick or revert.
155
156 --abort
157 Cancel the operation and return to the pre-sequence state.
158
160 git cherry-pick master
161 Apply the change introduced by the commit at the tip of the master
162 branch and create a new commit with this change.
163
164 git cherry-pick ..master, git cherry-pick ^HEAD master
165 Apply the changes introduced by all commits that are ancestors of
166 master but not of HEAD to produce new commits.
167
168 git cherry-pick maint next ^master, git cherry-pick maint master..next
169 Apply the changes introduced by all commits that are ancestors of
170 maint or next, but not master or any of its ancestors. Note that
171 the latter does not mean maint and everything between master and
172 next; specifically, maint will not be used if it is included in
173 master.
174
175 git cherry-pick master~4 master~2
176 Apply the changes introduced by the fifth and third last commits
177 pointed to by master and create 2 new commits with these changes.
178
179 git cherry-pick -n master~1 next
180 Apply to the working tree and the index the changes introduced by
181 the second last commit pointed to by master and by the last commit
182 pointed to by next, but do not create any commit with these
183 changes.
184
185 git cherry-pick --ff ..next
186 If history is linear and HEAD is an ancestor of next, update the
187 working tree and advance the HEAD pointer to match next. Otherwise,
188 apply the changes introduced by those commits that are in next but
189 not HEAD to the current branch, creating a new commit for each new
190 change.
191
192 git rev-list --reverse master -- README | git cherry-pick -n --stdin
193 Apply the changes introduced by all commits on the master branch
194 that touched README to the working tree and index, so the result
195 can be inspected and made into a single new commit if suitable.
196
197 The following sequence attempts to backport a patch, bails out because
198 the code the patch applies to has changed too much, and then tries
199 again, this time exercising more care about matching up context lines.
200
201 $ git cherry-pick topic^ [1m(1)
202 $ git diff [1m(2)
203 $ git reset --merge ORIG_HEAD [1m(3)
204 $ git cherry-pick -Xpatience topic^ [1m(4)
205
206 1. apply the change that would be shown by git show topic^.
207 In this example, the patch does not apply cleanly, so
208 information about the conflict is written to the index and
209 working tree and no new commit results.
210 2. summarize changes to be reconciled
211 3. cancel the cherry-pick. In other words, return to the
212 pre-cherry-pick state, preserving any local modifications
213 you had in the working tree.
214 4. try to apply the change introduced by topic^ again,
215 spending extra time to avoid mistakes based on incorrectly
216 matching context lines.
217
219 git-revert(1)
220
222 Part of the git(1) suite
223
224
225
226Git 2.31.1 2021-03-26 GIT-CHERRY-PICK(1)