Remove file from the repository but keep it locally

半腔热情 提交于 2019-11-27 08:55:53

问题


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


回答1:


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.ext to your .gitignore file so that git doesn't try to add it back.




回答2:


I would just:

  • Move the folder out of your working tree
  • git rm the folder, commit the change
  • Add to .gitignore (or .git/info/excludes), commit the change
  • Move the folder back


来源:https://stackoverflow.com/questions/3469741/remove-file-from-the-repository-but-keep-it-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!