更新未在git merge中显示的合并提交消息

时间:2019-03-26 17:18:04

标签: git rebase

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

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

我意识到当我git rebase -i没有显示合并提交时,我了解了为什么在这里[Merge commits don't appear in git rebase --interactive

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

如何将中间提交的消息更改为“ [#US810469]合并github.xx.com:org/repo的分支'master'?

3 个答案:

答案 0 :(得分:2)

git rebase -i时,您以线性方式重写历史记录,因此删除了合并提交。您可以执行此操作(假设您位于 develop 分支)

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

可能会有一些捷径,但是通过这种方式我很容易理解步骤。希望你也...

答案 1 :(得分:0)

与其在交互式对话框中插入一行,还不如在您要插入提交之前将选择更改为对提交的编辑。 示例:

pick 123abccc one
pick 1234abcc two
pick 12345abc three

要在123abccc(一个)之前插入一个新提交

pick 123abccc one
edit 1234abcc two
pick 12345abc three

在进行git rebase --continue之前,请添加所有新提交。

编辑: 如果您只想更改提交消息,则将选择项更改为reword。

答案 2 :(得分:0)

如果在 之后要修改的合并修订版仅是普通的旧提交(无合并),则可以考虑手动进行

git checkout 807fed0
git commit --amend -m "Here's the fixed comment"
git cherry-pick 807fed0..master # master or whatever branch
# if everything is ok, then move the local pointer of master (or whatever branch) and push as required
git branch -f master
git push whatever-remote -f master

准备好了!