git删除文件
一般情况下我们先删除工作区不需要的文件,这个时候Git知道你删除了文件,因此工作区和版本库就不一致了,git status
命令会立刻告诉哪里文件被删除了。
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
这里有两种选择,一是确实要从版本库中删除该文件,那就用命令 git rm
删除,并且 git commit
$ git rm readme.txt
rm 'readme.txt'
$ git commit -m "remove readme.txt"
[master de8bb92] remove readme.txt
1 file changed, 1 deletion(-)
delete mode 100644 readme.txt
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
另一种就是我们之前讲到的 git checkout readme.txt
这种可以理解是工作区误删除的