Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cherry-pick and squash a range of commits into a subdirectory or subtree

How can I tell cherry-pick to pick range of commits and squash it?

Or in other words, apply the diff between two commits to the current state of the repository?

The following does not work (cherry-pick has no --squash option):

git cherry-pick --squash e064480..eab48b59c 

Note: My use case is within a subtree scenario - before anyone starts arguing that I should not squash.

The following works, but then I have a range of separate commits. I can squash them manually with interactive rebase afterwards.

git cherry-pick -X subtree=vendor/package e064480..eab48b59c 

Is there any way to do the squashing as part of the cherry-pick?

like image 437
donquixote Avatar asked Feb 01 '16 04:02

donquixote


People also ask

Can you cherry pick a range of commits?

The thing is if you are cherry picking a range of commits, it will cherry pick the parent commits correctly but then when it hits a normal commit, it fails and says commit is not a merge.

What does cherry picking a commit do?

Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.


1 Answers

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.

like image 196
David Deutsch Avatar answered Sep 19 '22 13:09

David Deutsch