git實戰15 – 強制回復到上一個 commit 時間點

假設我們在下午5點36分時 commit 今天新增、修改的部份,但臨時加班工作到了7點17分,不過由於寫的不好,想要回復到下午5點36分 commit 時的程式碼

現在時間

[yamaou@halley study]$ date
Mon Mar 14 19:17:13 CST 2016

看一下目前修改過那些頁面

[yamaou@halley study]$ git status
# On branch 20160310-office
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   oop5/.htaccess
#       modified:   oop5/model/FunAdd/tpls/HtmlBody1.tpl
#       modified:   oop5/tpls/home.tpl
#       modified:   oop5/tpls_c/%%86^864^8644F0D6%%home.tpl.php
#       modified:   oop5/tpls_c/%%FD^FDA^FDAC0D7E%%HtmlBody1.tpl.php
#
no changes added to commit (use "git add" and/or "git commit -a")

強制回復到上一個 commit 時間點

[yamaou@halley study]$ git reset --hard HEAD
HEAD is now at fae32d7 2016/3/14 pm 5:36

再看一下狀態

[yamaou@halley study]$ git status
# On branch 20160310-office
nothing to commit (working directory clean)