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