git 樱桃挑选并将一系列提交压缩到子目录或子树中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35123108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cherry-pick and squash a range of commits into a subdirectory or subtree
提问by donquixote
How can I tell cherry-pick to pick a squashed range of commits?
我如何告诉cherry-pick 选择一个压缩范围的提交?
Or in other words, apply the diff between two commits to the current state of the repository?
或者换句话说,将两次提交之间的差异应用于存储库的当前状态?
The following does notwork (cherry-pick has no --squash option):
下面确实没有工作(摘樱桃没有--squash选项):
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.
以下工作,但后来我有一系列单独的提交。之后我可以使用交互式 rebase 手动压缩它们。
git cherry-pick -X subtree=vendor/package e064480..eab48b59c
Is there any way to do the squashing as part of the cherry-pick?
有什么办法可以将挤压作为樱桃采摘的一部分吗?
回答by David Deutsch
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.
通过-n
对git cherry-pick
。这将应用所有提交,但不会提交它们。然后只需git commit
在一次提交中提交所有更改即可。