正确删除文件的方法

正确删除文件的方法

十月 21, 2019

正确删除文件的方法

  • git rm [filename]
$ rm readme.md #删除工作区的readme.md文件
$ git status
On branch temp
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.md

no changes added to commit (use "git add" and/or "git commit -a")
$ git rm readme.md #删除暂存区的readme.md 或者使用add命令更新暂存区
$ git status
On branch temp
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

deleted: readme.md

$ git reset --hard HEAD #恢复工作区和暂存区到HEAD指针
HEAD is now at 645c351 Modified commit2
$ git status
On branch temp
nothing to commit, working tree clean
$ git rm readme.md #使用rm命令删除readme.md
rm 'readme.md'
$ git status #查看状态 发现和先使用rm删除工作区文件 然后再更新暂存区的效果是一样的
On branch temp
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

deleted: readme.md