06 Git中删除文件

Linux中直接删除文件: rm

删除已经提交的文件会导致工作区与版本库不一致, 采用git status命令会显示:

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm ..." to update what will be committed)
  (use "git checkout -- ..." 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 --
    只能恢复到最后一次提交的版本

你可能感兴趣的:(06 Git中删除文件)