简体   繁体   English

如何在合并分支上压缩Git提交

[英]How do I squash Git commits on a branch with merges

I usually never do this but this time I wound up with a feature branch that, for update purposes, got master merged into it (I usually favour rebase master on my feature branch to avoid useless merge commits). 我通常从来没有这样做,但这次我结束了一个功能分支,为了更新的目的,让master合并到它(我通常喜欢我的功能分支上的rebase master以避免无用的合并提交)。

And now I want to squash all commits of my feature branch into one before merging it as finalised to master but it is not as seamless as it usually is. 现在我想将我的功能分支的所有提交压缩成一个,然后将其合并为最终版本,但它不像通常那样无缝。

How can I do that? 我怎样才能做到这一点?

Simplest way would be to merge all the changes as single commit using merge --squash 最简单的方法是使用merge --squash将所有更改合并为单个提交

git checkout master
git merge --squash feature_branch
git commit -a

Note: However, this doesn't really do a merge. 注意:但是,这并没有真正进行合并。 It is more akin to doing a single commit on master itself. 它更像是对master本身进行一次提交。 That's why I always mention the name of the merged branch explicitly in commit message. 这就是为什么我总是在提交消息中明确提到合并分支的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM