2009-12-10 81 views
85

我试图编辑旧的提交消息,如解释here在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'. 

任何想法?

回答

88

它说:

When you save and exit the editor, it will rewind you back to that last commit in that list and drop you on the command line with the following message:

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

这并不意味着:

type again git rebase -i HEAD~3

尝试退出编辑器时,键入git rebase -i HEAD~3,它应该工作的罚款。
(否则,在你的特殊情况,一个git rebase -i --abort可能需要重置一切,让你再试一次)


由于Dave Vogt提到的意见,git rebase --continue是在重订基期要到下一个任务处理,修改完第一次提交后。

此外,Gregg Lindhis answer提到的git rebasereword命令:

By replacing the command "pick" with the command "edit", you can tell git rebase to stop after applying that commit, so that you can edit the files and/or the commit message, amend the commit, and continue rebasing.

If you just want to edit the commit message for a commit, replace the command " pick " with the command " reword ", since Git1.6.6 (January 2010) .

It does the same thing ‘ edit ’ does during an interactive rebase, except it only lets you edit the commit message without returning control to the shell. This is extremely useful.
Currently if you want to clean up your commit messages you have to:

$ git rebase -i next 

Then set all the commits to ‘edit’. Then on each one:

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

Using ‘ reword ’ instead of ‘ edit ’ lets you skip the git-commit and git-rebase calls.

+1

使用--abort命令。谢谢 – 2009-12-11 13:54:48

+2

另外,在修改第一次提交之后,'git rebase --continue'会进入重新绑定过程中的下一个任务。 – 2010-08-23 13:42:08

+0

将[link](https://help.github.com/articles/changing-a-commit-message/)添加到github wiki文章中以更改提交消息 – Joy 2017-11-18 18:49:51

42

FWIW,git的重订互动,现在已经是 “改写” 选项,这使得这种粘液h少痛苦!

9

为@gregg说要用一句话改写

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 

现在替换单词改写为承诺要编辑的消息。

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

现在关闭并保存此你会得到机会,编辑提交您已在下面窗口中使用改写消息。

您可以参考官方文档here以及

+0

这实际上是最简单的方法。像一个魅力工作感谢:) – 2018-02-26 09:25:40