这个时候,Git知道你删除了文件,因此,工作区和版本库就不一致了,git status
命令会立刻告诉你哪些文件被删除了:
huangjiaxin@hjiax2023 MINGW64 ~/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
现在你有两个选择,一是确实要从版本库中删除该文件,那就用命令git rm
删掉,并且git commit
:
huangjiaxin@hjiax2023 MINGW64 ~/learngit (master)
$ git rm test.txt
rm 'test.txt'
huangjiaxin@hjiax2023 MINGW64 ~/learngit (master)
$ git commit -m "removw test.txt"
[master 3c71913] removw test.txt
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 test.txt
现在,文件就从版本库中被删除了。
另一种情况是删错了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本