git rebase修改commit記錄

主要命令

git rebase -i 命令

開始

假如想要修改最近三次提交信息:

git rebase -i HEAD~3   //將想要修改的父提交作爲參數,即`HEAD~3^`

同理,修改最近第五次提交信息:

git rebase -i HEAD~5   //將想要修改的父提交作爲參數,即`HEAD~5^` 

使用上述命令後,會出現類似的界面


pick f7f3f6d 修改首頁bug
pick 310154e 增加webpack配置信息
pick a5f4a0d add readme文件

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

如果你想更改第2條commit 信息,就把第2條commit信息對應的pick 更改爲edit(輸入i進行編輯),然後esc+wq保存退出。

接下來,運行

git rebase --amend

運行上述命令後在彈出文本編輯界面重新提交commit信息,完成後保存退出。

接下來,運行

git rebase --continue

!!!修改完畢確認無誤後,強制推送到遠程!!!

git push origin master --force
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章