git cherry-pick
When you want just a single commit from anywhere to be in your branch, use git cherry-pick
.
Examples
# get the last commit from some-branch
git cherry-pick some-branch
# get the second-to-last commit from some-branch
git cherry-pick some-branch^
# get the 15th-to-last commit from some-branch
git cherry-pick some-branch~14
# get the commit by its tag
git cherry-pick my-tag
# get some random commit from wherever
git cherry-pick ffee1234
What to do about conflicts
If you encounter a conflict when running git cherry-pick
, you should:
- Make your normal edits as you would when resolving conflicts normally
git add
the file(s) with the fixed conflicts- Run
git cherry-pick --continue