Git可以合并--squash保留提交注释吗? [英] Can Git merge --squash preserve commit comments?

查看:157
本文介绍了Git可以合并--squash保留提交注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以自动添加压缩后的mybranch提交中的所有提交注释

Is there a way of automatically adding all the commit comments from the squashed mybranch commits when doing a

git merge --squash mybranch

,以便单个提交包含来自mybranch

so that the single commit contains a concatenation of all the commit comments from mybranch

推荐答案

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

I think that's what "git merge --squash" does automatically! Just do the commit with "git commit --no-edit" and I think that's what you'll get. I see all the commit messages inside .git/SQUASH_MSG immediately after I run the "git merge --squash" command. Do you?

我个人是挤进master的,但随后将结果强行推回到主题分支.这样,可以通过pull-request对我的最终提交进行代码审查.

Personally, I squash into master, but then force-push the result back to my topic branch. This way my final commit can be code-reviewed via pull-request.

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

Live example (try these exact commands, this uses my demo server, and really works):

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",以将压缩后的提交提交到远程主题分支以供代码检查.

At this point I recommend doing a "git push --force-with-lease" to get this squashed commit up to your remote topic branch ready for code-review.

注意:在示例中,我做了一件很想做的事.我实际上是在挤压源/主服务器,而不是本地主服务器,并且首先执行"git checkout分支"和"git reset --hard源/主服务器".这使我的本地主机不受此操作的干扰,因此我在那里工作的任何东西都将被保留.

Note: I do one fancy thing in the example. I'm actually squashing into origin/master, not local master, and I first do "git checkout branch" and "git reset --hard origin/master". This keeps my local master unperturbed by this operation, so that whatever I might be working on there is left alone.

我使用的是Git 2.7.4.我不知道,也许旧的git的行为有所不同.

I'm on Git 2.7.4. Maybe older gits behave differently, I don't know.

如果您想在Web UI中完成所有操作,并且碰巧正在使用Atlassian Bitbucket Server(本地版本),则可以安装我的

If you want to do this all in Web UI, and you happen to be using Atlassian Bitbucket Server (the on-premises version), you can install my Bit-Booster paid add-on, and hit the big "Squash" button it puts on pull-requests. It does the exact same thing, except that only non-merge commit messages are concatenated.

这篇关于Git可以合并--squash保留提交注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆