git里删除是一种修改操作
删除文件
先提交一个t2.md文件到git里然后利用rm命令删除没用的文件
$ git add t2.md
$ git commit -m "need to delete"
[master f04f5fc] need to delete
1 file changed, 1 insertion(+)
create mode 100644 t2.md
$ rm t2.md
此时查看状态的时候,因为删除文件所以工作区和版本库不一致,git status命令会提示哪些文件被删除
$ 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: t2.md
no changes added to commit (use "git add" and/or "git commit -a")
确定要删的文件
命令git rm删掉,并且git commit
$ git rm test.md
$ git commit -m "remove test.md"
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: t2.md
no changes added to commit (use "git add" and/or "git commit -a")
误删的文件
文件被误删但是版本库里还有保存,可以把误删的文件恢复到被删前的版本
$ git checkout -- test.md