git撤銷commit到未提交狀態

如何把最後一次commit撤銷回Changes not stagedUntracked files區呢?

有3種情況:

(1)把最後的commit切回Changes to be committed狀態,使用命令:

git reset --soft HEAD^

注意:Windows系統需要在^符號後面兩邊加上引號,如:

git reset --soft HEAD"^"

(2)把最後的commit切回Changes not staged for commit狀態,使用命令:

git reset HEAD^

(3)把Changes to be committed狀態切回Changes not staged for commit狀態,使用命令:

git reset HEAD <file>...          # 單個文件
git reset HEAD -- .               # 所有Changes to be committed的文件

最後一條命令在git命令行也有提示,不需要記住。

 

參考資料:

  1. Move (or “Undo”) last git commit to unstaged area [duplicate]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章