简体   繁体   English

如何在Git中压缩提交,以便可以将我的上一次提交与结帐进行比较,而看不到临时提交?

[英]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: 例如:

  1. checkout code 结帐代码
  2. commit - make some changes also add debug code 提交-进行一些更改还添加调试代码
  3. commit - make some changes also add debug code 提交-进行一些更改还添加调试代码
  4. commit - make some changes, remove all debugging code 提交-进行一些更改,删除所有调试代码

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 ,改变picksquash了第一个之后的所有提交并保存文件。

After the rebase, you should see one commit instead of 3. 重新设置基准后,您应该看到一次提交而不是3次提交。

暂无
暂无

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

相关问题 在没有git commit的情况下,如何在git add和git checkout之后找回我的差异? - How can I get my diff back after git add and git checkout without git commit? 如何在不解决其他提交冲突的情况下在 git 中变基,或者压缩我的所有提交,同时不影响其他人的提交? - How can I rebase in git without resolving other commit conflicts, or squash all of my commits while leaving others' commits untouched? 如何将A和K之间的提交压缩到一个提交Z中 - How can I squash commits between A and K into one commit Z 如何删除git中的最后两个提交并在工作目录中将我的提交1作为更改? - How can I remove last two commits in git and get my commit 1 as changes in working directory? 我如何压缩 git 中提交日期不是过去的提交? - How do I squash commits in git with a commit date that is not in the past? PR 完成后如何 git squash commit? - How Can I git squash commit after PR completed? 如何在最近一次提交的情况下使用git checkout忽略所有先前的提交? - How can I git checkout with just last commit ignoring all previous commit? Git:将提交发送到另一个分支,以便我可以工作并合并回去,而无需(非常慢)结帐? - Git: send commit to another branch so I can work and merge back, without (very slow) checkout? 如何撤消我上次的git add / commit? - How can I undo my last git add/commit? 我如何从git压缩的提交中获取最后的提交 - How can i get the last commit from squashed commit in git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM