在Git上更改旧的提交消息

我试图编辑一个旧的提交消息, 这里解释。

现在的事情是,当我尝试运行rebase -i HEAD~5 ,说interactive rebase already started

那么我试试: git rebase --continue但是得到这个错误:

 error: Ref refs/heads/master is at 7c1645b447a8ea86ee143dd08400710c419b945b but expected c7577b53d05c91026b9906b6d29c1cf44117d6ba fatal: Cannot lock the ref 'refs/heads/master'. 

有任何想法吗?

它说:

当您保存并退出编辑器时,它会将您倒回到该列表中的最后一个提交,并使用以下消息将您放到命令行上:

 $ git rebase -i HEAD~3 Stopped at 7482e0d... updated the gemspec to hopefully work better You can amend the commit now, with 

这并不意味着:

再次inputgit rebase -i HEAD~3

尝试在退出编辑器时不要inputgit rebase -i HEAD~3 ,它应该可以正常工作。
(否则,在你的特定情况下,可能需要一个git rebase -i --abort来重置所有的东西,并允许你再次尝试)


正如Dave Vogt在评论中提到的那样, 在你修改第一个提交之后git rebase --continue将用于重新git rebase --continue过程中的下一个任务。

另外, Gregg Lind在他的回答中提到git rebasereword命令

通过用命令“edit”replace命令“pick”,可以告诉git rebase在应用该提交后停止,以便可以编辑文件和/或提交消息,修改提交并继续重新绑定。

如果你只是想编辑提交的提交信息 ,从Git1.6.6(2010年1月)开始 , 用“ reword ”命令replace命令“ pick

它在交互式重新绑定过程中执行了“ edit ”,除了它只允许编辑提交消息而不返回到shell的控制 。 这非常有用。
目前如果你想清理你的提交消息,你必须:

 $ git rebase -i next 

然后将所有提交设置为“编辑”。 然后在每一个:

 # Change the message in your editor. $ git commit --amend $ git rebase --continue 

使用' reword '而不是' edit '可以让你跳过git-commitgit-rebase调用

FWIW,git rebase interactive现在有一个“reword”选项,这使得这个不那么痛苦!

您可以按照以下方式执行此操作,因为@gregg表示使用单词reword

 git rebase -i HEAD~n 

这里n是最后n个提交的列表。

例如,如果你使用git rebase -i HEAD~4

 pick e459d80 Do xyz pick 0459045 Do something pick 90fdeab Do blah blah blah pick 90fdeab Do pqr 

现在用rewordreplace单词select来提交你想编辑的信息。

  pick e459d80 Do xyz reword 0459045 Do something reword 90fdeab Do blah blah blah pick 90fdeab Do pqr 

现在closures并保存,您将有机会编辑您在以下窗口中使用reword的提交消息。

你也可以在这里引用官方文档