撤銷回退 情況?:已經 add ,但沒有 commit
add 后還是保存到了暫存區呢?怎么撤銷呢?
1 # 向ReadMe中新增??代碼
2 hyb@139-159-150-152:~/gitcode$ vim ReadMe
3 hyb@139-159-150-152:~/gitcode$ cat ReadMe
4 hello bit
5 hello git
6 hello world
7 hello version1
8 hello version2
9 hello version3
10 This piece of code is like shit #新增代碼
11
12 # add 存?暫存區
13 hyb@139-159-150-152:~/gitcode$ git add ReadMe
14 hyb@139-159-150-152:~/gitcode$ git status
15 On branch master
16 Changes to be committed:
17 (use "git restore --staged <file>..." to unstage)
18 modified: ReadMe
讓我們來回憶?下學過的 git reset 回退命令,該命令如果使? --mixed 參數,可以將暫存區的內容退回為指定的版本內容,但?作區?件保持不變。那我們就可以回退下暫存區的內容了!!!
?例如下:
1 # --mixed 是默認參數,使?時可以省略
2 hyb@139-159-150-152:~/gitcode$ git reset HEAD ReadMe
3 Unstaged changes after reset:
4 M ReadMe
? git status 查看?下,發現現在暫存區是?凈的,?作區有修改。
1 hyb@139-159-150-152:~/gitcode$ git status
2 On branch master
3 Changes not staged for commit:
4 (use "git add <file>..." to update what will be committed)
5 (use "git restore <file>..." to discard changes in working directory)
6 modified: ReadMe
7
8 no changes added to commit (use "git add" and/or "git commit -a")
還記得如何丟棄?作區的修改嗎?
1 hyb@139-159-150-152:~/gitcode$ git checkout -- ReadMe
2 hyb@139-159-150-152:~/gitcode$ git status
3 On branch master
4 nothing to commit, working tree clean
5 hyb@139-159-150-152:~/gitcode$ cat ReadMe
6 hello bit
7 hello git
8 hello world
9 hello version1
10 hello version2
11 hello version3
恢復了!