本文翻译自:How do I git rm a file without deleting it from disk? [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
The command removes the file in my system. 该命令将删除系统中的文件。 I meant it to remove only the file from Git-repository. 我的意思是它只从Git-repository中删除文件。
How can I remove the file from a Git repository, without removing the file in my system? 如何在不删除系统中的文件的情况下从Git存储库中删除该文件?
#1楼
参考:https://stackoom.com/question/5LC0/如何在不删除磁盘的情况下git-rm文件-重复
#2楼
According to "git help rm", 根据“git help rm”,
git rm --cached file
should do what you want. 应该做你想做的事。
#3楼
I tried experimenting with the answers given. 我试着尝试给出答案。 My personal finding came out to be: 我个人的发现是:
git rm -r --cached .
And then 然后
git add .
This seemed to make my working directory nice and clean. 这似乎使我的工作目录变得干净整洁。 You can put your fileName in place of the dot. 您可以将fileName放在点的位置。