Documentation / git-cherry-pick.txton commit fast-export: do automatic reencoding of commit messages only if requested (e80001f)
   1git-cherry-pick(1)
   2==================
   3
   4NAME
   5----
   6git-cherry-pick - Apply the changes introduced by some existing commits
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
  12                  [-S[<keyid>]] <commit>...
  13'git cherry-pick' --continue
  14'git cherry-pick' --quit
  15'git cherry-pick' --abort
  16
  17DESCRIPTION
  18-----------
  19
  20Given one or more existing commits, apply the change each one
  21introduces, recording a new commit for each.  This requires your
  22working tree to be clean (no modifications from the HEAD commit).
  23
  24When it is not obvious how to apply a change, the following
  25happens:
  26
  271. The current branch and `HEAD` pointer stay at the last commit
  28   successfully made.
  292. The `CHERRY_PICK_HEAD` ref is set to point at the commit that
  30   introduced the change that is difficult to apply.
  313. Paths in which the change applied cleanly are updated both
  32   in the index file and in your working tree.
  334. 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 `>>>>>>>`.
  385. No other modifications are made.
  39
  40See linkgit:git-merge[1] for some hints on resolving such
  41conflicts.
  42
  43OPTIONS
  44-------
  45<commit>...::
  46        Commits to cherry-pick.
  47        For a more complete list of ways to spell commits, see
  48        linkgit:gitrevisions[7].
  49        Sets of commits can be passed but no traversal is done by
  50        default, as if the `--no-walk` option was specified, see
  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').
  54
  55-e::
  56--edit::
  57        With this option, 'git cherry-pick' will let you edit the commit
  58        message prior to committing.
  59
  60-x::
  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
  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
  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
  74-r::
  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.
  78
  79-m parent-number::
  80--mainline parent-number::
  81        Usually you cannot cherry-pick a merge because you do not know which
  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
  87-n::
  88--no-commit::
  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
  93        option is used, your index does not have to match the
  94        HEAD commit.  The cherry-pick is done against the
  95        beginning state of your index.
  96+
  97This is useful when cherry-picking more than one commits'
  98effect to your index in a row.
  99
 100-s::
 101--signoff::
 102        Add Signed-off-by line at the end of the commit message.
 103        See the signoff option in linkgit:git-commit[1] for more information.
 104
 105-S[<keyid>]::
 106--gpg-sign[=<keyid>]::
 107        GPG-sign commits. The `keyid` argument is optional and
 108        defaults to the committer identity; if specified, it must be
 109        stuck to the option without a space.
 110
 111--ff::
 112        If the current HEAD is the same as the parent of the
 113        cherry-pick'ed commit, then a fast forward to this commit will
 114        be performed.
 115
 116--allow-empty::
 117        By default, cherry-picking an empty commit will fail,
 118        indicating that an explicit invocation of `git commit
 119        --allow-empty` is required. This option overrides that
 120        behavior, allowing empty commits to be preserved automatically
 121        in a cherry-pick. Note that when "--ff" is in effect, empty
 122        commits that meet the "fast-forward" requirement will be kept
 123        even without this option.  Note also, that use of this option only
 124        keeps commits that were initially empty (i.e. the commit recorded the
 125        same tree as its parent).  Commits which are made empty due to a
 126        previous commit are dropped.  To force the inclusion of those commits
 127        use `--keep-redundant-commits`.
 128
 129--allow-empty-message::
 130        By default, cherry-picking a commit with an empty message will fail.
 131        This option overrides that behavior, allowing commits with empty
 132        messages to be cherry picked.
 133
 134--keep-redundant-commits::
 135        If a commit being cherry picked duplicates a commit already in the
 136        current history, it will become empty.  By default these
 137        redundant commits cause `cherry-pick` to stop so the user can
 138        examine the commit. This option overrides that behavior and
 139        creates an empty commit object.  Implies `--allow-empty`.
 140
 141--strategy=<strategy>::
 142        Use the given merge strategy.  Should only be used once.
 143        See the MERGE STRATEGIES section in linkgit:git-merge[1]
 144        for details.
 145
 146-X<option>::
 147--strategy-option=<option>::
 148        Pass the merge strategy-specific option through to the
 149        merge strategy.  See linkgit:git-merge[1] for details.
 150
 151--rerere-autoupdate::
 152--no-rerere-autoupdate::
 153        Allow the rerere mechanism to update the index with the
 154        result of auto-conflict resolution if possible.
 155
 156SEQUENCER SUBCOMMANDS
 157---------------------
 158include::sequencer.txt[]
 159
 160EXAMPLES
 161--------
 162`git cherry-pick master`::
 163
 164        Apply the change introduced by the commit at the tip of the
 165        master branch and create a new commit with this change.
 166
 167`git cherry-pick ..master`::
 168`git cherry-pick ^HEAD master`::
 169
 170        Apply the changes introduced by all commits that are ancestors
 171        of master but not of HEAD to produce new commits.
 172
 173`git cherry-pick maint next ^master`::
 174`git cherry-pick maint master..next`::
 175
 176        Apply the changes introduced by all commits that are
 177        ancestors of maint or next, but not master or any of its
 178        ancestors.  Note that the latter does not mean `maint` and
 179        everything between `master` and `next`; specifically,
 180        `maint` will not be used if it is included in `master`.
 181
 182`git cherry-pick master~4 master~2`::
 183
 184        Apply the changes introduced by the fifth and third last
 185        commits pointed to by master and create 2 new commits with
 186        these changes.
 187
 188`git cherry-pick -n master~1 next`::
 189
 190        Apply to the working tree and the index the changes introduced
 191        by the second last commit pointed to by master and by the last
 192        commit pointed to by next, but do not create any commit with
 193        these changes.
 194
 195`git cherry-pick --ff ..next`::
 196
 197        If history is linear and HEAD is an ancestor of next, update
 198        the working tree and advance the HEAD pointer to match next.
 199        Otherwise, apply the changes introduced by those commits that
 200        are in next but not HEAD to the current branch, creating a new
 201        commit for each new change.
 202
 203`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::
 204
 205        Apply the changes introduced by all commits on the master
 206        branch that touched README to the working tree and index,
 207        so the result can be inspected and made into a single new
 208        commit if suitable.
 209
 210The following sequence attempts to backport a patch, bails out because
 211the code the patch applies to has changed too much, and then tries
 212again, this time exercising more care about matching up context lines.
 213
 214------------
 215$ git cherry-pick topic^             <1>
 216$ git diff                           <2>
 217$ git reset --merge ORIG_HEAD        <3>
 218$ git cherry-pick -Xpatience topic^  <4>
 219------------
 220<1> apply the change that would be shown by `git show topic^`.
 221    In this example, the patch does not apply cleanly, so
 222    information about the conflict is written to the index and
 223    working tree and no new commit results.
 224<2> summarize changes to be reconciled
 225<3> cancel the cherry-pick.  In other words, return to the
 226    pre-cherry-pick state, preserving any local modifications
 227    you had in the working tree.
 228<4> try to apply the change introduced by `topic^` again,
 229    spending extra time to avoid mistakes based on incorrectly
 230    matching context lines.
 231
 232SEE ALSO
 233--------
 234linkgit:git-revert[1]
 235
 236GIT
 237---
 238Part of the linkgit:git[1] suite