首页 > 解决方案 > 更新未显示在 git merge 中的合并提交消息

问题描述

我有以下提交,我需要使用分支名称更新中间提交。

...
...
9a3de7d [#US810469]Add configuration
807fed0 Merge branch 'master' of github.xx.com:org/repo
6153e1e [#US810469] fix typo

我意识到当我git rebase -i没有显示合并提交时,我知道了为什么在这里[合并提交没有出现在 git rebase --interactive

在交互式外壳中,我看到它说如果您删除一行,您将丢失提交。我想也许我可以在我想要的地方添加一个提交:) 但这没有用。它不断向我显示要编辑的待办事项。我尝试编辑它们并再次提交,但每次都失败。

如何将中间提交的消息更改为“[#US810469]Merge branch 'master' of github.xx.com:org/repo”?

标签: gitrebase

解决方案


当你git rebase -i,你正在以线性方式重写历史,从而删除你的合并提交。你可以这样做(假设你在开发分支上)

git branch temp # create temporary branch where you are now (at 6153e1e I suppose)
git reset --hard 807fed0 # move develop branch to the merge commit
git commit --amend # now edit your message to look the way you want it
git cherry-pick temp # since there is only commit in temp branch, cherry-pick will do

如果您在合并提交后有多个提交,那么您可以:

git checkout temp
git rebase develop
git checkout develop
git rebase temp
git branch -d temp

可能有一些捷径,但这样我很容易理解这些步骤;希望你也...


推荐阅读