Amending the message of Git commit made before a merge

落花浮王杯 提交于 2019-11-30 04:38:35
VonC

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}

If and only if your colleagues have not pushed/pulled the changes ontop of f3e71c2 elsewhere, this will work. Otherwise I don't know what will happen. Changing the commit message is entirely cosmetic (== metadata change), given that you haven't pushed the commit you want to amend yet, but this could still result in history confusion if your colleagues have pushed/ pulled any part of the history which is atop it.

(thanks to Abizern for pointing out this failure-mode)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!