首页 > 解决方案 > 即使在更新 git index 之后,git status 也会显示已删除的文件

问题描述

我已经克隆了一个 git repo。在构建过程中,某个文件夹中的许多文件显示为在执行时被删除:git status

他们已经在我不想删除的远程仓库中。关于这一点,我浏览了以下帖子: Git ignore deleted files

之后,我也将目录放入 .gitignore 中。仍然在执行git status时,我可以看到相同的结果。

标签: git

解决方案


在本地删除文件而不是在本地删除remote

这不会长期有效。当其他人克隆您的存储库时,他们将获得文件。

恢复本地文件

>git checkout .将恢复已删除的文件。

/mnt/c/git/repo666 (branchX)>git status
On branch branchX
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:    a.txt

no changes added to commit (use "git add" and/or "git commit -a")
/mnt/c/git/repo666 (branchX)>git checkout .
/mnt/c/git/repo666 (branchX)>git status
On branch branchX
nothing to commit, working tree clean
/mnt/c/git/repo666 (branchX)>

推荐阅读