您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
22 如何让工作区的文件恢复为...
发布时间:2020-07-19 08:37:02编辑:雪饮阅读()
首先我们看到我们目前有1,2,3这3个文件在暂存区,并且1.txt的内容也可以看到
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: 1.txt
modified: 2.txt
modified: 3.txt
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ cat 1.txt
1 add
那么接下来我要对1.txt这个文件进行修改并且不添加进暂存区
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ cat 1.txt
1 add work space
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: 1.txt
modified: 2.txt
modified: 3.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
接下来我觉得1这个文件修改后还不如之前的好,那么我想要工作区恢复到刚才暂存区的状态,这里指定恢复1.txt这个文件则如
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ git checkout -- 1.txt
接下来我们再来看看当前的状态
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we5 (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: 1.txt
modified: 2.txt
modified: 3.txt
发现又回到了刚才暂存区时候的状态哈。
关键字词:git,工作区,checkout