Linux中直接删除文件: rm <filename>
删除已经提交的文件会导致工作区与版本库不一致, 采用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 checkout -- <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
确认删除文件命令用错了,失误删除,需要恢复文件
git checkout -- <filename>
只能恢复到最后一次提交的版本