从回购中删除和取消跟踪文件,但将其保留在远程服务器上 [英] Remove and untrack files from repo but keep them on remote server

查看:73
本文介绍了从回购中删除和取消跟踪文件,但将其保留在远程服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了一些搜索,但是要么我不完全了解它是如何工作的,要么是我没有找到我需要的东西.

I've done some searching but either I don't understand exactly how this works or I'm not finding what I need.

我有一个生产服务器,我有我的本地开发箱.

I have a production server and I have my local development box.

到现在为止,有一个目录已由git repo跟踪,我不再要跟踪该目录.我还想从存储库中删除那些文件,因为它们不会被跟踪,只是使git存储库比需要的大.

There is a directory that has been tracked by the git repo until now, which I no longer want to track. I also want to remove those files from the repo as they will not be tracked and simply make the git repo larger than it needs to be.

但是,我的理解是,如果我在本地使用git rm --cached并更改.gitignore文件,则当我拉下不需要的更新存储库时,它将删除远程服务器上的文件.我希望文件保留在生产环境中,只是不再跟踪且不在存储库中.

However, my understading is that if I to a git rm --cached locally and change my .gitignore file, it will delete the files on the remote server when I pull down the updated repo, which I do not want. I want the files to remain on production, just not tracked any more and not in the repo.

我认为以前有人必须这样做,所以我可能会遗漏一些明显的东西.

I would think someone has had to do this before and I'm probably missing something obvious.

我希望这是有道理的.谢谢!

I hope that makes sense. Thanks!

推荐答案

您正确理解它.但是,您可以在生产服务器上制作这些文件的副本,拉出本地存储库(这将删除原始存储库),然后从副本中还原文件.之后,将不会跟踪这些文件,因此不会再执行(通常的)git操作(包括任何进一步的拉取)来覆盖或删除它们.

You understand it correctly. You can, however, make copies of these files on the production server, pull the local repo (which will erase the originals), and then restore the files from the copy. After that these files will not be tracked, so no (usual) git operations, including any further pulls, are going to overwrite or remove them.

实际上,问题的作者提出了一个更好的解决方案,即在生产服务器上使用git rm --cached,它将从索引中删除文件(允许它们在下一次提交时从存储库中删除),但保留他们在工作树上.

Actually the author of the question proposed a much nicer solution, that is using git rm --cached on the production server, which will remove the files from index (allowing them to be removed from the repository in the next commit), but preserving them in the working tree.

这篇关于从回购中删除和取消跟踪文件,但将其保留在远程服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆