gpt4 book ai didi

git - 使用 "fixup!"或 "squash!"之间有什么真正的区别吗?

转载 作者:太空狗 更新时间:2023-10-29 13:37:24 36 4
gpt4 key购买 nike

我一直在阅读关于 commit 的 git 文档和 rebase , 但我仍然不明白使用 fixup! 之间的区别或 squash!在执行 rebase --autosquash 时作为提交消息的前缀.我相信我明白了什么fixup!fixing previous commits 方面做, 但我没有看到一个很好的例子 squash!而是使用。任何人都可以澄清两者之间的区别并给出一些不同使用它们的上下文吗?提前致谢!

最佳答案

正如我在“Trimming Git Commits/Squashing Git History”中说明的那样,总结一下:

with the fixup! directive, you could keep that squashing "invisible" in the commit message, while still benefiting from the automatic commit reordering with the --autosquash option

作为Op Dash评论:

Using squash! will guarantee that the squashing operation is recorded in the history, which is unlike fixup! where the squash operation is invisible for a more "cleaner" approach.


在 Git 2.16.x/2.17(2018 年第 1 季度)之前,另一个区别是您不能将“git commit --fixup”与额外的提交消息结合起来。< br/>现在不再是这种情况。

参见 commit 30884c9 (2017 年 12 月 22 日)Ævar Arnfjörð Bjarmason ( avar ) .
帮助:Eric Sunshine ( sunshineco ) .
(由 Ævar Arnfjörð Bjarmason -- avar -- merge 于 commit 30884c9 ,2017 年 12 月 22 日)

commit: add support for --fixup <commit> -m"<extra message>"

Add support for supplying the -m option with --fixup.
Doing so has errored out ("Option -m cannot be combined") ever since --fixup was introduced.
Before this, the only way to amend the fixup message while committing was to use --edit and amend it in the editor.

The use-case for this feature is one of:

  • Leaving a quick note to self when creating a --fixup commit when it's not self-evident why the commit should be squashed without a note into another one.

  • (Ab)using the --fixup feature to "fix up" commits that have already been pushed to a branch that doesn't allow non-fast-forwards,
    i.e. just noting "this should have been part of that other commit", and if the history ever got rewritten in the future the two should be combined.

In such a case you might want to leave a small message,
e.g. "forgot this part, which broke XYZ".


请注意,在 Git 2.17(2018 年第 2 季度)之前,“git commit --fixup”不允许同时使用“-m<message>”选项;允许它用更多文本注释结果提交。

参见 commit 30884c9 , commit f55e84f (2017 年 12 月 22 日)Ævar Arnfjörð Bjarmason ( avar ) .
帮助:Eric Sunshine ( sunshineco ) .
(由 Junio C Hamano -- gitster -- merge 于 commit c1ab3b8 ,2018 年 2 月 27 日)

commit: add support for --fixup <commit> -m"<extra message>"

Add support for supplying the -m option with --fixup. Doing so has errored out ever since --fixup was introduced. Before this, the only way to amend the fixup message while committing was to use --edit and amend it in the editor.

此功能的用例是以下之一:

  • Leaving a quick note to self when creating a --fixup commit when it's not self-evident why the commit should be squashed without a note into another one.

  • (Ab)using the --fixup feature to "fix up" commits that have already been pushed to a branch that doesn't allow non-fast-forwards, i.e. just noting "this should have been part of that other commit", and if the history ever got rewritten in the future the two should be combined.

    In such a case you might want to leave a small message, e.g. "forgot this part, which broke XYZ".

With this, --fixup <commit> -m"More" -m"Details" will result in a commit message like:

!fixup <subject of <commit>>

More

Details

When the --fixup option was initially added the "Option -m cannot be combined" error was expanded from -c, -C and -F to also include --fixup (commit d71b8ba, "commit: --fixup option for use with rebase --autosquash", 2010-11-02, Git 1.7.4-rc0)).

关于git - 使用 "fixup!"或 "squash!"之间有什么真正的区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39252866/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com