使用 git rebase
$ git rebase -i HEAD~3
上面表示由 HEAD 開始三個需要修改
舉例來說
* 87bbfb7 - (HEAD -> master) add d (4 seconds ago)
* c1be43e - add c (19 seconds ago)
* 33954fb - add b (39 seconds ago)
* 6414dbf - commit a (52 seconds ago)
當輸入上述所提到的指令後會出現:
pick 33954fb add b
pick c1be43e add c
pick 87bbfb7 add d
# Rebase 6414dbf..87bbfb7 onto 6414dbf (3 command(s))
#
# 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
註解有提到要如何使用 rebase,其中一項 reword 就是我們要用的功能
例如我們現在要更改 33954fb 這一個 commit 指需要將前面的 pick 更改成 reword 或是 r ,然後存檔並退出即可。
推出後就是熟悉的 commit message 編輯畫面了,編輯後也是存檔離開即可完成動作。
如果想要從某一個 commit 之後開始編輯,則只需要打上該 commit 的 hash 即可。
$ git rebase -i [commit-hash]