Cherry-pick and squash a range of commits into a subdirectory or subtree
Pass -n
to git cherry-pick
. This will apply all the commits, but not commit them. Then simply do git commit
to commit all the changes in a single commit.
Useful alternative vs git cherry-pick -n
for some use cases might be git merge --squash
- for example, when you want to test a feature branch's changes on top of your integration branch, without rebasing.
Source: What's the difference between git merge --squash and git cherry-pick?
Follow from master → cherry pick two commit from another branch
git checkout mastergit cherry-pick :1 git cherry-pick :2git reset --soft HEAD~2 (number of cherry pick commits, i.e 2 ) git add . git commit