]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-cherry-pick.txt
git-cherry-pick.txt: clarify the use of revision range notation
[thirdparty/git.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] <commit>...
12 'git cherry-pick' --continue
13 'git cherry-pick' --quit
14 'git cherry-pick' --abort
15
16 DESCRIPTION
17 -----------
18
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).
22
23 When it is not obvious how to apply a change, the following
24 happens:
25
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.
38
39 See linkgit:git-merge[1] for some hints on resolving such
40 conflicts.
41
42 OPTIONS
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]. Note that specifying a range will
51 feed all <commit>... arguments to a single revision walk
52 (see a later example that uses 'maint master..next').
53
54 -e::
55 --edit::
56 With this option, 'git cherry-pick' will let you edit the commit
57 message prior to committing.
58
59 -x::
60 When recording the commit, append a line that says
61 "(cherry picked from commit ...)" to the original commit
62 message in order to indicate which commit this change was
63 cherry-picked from. This is done only for cherry
64 picks without conflicts. Do not use this option if
65 you are cherry-picking from your private branch because
66 the information is useless to the recipient. If on the
67 other hand you are cherry-picking between two publicly
68 visible branches (e.g. backporting a fix to a
69 maintenance branch for an older release from a
70 development branch), adding this information can be
71 useful.
72
73 -r::
74 It used to be that the command defaulted to do `-x`
75 described above, and `-r` was to disable it. Now the
76 default is not to do `-x` so this option is a no-op.
77
78 -m parent-number::
79 --mainline parent-number::
80 Usually you cannot cherry-pick a merge because you do not know which
81 side of the merge should be considered the mainline. This
82 option specifies the parent number (starting from 1) of
83 the mainline and allows cherry-pick to replay the change
84 relative to the specified parent.
85
86 -n::
87 --no-commit::
88 Usually the command automatically creates a sequence of commits.
89 This flag applies the changes necessary to cherry-pick
90 each named commit to your working tree and the index,
91 without making any commit. In addition, when this
92 option is used, your index does not have to match the
93 HEAD commit. The cherry-pick is done against the
94 beginning state of your index.
95 +
96 This is useful when cherry-picking more than one commits'
97 effect to your index in a row.
98
99 -s::
100 --signoff::
101 Add Signed-off-by line at the end of the commit message.
102
103 --ff::
104 If the current HEAD is the same as the parent of the
105 cherry-pick'ed commit, then a fast forward to this commit will
106 be performed.
107
108 --strategy=<strategy>::
109 Use the given merge strategy. Should only be used once.
110 See the MERGE STRATEGIES section in linkgit:git-merge[1]
111 for details.
112
113 -X<option>::
114 --strategy-option=<option>::
115 Pass the merge strategy-specific option through to the
116 merge strategy. See linkgit:git-merge[1] for details.
117
118 SEQUENCER SUBCOMMANDS
119 ---------------------
120 include::sequencer.txt[]
121
122 EXAMPLES
123 --------
124 `git cherry-pick master`::
125
126 Apply the change introduced by the commit at the tip of the
127 master branch and create a new commit with this change.
128
129 `git cherry-pick ..master`::
130 `git cherry-pick ^HEAD master`::
131
132 Apply the changes introduced by all commits that are ancestors
133 of master but not of HEAD to produce new commits.
134
135 `git cherry-pick maint next ^master`::
136 `git cherry-pick maint master..next`::
137
138 Apply the changes introduced by all commits that are
139 ancestors of maint or next, but not master or any of its
140 ancestors. Note that the latter does not mean `maint` and
141 everything between `master` and `next`; specifically,
142 `maint` will not be used if it is included in `master`.
143
144 `git cherry-pick master{tilde}4 master{tilde}2`::
145
146 Apply the changes introduced by the fifth and third last
147 commits pointed to by master and create 2 new commits with
148 these changes.
149
150 `git cherry-pick -n master~1 next`::
151
152 Apply to the working tree and the index the changes introduced
153 by the second last commit pointed to by master and by the last
154 commit pointed to by next, but do not create any commit with
155 these changes.
156
157 `git cherry-pick --ff ..next`::
158
159 If history is linear and HEAD is an ancestor of next, update
160 the working tree and advance the HEAD pointer to match next.
161 Otherwise, apply the changes introduced by those commits that
162 are in next but not HEAD to the current branch, creating a new
163 commit for each new change.
164
165 `git rev-list --reverse master \-- README | git cherry-pick -n --stdin`::
166
167 Apply the changes introduced by all commits on the master
168 branch that touched README to the working tree and index,
169 so the result can be inspected and made into a single new
170 commit if suitable.
171
172 The following sequence attempts to backport a patch, bails out because
173 the code the patch applies to has changed too much, and then tries
174 again, this time exercising more care about matching up context lines.
175
176 ------------
177 $ git cherry-pick topic^ <1>
178 $ git diff <2>
179 $ git reset --merge ORIG_HEAD <3>
180 $ git cherry-pick -Xpatience topic^ <4>
181 ------------
182 <1> apply the change that would be shown by `git show topic^`.
183 In this example, the patch does not apply cleanly, so
184 information about the conflict is written to the index and
185 working tree and no new commit results.
186 <2> summarize changes to be reconciled
187 <3> cancel the cherry-pick. In other words, return to the
188 pre-cherry-pick state, preserving any local modifications you had in
189 the working tree.
190 <4> try to apply the change introduced by `topic^` again,
191 spending extra time to avoid mistakes based on incorrectly matching
192 context lines.
193
194 SEE ALSO
195 --------
196 linkgit:git-revert[1]
197
198 GIT
199 ---
200 Part of the linkgit:git[1] suite