Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 1 | git-cherry-pick(1) |
| 2 | ================== |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 3 | |
| 4 | NAME |
| 5 | ---- |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 6 | git-cherry-pick - Apply the changes introduced by some existing commits |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Martin von Zweigbergk | 7791a1d | 2011-07-01 22:38:26 -0400 | [diff] [blame] | 10 | [verse] |
Nicolas Vigier | 3253553 | 2014-01-24 00:50:58 +0000 | [diff] [blame] | 11 | 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] |
| 12 | [-S[<keyid>]] <commit>... |
Ramkumar Ramachandra | 5a5d80f | 2011-08-04 16:09:15 +0530 | [diff] [blame] | 13 | 'git cherry-pick' --continue |
Jonathan Nieder | f80a872 | 2011-11-22 05:14:29 -0600 | [diff] [blame] | 14 | 'git cherry-pick' --quit |
Jonathan Nieder | 539047c | 2011-11-22 19:27:21 -0600 | [diff] [blame] | 15 | 'git cherry-pick' --abort |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 16 | |
| 17 | DESCRIPTION |
| 18 | ----------- |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 19 | |
| 20 | Given one or more existing commits, apply the change each one |
| 21 | introduces, recording a new commit for each. This requires your |
| 22 | working tree to be clean (no modifications from the HEAD commit). |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 23 | |
Jay Soffian | d7e5c0c | 2011-02-19 23:12:27 -0500 | [diff] [blame] | 24 | When it is not obvious how to apply a change, the following |
| 25 | happens: |
| 26 | |
| 27 | 1. The current branch and `HEAD` pointer stay at the last commit |
| 28 | successfully made. |
| 29 | 2. The `CHERRY_PICK_HEAD` ref is set to point at the commit that |
| 30 | introduced the change that is difficult to apply. |
| 31 | 3. Paths in which the change applied cleanly are updated both |
| 32 | in the index file and in your working tree. |
| 33 | 4. 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 `>>>>>>>`. |
| 38 | 5. No other modifications are made. |
| 39 | |
| 40 | See linkgit:git-merge[1] for some hints on resolving such |
| 41 | conflicts. |
| 42 | |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 43 | OPTIONS |
| 44 | ------- |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 45 | <commit>...:: |
| 46 | Commits to cherry-pick. |
Michael J Gruber | f028cda | 2010-07-05 18:11:41 +0200 | [diff] [blame] | 47 | For a more complete list of ways to spell commits, see |
Jonathan Nieder | 9d83e38 | 2010-10-11 11:03:32 -0500 | [diff] [blame] | 48 | linkgit:gitrevisions[7]. |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 49 | Sets of commits can be passed but no traversal is done by |
| 50 | default, as if the '--no-walk' option was specified, see |
Carlos Martín Nieto | b98878e | 2012-06-15 16:33:16 +0200 | [diff] [blame] | 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'). |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 54 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 55 | -e:: |
| 56 | --edit:: |
Thomas Rast | 0b444cd | 2010-01-10 00:33:00 +0100 | [diff] [blame] | 57 | With this option, 'git cherry-pick' will let you edit the commit |
Jim Meyering | 233808d | 2008-01-19 16:23:32 +0100 | [diff] [blame] | 58 | message prior to committing. |
Petr Baudis | 8bf14d6 | 2005-11-26 23:12:44 +0100 | [diff] [blame] | 59 | |
Junio C Hamano | abd6970 | 2006-10-05 17:54:14 -0700 | [diff] [blame] | 60 | -x:: |
Sebastian Schuberth | bea7d16 | 2011-04-15 19:53:51 +0200 | [diff] [blame] | 61 | When recording the commit, append a line that says |
| 62 | "(cherry picked from commit ...)" to the original commit |
| 63 | message in order to indicate which commit this change was |
| 64 | cherry-picked from. This is done only for cherry |
Ralf Wildenhues | dd8175f | 2007-10-21 11:36:19 +0200 | [diff] [blame] | 65 | picks without conflicts. Do not use this option if |
| 66 | you are cherry-picking from your private branch because |
| 67 | the information is useless to the recipient. If on the |
Junio C Hamano | abd6970 | 2006-10-05 17:54:14 -0700 | [diff] [blame] | 68 | other hand you are cherry-picking between two publicly |
| 69 | visible branches (e.g. backporting a fix to a |
| 70 | maintenance branch for an older release from a |
| 71 | development branch), adding this information can be |
| 72 | useful. |
| 73 | |
Andrew Ruder | 6b04600 | 2007-04-18 22:03:26 -0500 | [diff] [blame] | 74 | -r:: |
Junio C Hamano | abd6970 | 2006-10-05 17:54:14 -0700 | [diff] [blame] | 75 | It used to be that the command defaulted to do `-x` |
| 76 | described above, and `-r` was to disable it. Now the |
| 77 | default is not to do `-x` so this option is a no-op. |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 78 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 79 | -m parent-number:: |
| 80 | --mainline parent-number:: |
Mike Ralphson | 84989bd | 2008-02-29 17:00:38 +0000 | [diff] [blame] | 81 | Usually you cannot cherry-pick a merge because you do not know which |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 82 | side of the merge should be considered the mainline. This |
| 83 | option specifies the parent number (starting from 1) of |
| 84 | the mainline and allows cherry-pick to replay the change |
| 85 | relative to the specified parent. |
| 86 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 87 | -n:: |
| 88 | --no-commit:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 89 | Usually the command automatically creates a sequence of commits. |
| 90 | This flag applies the changes necessary to cherry-pick |
| 91 | each named commit to your working tree and the index, |
| 92 | without making any commit. In addition, when this |
Bryan Drewery | 37a7744 | 2008-11-19 23:11:42 -0600 | [diff] [blame] | 93 | option is used, your index does not have to match the |
| 94 | HEAD commit. The cherry-pick is done against the |
Petr Baudis | 8bd867e | 2008-07-16 14:35:22 +0200 | [diff] [blame] | 95 | beginning state of your index. |
Jonas Fonseca | df8baa4 | 2005-10-03 19:16:30 +0200 | [diff] [blame] | 96 | + |
| 97 | This is useful when cherry-picking more than one commits' |
Petr Baudis | 8bd867e | 2008-07-16 14:35:22 +0200 | [diff] [blame] | 98 | effect to your index in a row. |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 99 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 100 | -s:: |
| 101 | --signoff:: |
Dan McGee | cfd9c27 | 2008-04-26 15:14:28 -0500 | [diff] [blame] | 102 | Add Signed-off-by line at the end of the commit message. |
| 103 | |
Nicolas Vigier | 3253553 | 2014-01-24 00:50:58 +0000 | [diff] [blame] | 104 | -S[<keyid>]:: |
| 105 | --gpg-sign[=<keyid>]:: |
| 106 | GPG-sign commits. |
| 107 | |
Christian Couder | ab7e63e | 2010-03-06 21:34:44 +0100 | [diff] [blame] | 108 | --ff:: |
| 109 | If the current HEAD is the same as the parent of the |
| 110 | cherry-pick'ed commit, then a fast forward to this commit will |
| 111 | be performed. |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 112 | |
Neil Horman | df478b7 | 2012-04-11 16:21:53 -0400 | [diff] [blame] | 113 | --allow-empty:: |
| 114 | By default, cherry-picking an empty commit will fail, |
| 115 | indicating that an explicit invocation of `git commit |
| 116 | --allow-empty` is required. This option overrides that |
| 117 | behavior, allowing empty commits to be preserved automatically |
| 118 | in a cherry-pick. Note that when "--ff" is in effect, empty |
| 119 | commits that meet the "fast-forward" requirement will be kept |
Neil Horman | b27cfb0 | 2012-04-20 10:36:15 -0400 | [diff] [blame] | 120 | even without this option. Note also, that use of this option only |
| 121 | keeps commits that were initially empty (i.e. the commit recorded the |
| 122 | same tree as its parent). Commits which are made empty due to a |
| 123 | previous commit are dropped. To force the inclusion of those commits |
| 124 | use `--keep-redundant-commits`. |
| 125 | |
Chris Webb | 4bee958 | 2012-08-02 11:38:51 +0100 | [diff] [blame] | 126 | --allow-empty-message:: |
| 127 | By default, cherry-picking a commit with an empty message will fail. |
| 128 | This option overrides that behaviour, allowing commits with empty |
| 129 | messages to be cherry picked. |
| 130 | |
Neil Horman | b27cfb0 | 2012-04-20 10:36:15 -0400 | [diff] [blame] | 131 | --keep-redundant-commits:: |
| 132 | If a commit being cherry picked duplicates a commit already in the |
| 133 | current history, it will become empty. By default these |
| 134 | redundant commits are ignored. This option overrides that behavior and |
| 135 | creates an empty commit object. Implies `--allow-empty`. |
Neil Horman | df478b7 | 2012-04-11 16:21:53 -0400 | [diff] [blame] | 136 | |
Jonathan Nieder | 67ac1e1 | 2010-12-10 18:51:44 -0600 | [diff] [blame] | 137 | --strategy=<strategy>:: |
| 138 | Use the given merge strategy. Should only be used once. |
| 139 | See the MERGE STRATEGIES section in linkgit:git-merge[1] |
| 140 | for details. |
| 141 | |
| 142 | -X<option>:: |
| 143 | --strategy-option=<option>:: |
| 144 | Pass the merge strategy-specific option through to the |
| 145 | merge strategy. See linkgit:git-merge[1] for details. |
| 146 | |
Ramkumar Ramachandra | 26ae337 | 2011-08-04 16:09:11 +0530 | [diff] [blame] | 147 | SEQUENCER SUBCOMMANDS |
| 148 | --------------------- |
| 149 | include::sequencer.txt[] |
| 150 | |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 151 | EXAMPLES |
| 152 | -------- |
Jeff King | 5d2fc91 | 2011-08-03 20:13:29 -0600 | [diff] [blame] | 153 | `git cherry-pick master`:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 154 | |
| 155 | Apply the change introduced by the commit at the tip of the |
| 156 | master branch and create a new commit with this change. |
| 157 | |
Jeff King | 5d2fc91 | 2011-08-03 20:13:29 -0600 | [diff] [blame] | 158 | `git cherry-pick ..master`:: |
| 159 | `git cherry-pick ^HEAD master`:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 160 | |
| 161 | Apply the changes introduced by all commits that are ancestors |
| 162 | of master but not of HEAD to produce new commits. |
| 163 | |
Carlos Martín Nieto | b98878e | 2012-06-15 16:33:16 +0200 | [diff] [blame] | 164 | `git cherry-pick maint next ^master`:: |
| 165 | `git cherry-pick maint master..next`:: |
| 166 | |
| 167 | Apply the changes introduced by all commits that are |
| 168 | ancestors of maint or next, but not master or any of its |
| 169 | ancestors. Note that the latter does not mean `maint` and |
| 170 | everything between `master` and `next`; specifically, |
| 171 | `maint` will not be used if it is included in `master`. |
| 172 | |
Jeff King | 6cf378f | 2012-04-26 04:51:57 -0400 | [diff] [blame] | 173 | `git cherry-pick master~4 master~2`:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 174 | |
| 175 | Apply the changes introduced by the fifth and third last |
| 176 | commits pointed to by master and create 2 new commits with |
| 177 | these changes. |
| 178 | |
Jeff King | 5d2fc91 | 2011-08-03 20:13:29 -0600 | [diff] [blame] | 179 | `git cherry-pick -n master~1 next`:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 180 | |
| 181 | Apply to the working tree and the index the changes introduced |
| 182 | by the second last commit pointed to by master and by the last |
| 183 | commit pointed to by next, but do not create any commit with |
| 184 | these changes. |
| 185 | |
Jeff King | 5d2fc91 | 2011-08-03 20:13:29 -0600 | [diff] [blame] | 186 | `git cherry-pick --ff ..next`:: |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 187 | |
| 188 | If history is linear and HEAD is an ancestor of next, update |
| 189 | the working tree and advance the HEAD pointer to match next. |
| 190 | Otherwise, apply the changes introduced by those commits that |
| 191 | are in next but not HEAD to the current branch, creating a new |
| 192 | commit for each new change. |
| 193 | |
Jeff King | 6cf378f | 2012-04-26 04:51:57 -0400 | [diff] [blame] | 194 | `git rev-list --reverse master -- README | git cherry-pick -n --stdin`:: |
Christian Couder | f873a27 | 2010-06-14 00:29:38 -0500 | [diff] [blame] | 195 | |
| 196 | Apply the changes introduced by all commits on the master |
| 197 | branch that touched README to the working tree and index, |
| 198 | so the result can be inspected and made into a single new |
| 199 | commit if suitable. |
| 200 | |
Jonathan Nieder | 67ac1e1 | 2010-12-10 18:51:44 -0600 | [diff] [blame] | 201 | The following sequence attempts to backport a patch, bails out because |
| 202 | the code the patch applies to has changed too much, and then tries |
| 203 | again, this time exercising more care about matching up context lines. |
| 204 | |
| 205 | ------------ |
| 206 | $ git cherry-pick topic^ <1> |
| 207 | $ git diff <2> |
| 208 | $ git reset --merge ORIG_HEAD <3> |
| 209 | $ git cherry-pick -Xpatience topic^ <4> |
| 210 | ------------ |
| 211 | <1> apply the change that would be shown by `git show topic^`. |
| 212 | In this example, the patch does not apply cleanly, so |
| 213 | information about the conflict is written to the index and |
| 214 | working tree and no new commit results. |
| 215 | <2> summarize changes to be reconciled |
| 216 | <3> cancel the cherry-pick. In other words, return to the |
| 217 | pre-cherry-pick state, preserving any local modifications you had in |
| 218 | the working tree. |
| 219 | <4> try to apply the change introduced by `topic^` again, |
| 220 | spending extra time to avoid mistakes based on incorrectly matching |
| 221 | context lines. |
| 222 | |
Christian Couder | 89d32d3 | 2010-06-02 07:58:40 +0200 | [diff] [blame] | 223 | SEE ALSO |
| 224 | -------- |
| 225 | linkgit:git-revert[1] |
| 226 | |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 227 | GIT |
| 228 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 229 | Part of the linkgit:git[1] suite |