97

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?

4

3 回答 3

143

传给. -n_ git cherry-pick这将应用所有提交,但不提交它们。然后只需git commit在一次提交中提交所有更改。

于 2016-02-01T12:04:36.387 回答
5

对于某些用例而言,有用的替代方案git cherry-pick -n可能是git merge --squash- 例如,当您想在集成分支之上测试功能分支的更改时,而不需要变基。

资料来源:git merge --squash 和 git cherry-pick 有什么区别?

于 2020-10-14T17:06:32.487 回答
2

从 master 跟随 →cherry 从另一个分支中挑选两个提交

git checkout master
git cherry-pick :1  
git cherry-pick :2
git reset --soft HEAD~2 (number of cherry pick commits, i.e 2 ) 
git add . 
git commit
于 2020-09-22T09:28:23.883 回答