146

我已经使用Git Extensions有一段时间了(太棒了!),但我还没有找到以下问题的简单答案:

有时,在输入提交信息时,会出现拼写错误。我的朋友向我展示了如何通过以下方式修复它(在 Git 扩展中):

右键单击提交 > 高级 > 修复提交

在此处输入图像描述

然后我只需选中“修改”框并重写我的信息,瞧!我的提交信息是固定的。

然而,另一个选项“Squash commit”......我一直想知道它的作用是什么?!

我的问题是:

有人能简单地解释一下Git/Git 扩展中的Squash 提交Fixup 提交之间的确切区别是什么吗?他们看起来有点……和我“相似”在此处输入图像描述 在此处输入图像描述

4

7 回答 7

185

我不知道 Git Extensions 专门用它做什么,但git rebase可以选择使用 squash 自动压缩或修复提交!或修复!前缀,分别:

   --autosquash, --no-autosquash
       When the commit log message begins with "squash! ..." (or "fixup!
       ..."), and there is a commit whose title begins with the same ...,
       automatically modify the todo list of rebase -i so that the commit
       marked for squashing comes right after the commit to be modified,
       and change the action of the moved commit from pick to squash (or
       fixup).

squash 和 fixup 的区别在于,在 rebase 期间,squash操作会提示您合并原始和 squash 提交的消息,而fixup操作会保留原始消息并丢弃来自 fixup 提交的消息。

于 2013-05-26T11:11:07.590 回答
83

简而言之,在对一系列提交进行变基时,每个标记为 a 的提交都squash让您有机会将其消息用作 apickreword提交消息的一部分。

当您使用fixup来自该提交的消息时,将被丢弃。

于 2014-07-11T14:20:19.740 回答
34

如果问题是执行git rebase --interactivesquash时 git和in之间有什么区别,那么答案就是提交消息fixup

s, squash <commit>= 使用提交,但融合到之前的提交中

f, fixup <commit>= 类似“squash”,但丢弃此提交的日志消息


例如:

pick 22a4667 father commit message
squash 46d7c0d child commit message # case 1
# fixup 46d7c0d child commit message # case 2

案例 1中变基后的提交消息将是:

father commit message

child commit message

而案例 2 中的提交消息是:

father commit message
# no sub messages
于 2019-12-29T20:55:22.393 回答
16

来自git-rebase doc,“交互模式”部分

如果要将两个或多个提交合并为一个,请将第二个和后续提交的命令“pick”替换为“squash”或“fixup”。如果提交有不同的作者,折叠的提交将归属于第一个提交的作者。折叠提交的建议提交消息是第一个提交的提交消息和使用“squash”命令的提交消息的串联,但省略了使用“fixup”命令的提交的提交消息。

于 2015-03-12T13:48:54.550 回答
5

两者squashfixup允许代码更改由它们各自的差异引入。(通常不提及)

squash和之间的区别在于fixup如何处理提交消息

在这种fixup情况下,原始提交消息保持不变,并且fixup提交消息中的任何文本都被忽略(毫不客气地转储)。

在这种squash情况下,两个提交消息一个接一个地组合(“融合”),并提供给用户的编辑器,以便用户可以根据需要将它们合并/融合在一起。

初始组合消息(壁球)将包含注释标记,显示消息的开始和结束位置。可以应用多个squashand 。fixup

在讨论小的代码更正(无需更改消息)时,术语可能会令人困惑,因为通常人们可能会建议代码被“压缩”,squash而实际上并不需要 a。

于 2021-08-27T12:53:41.537 回答
2

我修补了 git 扩展,但无法将许多提交压缩为一个。为此,我不得不求助于命令行,发现这篇文章很有帮助

git rebase -i Head~2

这是交互式变基,请注意以下几点:

  • ~2 这里指的是你想在这个操作中涉及多少次提交,包括当前的头部
  • 您必须编辑随后的交互式编辑窗口,将第一项保留为“pick”并将后续行替换为“squash”。如果这是不透明的,上面链接中的说明会更清楚。
于 2015-05-08T17:15:44.353 回答
0

为什么不问问 git 本身?当你 rebase 时git-bash,它​​说:

pick 512b1d7 (some comment)
# Rebase 621b2e4..512b1d7 onto 621b2e4 (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
D:/code/fenixito-legacy-api/.git/rebase-merge/git-rebase-todo [unix] (11:57 23/10/2019)                                         1,1 start
"D:/code/xxx/.git/rebase-merge/git-rebase-todo" [UNIX] 27L, 1170C

所以你看:

s, squash = 使用提交,但融合到之前的提交中

f, fixup = like "squash", 但丢弃这个提交的日志信息

于 2019-10-23T09:58:54.800 回答