在合并之前修改Git提交的消息

在合并之前修改Git提交的消息

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

问题描述

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

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

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

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

您可以试试,与:

  -p 
- 保留合并








由于的描述(因为如果冲突解决方案是记录器, -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

The BUG section of the man page includes:


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

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提交的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:29