在合并之前修改Git提交的消息 [英] Amending the message of Git commit made before a merge

查看:124
本文介绍了在合并之前修改Git提交的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在合并到远程分支之前,我提交了一些测试代码。这次合并发生了很多冲突,并花了一些时间来纠正。所以我的历史看起来像这样:

  7ab562c从远程分支合并
...整个提交的提交负载从远程分支...
f3e71c2临时测试提交

测试代码很好,我真的只想改变提交信息。通常情况下,我会立即着手使用 git rebase -i f3e71c2 ^ (因为还没有推送过),但一位同事告诉我这个会搞乱合并。我真的不想搞乱合并:)

我的同事是否正确?如果是这样,有什么我可以做的,或者我只需要忍受这段历史?

您可以试试 git rebase --preserve-merges --interactive ,与:

  -p 
- 保留合并




而不是忽略合并,请尝试重新创建合并。




手册页的BUG部分包括:


- preserve-merges --interactive 不代表修订图的拓扑结构。

编辑提交并重新提交它们的提交信息应该可以正常工作,但尝试重新排序提交往往会产生违反直觉的结果。







由于 jthill 评论描述(因为如果冲突解决方案是记录器, -p 会更好地保留合并):


您可以追溯轻合并:



  git config rerere.enabled true 
git checkout $ merge ^ 1
git merge $ merge ^ 2
git read-tree --reset -u $ merge
git commit - m-
git checkout @ { - 1}


I committed some test code before merging in a remote branch. This merge had a lot of conflicts and took some serious time to put right. So my history looks something like this:

7ab562c Merge from remote branch
... whole load of commits brought across from the remote branch...
f3e71c2 Temporary TESTING COMMIT

The test code is fine, I really just want to change the commit message. Normally I'd go right ahead with a git rebase -i f3e71c2^ (since none of this has been pushed yet), but I've been told by a colleague that this will mess up the merge. I really don't want to mess up the merge :)

Is my colleague correct? And if so, is there anything I can do, or do I just need to live with this history?

解决方案

You can try a git rebase --preserve-merges --interactive, with:

-p
--preserve-merges

Instead of ignoring merges, try to recreate them.

The BUG section of the man page includes:

The todo list presented by --preserve-merges --interactive does not represent the topology of the revision graph.
Editing commits and rewording their commit messages should work fine, but attempts to reorder commits tend to produce counterintuitive results.


As jthill's comment describes (since -p will better preserve merges if conflict resolutions were recorder):

You can retroactively light rerere for a merge:

git config rerere.enabled true
git checkout $merge^1
git merge $merge^2
git read-tree --reset -u $merge
git commit -m-
git checkout @{-1}

这篇关于在合并之前修改Git提交的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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