Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-cherry-pick(1) |
| 2 | ================== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 6 | git-cherry-pick - Apply the changes introduced by some existing commits |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 10 | [verse] |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 11 | 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>... |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 12 | 'git cherry-pick' --continue |
Junio C Hamano | f0944d0 | 2011-11-30 20:46:29 | [diff] [blame] | 13 | 'git cherry-pick' --quit |
| 14 | 'git cherry-pick' --abort |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
| 16 | DESCRIPTION |
| 17 | ----------- |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 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). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 22 | |
Junio C Hamano | a8cc1d8 | 2011-03-10 01:18:12 | [diff] [blame] | 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 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 42 | OPTIONS |
| 43 | ------- |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 44 | <commit>...:: |
| 45 | Commits to cherry-pick. |
Junio C Hamano | 78e3a78 | 2010-07-15 22:24:45 | [diff] [blame] | 46 | For a more complete list of ways to spell commits, see |
Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 47 | linkgit:gitrevisions[7]. |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 48 | Sets of commits can be passed but no traversal is done by |
| 49 | default, as if the '--no-walk' option was specified, see |
Junio C Hamano | 9257a33 | 2012-06-25 20:01:02 | [diff] [blame] | 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'). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 53 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 54 | -e:: |
| 55 | --edit:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 56 | With this option, 'git cherry-pick' will let you edit the commit |
Junio C Hamano | 0e66113 | 2008-01-21 02:37:44 | [diff] [blame] | 57 | message prior to committing. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 58 | |
Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 59 | -x:: |
Junio C Hamano | b77f819 | 2011-05-05 01:30:38 | [diff] [blame] | 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 |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 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 |
Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 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 | |
Junio C Hamano | 81c711d | 2007-04-20 07:20:14 | [diff] [blame] | 73 | -r:: |
Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 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. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 77 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 78 | -m parent-number:: |
| 79 | --mainline parent-number:: |
Junio C Hamano | 69a9858 | 2008-03-01 18:42:18 | [diff] [blame] | 80 | Usually you cannot cherry-pick a merge because you do not know which |
Junio C Hamano | d814b6d | 2007-11-04 11:13:49 | [diff] [blame] | 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 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 86 | -n:: |
| 87 | --no-commit:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 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 |
Junio C Hamano | 8dae8cd | 2008-11-24 05:38:55 | [diff] [blame] | 92 | option is used, your index does not have to match the |
| 93 | HEAD commit. The cherry-pick is done against the |
Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 94 | beginning state of your index. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 95 | + |
| 96 | This is useful when cherry-picking more than one commits' |
Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 97 | effect to your index in a row. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 98 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 99 | -s:: |
| 100 | --signoff:: |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 101 | Add Signed-off-by line at the end of the commit message. |
| 102 | |
Junio C Hamano | 961e052 | 2010-03-29 07:49:20 | [diff] [blame] | 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. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 107 | |
Junio C Hamano | 37e389e | 2012-04-30 22:36:09 | [diff] [blame] | 108 | --allow-empty:: |
| 109 | By default, cherry-picking an empty commit will fail, |
| 110 | indicating that an explicit invocation of `git commit |
| 111 | --allow-empty` is required. This option overrides that |
| 112 | behavior, allowing empty commits to be preserved automatically |
| 113 | in a cherry-pick. Note that when "--ff" is in effect, empty |
| 114 | commits that meet the "fast-forward" requirement will be kept |
| 115 | even without this option. Note also, that use of this option only |
| 116 | keeps commits that were initially empty (i.e. the commit recorded the |
| 117 | same tree as its parent). Commits which are made empty due to a |
| 118 | previous commit are dropped. To force the inclusion of those commits |
| 119 | use `--keep-redundant-commits`. |
| 120 | |
Junio C Hamano | f335393 | 2012-09-04 23:16:51 | [diff] [blame] | 121 | --allow-empty-message:: |
| 122 | By default, cherry-picking a commit with an empty message will fail. |
| 123 | This option overrides that behaviour, allowing commits with empty |
| 124 | messages to be cherry picked. |
| 125 | |
Junio C Hamano | 37e389e | 2012-04-30 22:36:09 | [diff] [blame] | 126 | --keep-redundant-commits:: |
| 127 | If a commit being cherry picked duplicates a commit already in the |
| 128 | current history, it will become empty. By default these |
| 129 | redundant commits are ignored. This option overrides that behavior and |
| 130 | creates an empty commit object. Implies `--allow-empty`. |
| 131 | |
Junio C Hamano | 23e3f53 | 2011-02-10 02:05:29 | [diff] [blame] | 132 | --strategy=<strategy>:: |
| 133 | Use the given merge strategy. Should only be used once. |
| 134 | See the MERGE STRATEGIES section in linkgit:git-merge[1] |
| 135 | for details. |
| 136 | |
| 137 | -X<option>:: |
| 138 | --strategy-option=<option>:: |
| 139 | Pass the merge strategy-specific option through to the |
| 140 | merge strategy. See linkgit:git-merge[1] for details. |
| 141 | |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 142 | SEQUENCER SUBCOMMANDS |
| 143 | --------------------- |
| 144 | include::sequencer.txt[] |
| 145 | |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 146 | EXAMPLES |
| 147 | -------- |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 148 | `git cherry-pick master`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 149 | |
| 150 | Apply the change introduced by the commit at the tip of the |
| 151 | master branch and create a new commit with this change. |
| 152 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 153 | `git cherry-pick ..master`:: |
| 154 | `git cherry-pick ^HEAD master`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 155 | |
| 156 | Apply the changes introduced by all commits that are ancestors |
| 157 | of master but not of HEAD to produce new commits. |
| 158 | |
Junio C Hamano | 9257a33 | 2012-06-25 20:01:02 | [diff] [blame] | 159 | `git cherry-pick maint next ^master`:: |
| 160 | `git cherry-pick maint master..next`:: |
| 161 | |
| 162 | Apply the changes introduced by all commits that are |
| 163 | ancestors of maint or next, but not master or any of its |
| 164 | ancestors. Note that the latter does not mean `maint` and |
| 165 | everything between `master` and `next`; specifically, |
| 166 | `maint` will not be used if it is included in `master`. |
| 167 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 168 | `git cherry-pick master~4 master~2`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 169 | |
| 170 | Apply the changes introduced by the fifth and third last |
| 171 | commits pointed to by master and create 2 new commits with |
| 172 | these changes. |
| 173 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 174 | `git cherry-pick -n master~1 next`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 175 | |
| 176 | Apply to the working tree and the index the changes introduced |
| 177 | by the second last commit pointed to by master and by the last |
| 178 | commit pointed to by next, but do not create any commit with |
| 179 | these changes. |
| 180 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 181 | `git cherry-pick --ff ..next`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 182 | |
| 183 | If history is linear and HEAD is an ancestor of next, update |
| 184 | the working tree and advance the HEAD pointer to match next. |
| 185 | Otherwise, apply the changes introduced by those commits that |
| 186 | are in next but not HEAD to the current branch, creating a new |
| 187 | commit for each new change. |
| 188 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 189 | `git rev-list --reverse master -- README | git cherry-pick -n --stdin`:: |
Junio C Hamano | 7d44952 | 2010-07-01 00:08:51 | [diff] [blame] | 190 | |
| 191 | Apply the changes introduced by all commits on the master |
| 192 | branch that touched README to the working tree and index, |
| 193 | so the result can be inspected and made into a single new |
| 194 | commit if suitable. |
| 195 | |
Junio C Hamano | 23e3f53 | 2011-02-10 02:05:29 | [diff] [blame] | 196 | The following sequence attempts to backport a patch, bails out because |
| 197 | the code the patch applies to has changed too much, and then tries |
| 198 | again, this time exercising more care about matching up context lines. |
| 199 | |
| 200 | ------------ |
| 201 | $ git cherry-pick topic^ <1> |
| 202 | $ git diff <2> |
| 203 | $ git reset --merge ORIG_HEAD <3> |
| 204 | $ git cherry-pick -Xpatience topic^ <4> |
| 205 | ------------ |
| 206 | <1> apply the change that would be shown by `git show topic^`. |
| 207 | In this example, the patch does not apply cleanly, so |
| 208 | information about the conflict is written to the index and |
| 209 | working tree and no new commit results. |
| 210 | <2> summarize changes to be reconciled |
| 211 | <3> cancel the cherry-pick. In other words, return to the |
| 212 | pre-cherry-pick state, preserving any local modifications you had in |
| 213 | the working tree. |
| 214 | <4> try to apply the change introduced by `topic^` again, |
| 215 | spending extra time to avoid mistakes based on incorrectly matching |
| 216 | context lines. |
| 217 | |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 218 | SEE ALSO |
| 219 | -------- |
| 220 | linkgit:git-revert[1] |
| 221 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 222 | GIT |
| 223 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 224 | Part of the linkgit:git[1] suite |