git rm
删除的本质
在git中删除一个文件,本质上是从tracked files中移除对这些文件的跟踪。更具体地说,就是将这些文件从staging area移除。然后commit。
作用
git rm的作用就是将文件从暂存区删除
git rm的作用就是将文件从工作目录 和 暂存区 删除。
git rm并不能仅仅删除工作目录中的文件,而暂存区保持不变。目前git也没有提供任何参数支持这一功能。要想实现这一目标,只能使用Linux自带的/bin/rm命令
使用场景
彻底删除文件
所谓彻底删除文件,就是在工作目录和暂存区删除文件。由于gir rm不能直接删除工作目录中的文件,于是使用/bin/rm手动删除。此时执行git status 时就会在 “Changes not staged for commit”部分看到,表示没有被更改没有被暂存
$ rm PROJECTS.md $ git status On branch master Your branch is up-to-date with 'origin/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 workingdirectory) deleted: PROJECTS.md no changes added to commit (use "git add" and/or "git commit -a")