git 从存储库中删除文件但将其保留在本地

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

Remove file from the repository but keep it locally

gitgitignoregit-rm

提问by Rodrigo Souza

I have a folder which I'd like to remove in my remote repository. I'd like to delete it, but keep the folder in my computer

我有一个文件夹,我想在我的远程存储库中删除它。我想删除它,但将文件夹保留在我的计算机中

回答by jamessan

git rm --cached -r somedir

Will stage the deletion of the directory, but doesn't touch anything on disk. This works also for a file, like:

将暂存目录的删除,但不涉及磁盘上的任何内容。这也适用于文件,例如:

git rm --cached somefile.ext

Afterwards you may want to add somedir/or somefile.extto your .gitignorefile so that git doesn't try to add it back.

之后,您可能希望将somedir/或添加somefile.ext到您的.gitignore文件中,以便 git 不会尝试将其添加回来。

回答by Jeff

I would just:

我只想:

  • Move the folder out of your working tree
  • git rmthe folder, commit the change
  • Add to .gitignore(or .git/info/excludes), commit the change
  • Move the folder back
  • 将文件夹移出工作树
  • git rm文件夹,提交更改
  • 添加到.gitignore(或.git/info/excludes),提交更改
  • 将文件夹移回