Git 扩展:Squash 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46733179/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:56:32  来源:igfitidea点击:

Git Extensions: Squash commits?

gitgit-extensions

提问by Slaknation

To squash multiple commits, I have always used:

为了压缩多个提交,我一直使用:

git reset --soft HEAD~<number of commits to squash> && git commit

But I wonder if there is a good way to do this in a good git client like git extensions? It would be cool if you could just select consecutive commits and squash them.

但是我想知道在像 git 扩展这样的好的 git 客户端中是否有一个很好的方法来做到这一点?如果您可以选择连续的提交并压缩它们,那就太酷了。

回答by RussKie

You can easily do it in GE:

您可以在 GE 中轻松完成:

  1. mixed reset to the commit you want to squash to
  2. stage and commit files you require
  3. done
  1. 混合重置为您想要压缩的提交
  2. 暂存和提交您需要的文件
  3. 完毕

How to squash:

如何压扁:

enter image description here

在此处输入图片说明

回答by user1682406

Here is the slowed down version of the accepted answer:

这是已接受答案的减慢版本:

Here is the slowed down version of the accepted answer

这是已接受答案的减慢版本

回答by Philippe

You could achieve this easily with GitExtensions by 2 ways.

您可以通过 2 种方式使用 GitExtensions 轻松实现这一点。

The firstis to do exactly the same thing but from the GUI which is suitable when you don't want to use the existing commit messages of the commits you watch to squash. .

第一个是做完全相同的事情,但是从 GUI 开始,当您不想使用您观看的提交的现有提交消息来压缩时,这是合适的。.

 git reset --soft HEAD~<number of commits to squash>

From the history browser of GitExtensions, right click on the last commit you want to keep and select 'reset branch to here'. Then select the option 'soft'.

在 GitExtensions 的历史浏览器中,右键单击要保留的最后一次提交并选择'reset branch to here'。然后选择选项'soft'

 git commit

Then commit the changes that are still staged.

然后提交仍处于暂存阶段的更改。

The secondis to a 'rebase --interactive' :

所述第二是为“重订--interactive”:

Right click on the same commit described above and select 'rebase on'. In the pop-up check the checkbox 'interactive'.

右键单击上述相同的提交并选择“rebase on”。在弹出窗口中选中“交互式”复选框。

Then, in the editor, set the commit action to 'squash'. Read a good documentation on the interactive rebase before doing it. This solution is perfect when you want to write a good commit message built from the commits messages from the commits you are squashing.

然后,在编辑器中,将提交操作设置为“挤压”。在做之前阅读关于交互式 rebase 的好文档。当您想根据您正在压缩的提交的提交消息编写良好的提交消息时,此解决方案是完美的。

回答by BoffinBrain

(Assuming you're using Windows)

(假设您使用的是 Windows)

Yes, I believe TortoiseGitcan do it. As a previous user of TortoiseSVN, I would recommend it. When viewing the commit log, you can do the following:

是的,我相信TortoiseGit可以做到。作为 TortoiseSVN 的前用户,我会推荐它。查看提交日志时,您可以执行以下操作:

Combine multiple commits context menu

Combine multiple commits context menu

In addition, when you commit using TortoiseGit, you'll have the option to simply amendyour previous commit, so you can do this as you go. It will also pull in the last commit message when you do this (I cleared mine for privacy reasons in the screenshot).

此外,当您使用 TortoiseGit提交时,您可以选择简单地修改之前的提交,这样您就可以随时进行。当您执行此操作时,它还会拉入最后一次提交消息(我在屏幕截图中出于隐私原因清除了我的)。

Amend last commit

Amend last commit

Of course, I'm sure you already know this, but don't try to combine or amend commits that are already pushed to remote, or your next push will fail miserably.

当然,我相信你已经知道这一点,但不要试图合并或修改已经推送到远程的提交,否则你的下一次推送将失败。

As an extra bonus, you'll get the benefits of overlay icons when browsing your working copy in Explorer.

作为额外的奖励,在资源管理器中浏览您的工作副本时,您将获得覆盖图标的好处。

Explorer icons

Explorer icons