更改未删除的上一个git commit消息

xpt*_*xpt 4 git

如何更改以前未刷新的git提交消息?

更新: 问题急剧减少,以适应答案.要查看完整内容.看历史.

这样做的正确方法是什么?谢谢.

Rya*_*eve 14

要更改最新提交的消息,请运行:

git commit -m "corrected message" --amend

就足够了.

但是,如果您需要在最近之前更改提交消息,则应使用交互式rebase.此示例允许您在最近之前更改提交的消息.~2根据需要进行调整以进一步返回.

git rebase -i HEAD~2
<editor will open>
<change "pick" to "reword" for whichever commit(s) you wish to alter the message of>
<close/save the editor>
<for each commit you changed "pick" to "reword", git will present an editor with the existing commit message>
<update the commit message as desired and close/save the editor>
Run Code Online (Sandbox Code Playgroud)

而已.在每次提交后git停止后你从"pick"切换到"reword",你将回到你的HEAD提交,并更新评论.请注意,从第一次提交其注释的提交开始,该提交和所有后续提交都将具有新的哈希.由于您表示未提交提交,因此对于使用repo的其他人来说,这不应该导致问题.