[英]Change old commit message using `git rebase`
我試圖編輯舊的提交消息,如此處所述。
問題是,現在,當我嘗試運行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
這並不意味着:
再次輸入
git rebase -i HEAD~3
退出編輯器時盡量不要輸入git rebase -i HEAD~3
,它應該可以正常工作。
(否則,在您的特定情況下,可能需要git rebase -i --abort
來重置所有內容並允許您重試)
正如Dave Vogt在評論中提到的那樣, git rebase --continue
用於在您修改了第一個 commit 之后進入變基過程中的下一個任務。
此外, Gregg Lind在他的回答中提到了git rebase
的reword
命令:
通過將命令“pick”替換為命令“edit”,您可以告訴
git rebase
在應用該提交后停止,以便您可以編輯文件和/或提交消息,修改提交並繼續變基。如果您只想編輯提交的提交消息,請將命令“
pick
”替換為命令“reword
” ,因為Git1.6.6(2010 年 1 月) 。它在交互式 rebase 期間執行相同的操作 '
edit
',除了它只允許您編輯提交消息而不將控制權返回給 shell 。 這是非常有用的。
目前,如果您想清理提交消息,您必須:
$ git rebase -i next
然后將所有提交設置為“編輯”。 然后在每一個上:
# Change the message in your editor.
$ git commit --amend
$ git rebase --continue
使用 '
reword
' 而不是 'edit
' 可以讓您跳過git-commit
和git-rebase
調用。
正如 Gregg Lind 建議的那樣,您可以使用reword來提示您僅更改提交消息(否則保持提交不變):
git rebase -i HEAD~n
這里, n
是最后 n 次提交的列表。
例如,如果您使用git rebase -i HEAD~4
,您可能會看到如下內容:
pick e459d80 Do xyz
pick 0459045 Do something
pick 90fdeab Do something else
pick facecaf Do abc
現在將pick替換為reword ,用於您要編輯以下消息的提交:
pick e459d80 Do xyz
reword 0459045 Do something
reword 90fdeab Do something else
pick facecaf Do abc
保存文件后退出編輯器,接下來將提示您編輯標記為reword的提交的消息,每條消息在一個文件中。 請注意,當您將pick
替換為reword
時,僅編輯提交消息會簡單得多,但這樣做沒有任何效果。
在 GitHub 的更改提交消息頁面上了解更多信息。
FWIW,git rebase interactive 現在有一個reword
選項,這讓這變得不那么痛苦了!
只是想為此提供一個不同的選擇。 就我而言,我通常在我的各個分支上工作,然后合並到 master,而我對本地所做的各個提交並不那么重要。
由於一個 git 鈎子會檢查 Jira 上的相應票號但區分大小寫,因此我無法推送我的代碼。 此外,提交是很久以前完成的,我不想計算有多少提交返回到 rebase。
所以我所做的是從最新的 master 創建一個新分支,並將問題分支中的所有提交壓縮到新分支上的單個提交中。 這對我來說更容易,我認為把它放在這里作為將來的參考是個好主意。
來自最新大師:
git checkout -b new-branch
然后
git merge --squash problem-branch
git commit -m "new message"
參考: https ://github.com/rotati/wiki/wiki/Git:-Combine-all-messy-commits-into-one-commit-before-merging-to-Master-branch
這是一個非常好的要點,涵蓋了所有可能的情況: https ://gist.github.com/nepsilon/156387acf9e1e72d48fa35c4fabef0b4
概述:
git rebase -i HEAD~X
# X is the number of commits to go back
# Move to the line of your commit, change pick into edit,
# then change your commit message:
git commit --amend
# Finish the rebase with:
git rebase --continue
我試圖按照此處的說明編輯舊的提交消息。
問題是,現在,當我嘗試運行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'.
有任何想法嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.