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