interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-cherry-pick.adoc

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