少於 1 分鐘閱讀

方法一:直接使用–amend調整

#先修改需要修改的地方。
$ git add .
$ git commit –amend #會跳出vim畫面,調整好後輸入:wq離開即可

方法二: 先reset,再調整

$ git reset HEAD^
#重新修改
$ git add .
$ git commit -m “MSG”

方法三: 使用rebase調整

1. 查看修改

$ git rebase -i master~1 //最後一次
$ git rebase -i master~5 //最後五次

2. 顯示結果如下,修改 pick 為 edit ,並 :wq 存檔離開

pick 92b495b 2009-08-08: ×××××××

# Rebase 9ef2b1f..92b495b onto 9ef2b1f
#
# Commands:
#  pick = use commit
#  edit = use commit, but stop for amending
#  squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

3. 命令列顯示

Rebasing (1/1)
You can amend the commit now, with

git commit --amend

4. 使用 git commit –amend 进行修改,完成后 :wq 退出

$ git commit --amend

5. 使用 git rebase –continue 完成操作

$ git rebase --continue

參考

  1. http://blog.csdn.net/tangkegagalikaiwu/article/details/8542827

更新時間:

留言