git 如何仅删除远程存储库中的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14576109/
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 15:22:30  来源:igfitidea点击:

How to delete a file in remote repository ONLY?

git

提问by Arafangion

Possible Duplicate:
Git: Remove a file from the repository without deleting it from the local filesystem

可能的重复:
Git:从存储库中删除文件而不从本地文件系统中删除它

I wish to delete files from remote repository without deleting the files from local copy. Is there a way to do this in git?

我希望从远程存储库中删除文件而不从本地副本中删除文件。有没有办法在 git 中做到这一点?

The reason is: I am working on a project at early stage. I committed some files which should not be in the repository, so I added those files into .gitignore. If I remove those files from my local copy, the program will not work.

原因是:我正在做一个早期的项目。我提交了一些不应该在存储库中的文件,所以我将这些文件添加到.gitignore. 如果我从本地副本中删除这些文件,该程序将无法运行。

Thanks everyone. THis question is duplicating "Remove a file from a Git repository without deleting it from the local filesystem"

谢谢大家。这个问题是重复“从 Git 存储库中删除文件而不从本地文件系统中删除它

回答by Arafangion

Use this command

使用这个命令

git rm --cached <filename>
git rm --cached -r <dir_name>
git commit -m "Removed folder from repository"
git push origin master

This removes the filenamefrom the index, without touching your working tree.

这将从索引中删除文件名,而不会触及您的工作树。