删除一个文件

1. 一般删除本地的一个文件

  rm hanmeimei.py

  hanmeimeideMacBook-Pro:ExPython hanmeimei$ git st
  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 working directory)

      deleted:    hanmeimei.py
  • 这是可以选择 git add/rm <file>... 把变更增添到暂存区
  • 也可以选择 git checkout -- <file>... 恢复删除的文件

2. 删除完本地,还要记得在 git 仓库中删除该文件

  git rm file

  hanmeimeideMacBook-Pro:ExPython hanmeimei$ git st
  On branch master
  Your branch is up-to-date with 'origin/master'.
  Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

      deleted:    hanmeimei.py
  • 这时可以选择 git ci -m "git rm file" 把变更提交

3. 其实可以直接 git rm file,不需要第一步 =.=

4. 恢复误删除的文件

git checkout -- file

git checkout 其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。

results matching ""

    No results matching ""