git reset hard/mixed/soft三種模式詳解

請在你的git bash輸入如下命令,此時會在你的瀏覽器彈出一個關於git reset詳解的html頁面。其實這個html就在你的本地,順騰摸瓜,可以在此路徑下面找到其它的一些命令教程。

git reset --help

暫且只討論下面的用法,soft,mixed,hard。請將下面的英文解釋多看幾遍,可以自行google翻譯。

git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

--soft
Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

If -N is specified, removed paths are marked as intent-to-add (see git-add(1)).

--hard
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

理解上圖中的關係,多看幾遍英文解釋,多動手操作幾遍。下面是我的理解。

hard:將HEAD之後的變更內容全部丟棄。

mixed:將HEAD之後的變更內容放到工作區中

soft:代表將HEAD之後的變更內容放到暫存區中。

以下下三個圖均在我當前HEAD中,將test.txt添加到了暫存區,但是沒有提交的條件下執行的。不用關注我過程修改的內容,你只需要關注當我執行了mixed/soft/hard之後,使用git status查看的狀態。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章