Home Explore Blog CI



git

4th chunk of `Documentation/git-cherry-pick.adoc`
7f9bd71f3ab115d9cb01185dd009b6b839e8e0f0029ad4f00000000100000bf6
 linkgit:git-merge[1]
	for details.

-X<option>::
--strategy-option=<option>::
	Pass the merge strategy-specific option through to the
	merge strategy.  See linkgit:git-merge[1] for details.

include::rerere-options.adoc[]

SEQUENCER SUBCOMMANDS
---------------------
include::sequencer.adoc[]

EXAMPLES
--------
`git cherry-pick master`::

	Apply the change introduced by the commit at the tip of the
	master branch and create a new commit with this change.

`git cherry-pick ..master`::
`git cherry-pick ^HEAD master`::

	Apply the changes introduced by all commits that are ancestors
	of master but not of HEAD to produce new commits.

`git cherry-pick maint next ^master`::
`git cherry-pick maint master..next`::

	Apply the changes introduced by all commits that are
	ancestors of maint or next, but not master or any of its
	ancestors.  Note that the latter does not mean `maint` and
	everything between `master` and `next`; specifically,
	`maint` will not be used if it is included in `master`.

`git cherry-pick master~4 master~2`::

	Apply the changes introduced by the fifth and third last
	commits pointed to by master and create 2 new commits with
	these changes.

`git cherry-pick -n master~1 next`::

	Apply to the working tree and the index the changes introduced
	by the second last commit pointed to by master and by the last
	commit pointed to by next, but do not create any commit with
	these changes.

`git cherry-pick --ff ..next`::

	If history is linear and HEAD is an ancestor of next, update
	the working tree and advance the HEAD pointer to match next.
	Otherwise, apply the changes introduced by those commits that
	are in next but not HEAD to the current branch, creating a new
	commit for each new change.

`git rev-list --reverse master -- README | git cherry-pick -n --stdin`::

	Apply the changes introduced by all commits on the master
	branch that touched README to the working tree and index,
	so the result can be inspected and made into a single new
	commit if suitable.

The following sequence attempts to backport a patch, bails out because
the code the patch applies to has changed too much, and then tries
again, this time exercising more care about matching up context lines.

------------
$ git cherry-pick topic^             <1>
$ git diff                           <2>
$ git cherry-pick --abort            <3>
$ git cherry-pick -Xpatience topic^  <4>
------------
<1> apply the change that would be shown by `git show topic^`.
    In this example, the patch does not apply cleanly, so
    information about the conflict is written to the index and
    working tree and no new commit results.
<2> summarize changes to be reconciled
<3> cancel the cherry-pick.  In other words, return to the
    pre-cherry-pick state, preserving any local modifications
    you had in the working tree.
<4> try to apply the change introduced by `topic^` again,
    spending extra time to avoid mistakes based on incorrectly
    matching context lines.

SEE ALSO
--------
linkgit:git-revert[1]

GIT
---
Part of the linkgit:git[1] suite

Title: Git Cherry-Pick Command Options and Usage Examples
Summary
The git cherry-pick command allows for applying changes from specific commits or branches, with options to customize behavior, such as handling empty commits, redundant commits, and merge strategies, and includes examples demonstrating how to use the command in various scenarios, including backporting patches and reconciling conflicts.