一:git restore指令
(1)先用git status看一下狀態
(2)打開a.c添加點內容(原本內容是aaa)
(3)再用git status看一下狀態
此時a.c的狀態是剛剛更改過,但是還沒有用git add指令添加到暫存區中,也就是說a.c目前處於工作區下。
(4)使用git restore
也就是:git restore a.c
(5)用git status看一下狀態
(6)最后看一下a.c中的內容
結論:git restore指令使得在工作空間但是不在暫存區的文件撤銷更改(內容恢復到沒修改之前的狀態)
二:git restore --staged指令
(1)先用git status看下狀態,再用cat a.c 看下a.c文件的內容
(2)vim a.c 打開文件修改文件的內容
(3)git status看下狀態
(4)git add a.c 將文件添加到暫存區
(5)git restore --staged 的使用
可以看到使用git restore --staged之后,文件的內容並沒有改變。
結論:git restore --staged的作用是將暫存區的文件從暫存區撤出,但不會更改文件的內容。
https://blog.csdn.net/qq_38158479/article/details/106972138