[英]How can I squash a commit in Git so that I can diff my last commit against the checkout without seeing the interim commits?
I'm using gitlab, and when I commit it gives the code reviewer an opportunity to diff a commit with a previous commit. 我正在使用gitlab,当我提交它时,它使代码审阅者有机会将提交与之前的提交进行区分。 Some of me commits have distracting debugging code, I don't want that stuff being presented in the merge request. 我的某些提交中有分散注意力的调试代码,我不希望这些内容出现在合并请求中。 For example: 例如:
So what I want is to be able to diff 4 against 1, but have all the "real" changes rolled up into 4 without any of the debugging code from 2 and 3. Basically, I want to hide some of my sausage making. 因此,我希望能够将4与1进行比较,但是将所有“实际”更改汇总为4,而无需使用2和3中的任何调试代码。基本上,我想隐藏一些香肠制作方法。 Is this possible? 这可能吗?
Assuming that you can use normal git
on the command line, and that the hash of the initial checkout is 454354
, you can use git rebase -i 454354
, and change the pick
to squash
for all the commits after the first one and then save the file. 假设你可以正常使用git
在命令行上,并且初始结账的哈希值是454354
,你可以使用git rebase -i 454354
,改变pick
到squash
了第一个之后的所有提交并保存文件。
After the rebase, you should see one commit instead of 3. 重新设置基准后,您应该看到一次提交而不是3次提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.