| 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 | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 15 | |
| 16 | Given one or more existing commits, apply the change each one |
| 17 | introduces, recording a new commit for each. This requires your |
| 18 | working tree to be clean (no modifications from the HEAD commit). |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 19 | |
| Junio C Hamano | a8cc1d8 | 2011-03-10 01:18:12 | [diff] [blame] | 20 | When it is not obvious how to apply a change, the following |
| 21 | happens: |
| 22 | |
| 23 | 1. The current branch and `HEAD` pointer stay at the last commit |
| 24 | successfully made. |
| 25 | 2. The `CHERRY_PICK_HEAD` ref is set to point at the commit that |
| 26 | introduced the change that is difficult to apply. |
| 27 | 3. Paths in which the change applied cleanly are updated both |
| 28 | in the index file and in your working tree. |
| 29 | 4. For conflicting paths, the index file records up to three |
| 30 | versions, as described in the "TRUE MERGE" section of |
| 31 | linkgit:git-merge[1]. The working tree files will include |
| 32 | a description of the conflict bracketed by the usual |
| 33 | conflict markers `<<<<<<<` and `>>>>>>>`. |
| 34 | 5. No other modifications are made. |
| 35 | |
| 36 | See linkgit:git-merge[1] for some hints on resolving such |
| 37 | conflicts. |
| 38 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 39 | OPTIONS |
| 40 | ------- |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 41 | <commit>...:: |
| 42 | Commits to cherry-pick. |
| Junio C Hamano | 78e3a78 | 2010-07-15 22:24:45 | [diff] [blame] | 43 | For a more complete list of ways to spell commits, see |
| Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 44 | linkgit:gitrevisions[7]. |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 45 | Sets of commits can be passed but no traversal is done by |
| 46 | default, as if the '--no-walk' option was specified, see |
| 47 | linkgit:git-rev-list[1]. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 48 | |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 49 | -e:: |
| 50 | --edit:: |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 51 | With this option, 'git cherry-pick' will let you edit the commit |
| Junio C Hamano | 0e66113 | 2008-01-21 02:37:44 | [diff] [blame] | 52 | message prior to committing. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 53 | |
| Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 54 | -x:: |
| Junio C Hamano | b77f819 | 2011-05-05 01:30:38 | [diff] [blame] | 55 | When recording the commit, append a line that says |
| 56 | "(cherry picked from commit ...)" to the original commit |
| 57 | message in order to indicate which commit this change was |
| 58 | cherry-picked from. This is done only for cherry |
| Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 59 | picks without conflicts. Do not use this option if |
| 60 | you are cherry-picking from your private branch because |
| 61 | the information is useless to the recipient. If on the |
| Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 62 | other hand you are cherry-picking between two publicly |
| 63 | visible branches (e.g. backporting a fix to a |
| 64 | maintenance branch for an older release from a |
| 65 | development branch), adding this information can be |
| 66 | useful. |
| 67 | |
| Junio C Hamano | 81c711d | 2007-04-20 07:20:14 | [diff] [blame] | 68 | -r:: |
| Junio C Hamano | af2b8c5 | 2006-10-06 01:00:40 | [diff] [blame] | 69 | It used to be that the command defaulted to do `-x` |
| 70 | described above, and `-r` was to disable it. Now the |
| 71 | 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] | 72 | |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 73 | -m parent-number:: |
| 74 | --mainline parent-number:: |
| Junio C Hamano | 69a9858 | 2008-03-01 18:42:18 | [diff] [blame] | 75 | 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] | 76 | side of the merge should be considered the mainline. This |
| 77 | option specifies the parent number (starting from 1) of |
| 78 | the mainline and allows cherry-pick to replay the change |
| 79 | relative to the specified parent. |
| 80 | |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 81 | -n:: |
| 82 | --no-commit:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 83 | Usually the command automatically creates a sequence of commits. |
| 84 | This flag applies the changes necessary to cherry-pick |
| 85 | each named commit to your working tree and the index, |
| 86 | without making any commit. In addition, when this |
| Junio C Hamano | 8dae8cd | 2008-11-24 05:38:55 | [diff] [blame] | 87 | option is used, your index does not have to match the |
| 88 | HEAD commit. The cherry-pick is done against the |
| Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 89 | beginning state of your index. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 90 | + |
| 91 | This is useful when cherry-picking more than one commits' |
| Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 92 | effect to your index in a row. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 93 | |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 94 | -s:: |
| 95 | --signoff:: |
| Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 96 | Add Signed-off-by line at the end of the commit message. |
| 97 | |
| Junio C Hamano | 961e052 | 2010-03-29 07:49:20 | [diff] [blame] | 98 | --ff:: |
| 99 | If the current HEAD is the same as the parent of the |
| 100 | cherry-pick'ed commit, then a fast forward to this commit will |
| 101 | be performed. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 102 | |
| Junio C Hamano | 23e3f53 | 2011-02-10 02:05:29 | [diff] [blame] | 103 | --strategy=<strategy>:: |
| 104 | Use the given merge strategy. Should only be used once. |
| 105 | See the MERGE STRATEGIES section in linkgit:git-merge[1] |
| 106 | for details. |
| 107 | |
| 108 | -X<option>:: |
| 109 | --strategy-option=<option>:: |
| 110 | Pass the merge strategy-specific option through to the |
| 111 | merge strategy. See linkgit:git-merge[1] for details. |
| 112 | |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 113 | EXAMPLES |
| 114 | -------- |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 115 | `git cherry-pick master`:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 116 | |
| 117 | Apply the change introduced by the commit at the tip of the |
| 118 | master branch and create a new commit with this change. |
| 119 | |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 120 | `git cherry-pick ..master`:: |
| 121 | `git cherry-pick ^HEAD master`:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 122 | |
| 123 | Apply the changes introduced by all commits that are ancestors |
| 124 | of master but not of HEAD to produce new commits. |
| 125 | |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 126 | `git cherry-pick master{tilde}4 master{tilde}2`:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 127 | |
| 128 | Apply the changes introduced by the fifth and third last |
| 129 | commits pointed to by master and create 2 new commits with |
| 130 | these changes. |
| 131 | |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 132 | `git cherry-pick -n master~1 next`:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 133 | |
| 134 | Apply to the working tree and the index the changes introduced |
| 135 | by the second last commit pointed to by master and by the last |
| 136 | commit pointed to by next, but do not create any commit with |
| 137 | these changes. |
| 138 | |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 139 | `git cherry-pick --ff ..next`:: |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 140 | |
| 141 | If history is linear and HEAD is an ancestor of next, update |
| 142 | the working tree and advance the HEAD pointer to match next. |
| 143 | Otherwise, apply the changes introduced by those commits that |
| 144 | are in next but not HEAD to the current branch, creating a new |
| 145 | commit for each new change. |
| 146 | |
| Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 147 | `git rev-list --reverse master \-- README | git cherry-pick -n --stdin`:: |
| Junio C Hamano | 7d44952 | 2010-07-01 00:08:51 | [diff] [blame] | 148 | |
| 149 | Apply the changes introduced by all commits on the master |
| 150 | branch that touched README to the working tree and index, |
| 151 | so the result can be inspected and made into a single new |
| 152 | commit if suitable. |
| 153 | |
| Junio C Hamano | 23e3f53 | 2011-02-10 02:05:29 | [diff] [blame] | 154 | The following sequence attempts to backport a patch, bails out because |
| 155 | the code the patch applies to has changed too much, and then tries |
| 156 | again, this time exercising more care about matching up context lines. |
| 157 | |
| 158 | ------------ |
| 159 | $ git cherry-pick topic^ <1> |
| 160 | $ git diff <2> |
| 161 | $ git reset --merge ORIG_HEAD <3> |
| 162 | $ git cherry-pick -Xpatience topic^ <4> |
| 163 | ------------ |
| 164 | <1> apply the change that would be shown by `git show topic^`. |
| 165 | In this example, the patch does not apply cleanly, so |
| 166 | information about the conflict is written to the index and |
| 167 | working tree and no new commit results. |
| 168 | <2> summarize changes to be reconciled |
| 169 | <3> cancel the cherry-pick. In other words, return to the |
| 170 | pre-cherry-pick state, preserving any local modifications you had in |
| 171 | the working tree. |
| 172 | <4> try to apply the change introduced by `topic^` again, |
| 173 | spending extra time to avoid mistakes based on incorrectly matching |
| 174 | context lines. |
| 175 | |
| Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 176 | SEE ALSO |
| 177 | -------- |
| 178 | linkgit:git-revert[1] |
| 179 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 180 | GIT |
| 181 | --- |
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 182 | Part of the linkgit:git[1] suite |