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