如何在不从磁盘中删除文件的情况下 git rm 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1273108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:53:13  来源:igfitidea点击:

How do I git rm a file without deleting it from disk?

gitgit-rm

提问by Léo Léopold Hertz ??

The command removes the file in my system. I meant it to remove only the file from Git-repository.

该命令删除我系统中的文件。我的意思是只从 Git 存储库中删除文件。

How can I remove the file from a Git repository, without removing the file in my system?

如何从 Git 存储库中删除文件,而不删除系统中的文件?

回答by kwatford

git rm --cached file

should do what you want.

应该做你想做的。

You can read more details at git help rm

您可以在以下位置阅读更多详细信息 git help rm

回答by gran_profaci

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.

这似乎使我的工作目录变得干净整洁。你可以用你的文件名代替点。