這次來介紹一下 git reset 的用法,為什麼會介紹這指令呢?因為今天想要看專案狀態,用 git status 觀看,發現被我玩爛了,所以出現了底下錯誤訊息:
$ git status error: bad index file sha1 signature fatal: index file corrupt解決此問題非常簡單,要先刪除 index 檔案,請先砍掉
.git/index,恢復此 index 請用
git reset這行指令相當於
git reset –mixed HEAD,或者是可以用 git read-tree 來取代 git reset,當然 git reset 不只是有這功能而已,假如您已經建立了 commit 訊息,也可以將此訊息拿掉,重新在 commit,或者是您修改過的檔案在暫存區,git 也可以幫您恢復到未暫存,或者是不想要這次的修改,也可以恢復到未修改的檔案喔。
取消已經暫存的檔案 假如我們有兩個檔案需要 commit,但是不小心按到 git add * 全部加入到暫存區,那該怎麼恢復呢?
# On branch master # Changes to be committed: # (use "git reset HEAD上面是以經在暫存區裡面等待被 commit 檔案(..." to unstage) # # modified: Makefile # modified: user/easy_setup/easysetup.h #
Changes to be committed),大家可以看到括號裡面有提示如何拿掉 (use “git reset HEAD
git reset HEAD user/easy_setup/easysetup.h之後會看到 『
user/easy_setup/easysetup.h: locally modified』此訊息,這時候在用 git status 看狀態
# On branch master # Changes to be committed: # (use "git reset HEAD[Read More]..." to unstage) # # modified: Makefile # # Changed but not updated: # (use "git add ..." to update what will be committed) # # modified: user/easy_setup/easysetup.h #
