2009-12-10 79 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