經過git rebase修改commit message

今天發現一個項目的git commit message中的單詞拼錯了,須要修改一下。但這樣簡單的修改,須要經過git rebase才能完成。git

首先要git rebase到須要修改message的那個commit的前1個commit。假設commit id是32e0a87f,運行下面的git rebase命令:github

git rebase -i 32e0a87f

在git bash中運行上面的命令後,會彈出編輯框,在編輯框中會分行依次顯示以pick開頭的這個commit以後的全部commit message。bash

將須要修改的commit message以前的"pick"改成"reword",點擊保存按鈕,並關閉編輯框,這時會執行rebase操做。url

Rebasing (1/3)

接着會再次彈出編輯框,此次編輯框中只有以前改成"reword"的那個commit message,此時修改commit message的內容,點擊保存按鈕並關閉編輯框,會繼續執行rebase操做。code

若是操做成功,會出現以下的提示:blog

[detached HEAD aa3b52c] Add return url
 2 files changed, 1 insertion(+), 3 deletions(-)
Successfully rebased and updated refs/heads/oss.

這樣就完成了git commit message的修改,而後強制push一下就搞定了。get

git push --force

【參考資料】it

Changing a commit messageio

相關文章
相關標籤/搜索