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