gpt4 book ai didi

git - Git merge --squash 可以保留提交注释吗?

转载 作者:太空狗 更新时间:2023-10-29 14:27:54 26 4
gpt4 key购买 nike

有没有一种方法可以在执行

时自动添加压缩的 mybranch提交中的所有提交注释
git merge --squash mybranch

以便单个提交包含来自 mybranch

的所有提交注释的串联

最佳答案

我认为这就是“git merge --squash”自动执行的操作!只需使用“git commit --no-edit”进行提交,我想这就是你会得到的。在运行“git merge --squash”命令后,我立即在 .git/SQUASH_MSG 中看到了所有提交消息。你呢?

就我个人而言,我挤入 master,然后将结果强制推回我的主题分支。这样我的最终提交可以通过 pull 请求进行代码审查。

实例(尝试这些确切的命令,这使用我的演示服务器,并且确实有效):

git clone http://vm.bit-booster.com/bitbucket/scm/bb/rebase-example-2.git
cd rebase-example-2
git checkout branch
git reset --hard origin/master
git merge --squash origin/branch
git commit --no-edit

git show
commit 74656c51212526af49382c985419244737141217
Author: G. Sylvie Davies <sylvie@bit-booster.com>
Date: Mon Dec 26 22:07:50 2016 -0800

Squashed commit of the following:

commit 3120cbba4e94e0a81eed2f9ff42e7012cca996bf
Author: G. Sylvie Davies <sylvie@bit-booster.com>
Date: Thu Dec 15 18:24:02 2016 -0800

b2

commit ccb522334464879b8f39824031c997b57303475d
Merge: 6b85efb 026bf0c
Author: G. Sylvie Davies <sylvie@bit-booster.com>
Date: Thu Dec 15 18:13:35 2016 -0800

m

commit 6b85efbddbb74d49a096bfc54fd4df15e261b72f
Author: G. Sylvie Davies <sylvie@bit-booster.com>
Date: Thu Dec 15 18:12:51 2016 -0800

b1

在这一点上,我建议执行“git push --force-with-lease”,将这个压缩的提交提交到您的远程主题分支,为代码审查做好准备。

注意:我在示例中做了一件奇特的事情。我实际上挤进了 origin/master,而不是本地 master,我首先执行“git checkout branch”和“git reset --hard origin/master”。这使我的本地 master 不受此操作的干扰,因此无论我在那里可能正在做什么,都不会受到影响。

我正在使用 Git 2.7.4。也许较旧的 git 表现不同,我不知道。

如果你想在 Web UI 中完成这一切,并且你恰好使用 Atlassian Bitbucket Server(本地版本),你可以安装我的 Bit-Booster付费附加组件,然后点击它放在 pull 请求上的大“ Squash ”按钮。它做完全相同的事情,只是仅连接非 merge 提交消息。

enter image description here

关于git - Git merge --squash 可以保留提交注释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41339160/

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