Git/Git 扩展中的“squash”和“fixup”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16758131/
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
What's the difference between "squash" and "fixup" in Git/Git Extension?
提问by Placeholder
I've been using Git Extensionsfor a while now (it's awesome!) but I haven't found a simple answer to the following:
我已经使用Git Extensions一段时间了(太棒了!)但我还没有找到以下问题的简单答案:
Sometimes, when typing a commit message, a make a typo. My friend showed me how to fix it the following way (in Git Extentions):
有时,在输入提交消息时,会打错字。我的朋友向我展示了如何通过以下方式修复它(在 Git 扩展中):
Right-Click on the commit > Advanced > Fixup commit
右键单击提交 > 高级 > 修复提交
Then I simply check the box "Amend" and rewrite my message and voila! My commit message is fixed.
然后我只需选中“修改”框并重写我的消息,瞧!我的提交消息已修复。
However this other option "Squash commit"... I have always wondered what it does?!
然而,另一个选项“壁球提交”......我一直想知道它的作用是什么?!
My question is:
我的问题是:
Would someone simply explain me what is the exact difference between Squash commitand Fixup commitin Git/Git Extentions? They look kind of... "similar"to me:
有人会简单的介绍一下我之间有什么准确的区别壁球承诺和Fixup时提交的混帐/ Git的一些推广?他们看起来有点......对我来说“相似”:
回答by drizzd
I do not know what Git Extensions does with it specifically, but git rebase
has an option to automatically squash or fixup commits with squash! or fixup! prefixes, respectively:
我不知道 Git Extensions 专门用它做什么,但git rebase
可以选择自动压缩或修复提交与壁球!或修复!前缀分别为:
--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).
The difference between squash and fixup is that during the rebase, the squash
operation will prompt you to combine the messages of the original and the squash commit, whereas the fixup
operation will keep the original message and discard the message from the fixup commit.
squash 和 fixup 的区别在于,在 rebase 期间,squash
操作会提示您合并原始和 squash 提交的消息,而fixup
操作将保留原始消息并丢弃来自 fixup 提交的消息。
回答by ocodo
Simply put, when rebasing a series of commits, each commit marked as a squash
, gives you the opportunity to use its message as part of a pick
or reword
commit message.
简而言之,当重新设置一系列提交时,每个提交都标记为 a squash
,让您有机会将其消息用作 apick
或reword
commit 消息的一部分。
When you use fixup
the message from that commit is discarded.
当您使用fixup
来自该提交的消息时,该消息将被丢弃。
回答by Paulo Lieuthier
From git-rebase doc, "interactive mode" section:
If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit message for the folded commit is the concatenation of the commit messages of the first commit and of those with the "squash" command, but omits the commit messages of commits with the "fixup" command.
如果要将两个或多个提交合并为一个,请将第二个和后续提交的命令“pick”替换为“squash”或“fixup”。如果提交有不同的作者,折叠提交将归于第一个提交的作者。折叠提交的建议提交消息是第一次提交的提交消息和使用“squash”命令的提交消息的串联,但省略了使用“fixup”命令的提交的提交消息。
回答by Loi Nguyen Huynh
Ifthe question is what's the difference between squash
and fixup
in git when doing git rebase --interactive, then the answer is the commit message.
如果问题是执行git rebase --interactive时gitsquash
和fixup
git之间的区别是什么,那么答案就是提交消息。
s, squash <commit>
= use commit, but meld into previous commit
f, fixup <commit>
= like "squash", but discard this commit's log message
s, squash <commit>
= 使用提交,但融入之前的提交
f, fixup <commit>
= 像“squash”,但是丢弃这个提交的日志信息
For example:
例如:
pick 22a4667 father commit message
squash 46d7c0d child commit message # case 1
# fixup 46d7c0d child commit message # case 2
The commit messageafter rebasing in case 1would be:
在第1 种情况下rebase 后的提交消息将是:
father commit message
child commit message
while the commit message in case 2 is:
而案例 2 中的提交消息是:
father commit message
# no sub messages
回答by BraveNewMath
I tinkered with git extensions and couldn't get it to squash many commits into one. To do that, I had to resort to the command line and found this posthelpful
我修改了 git 扩展,但无法将许多提交压缩为一个。为此,我不得不求助于命令行并发现这篇文章很有帮助
git rebase -i Head~2
This is interactive rebase, and note the following:
这是交互式 rebase,请注意以下几点:
- ~2 here refers to how many commits you want to involve in this operation, including the current head
- You have to edit the subsquent interactive edit window, leave the first item as "pick" and replace subsequent lines with "squash". The instructions in the link above are much clearer if this is opaque.
- ~2这里指的是这个操作要涉及多少个commit,包括当前head
- 您必须编辑随后的交互式编辑窗口,将第一项保留为“pick”,并将后续行替换为“squash”。如果这是不透明的,上面链接中的说明会更清楚。
回答by WesternGun
Why not ask git itself?
When you rebase with git-bash
, it says:
为什么不问问 git 本身呢?当你用 变基时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
So you see:
所以你看:
s, squash = use commit, but meld into previous commit
f, fixup = like "squash", but discard this commit's log message
s, squash = 使用提交,但融合到之前的提交中
f, fixup = like "squash", 但丢弃这个提交的日志信息