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