简体   繁体   English

git添加到.gitignore并保留文件

[英]git add to .gitignore and keep files

At work we setup a git repo to manage the current site. 在工作中,我们设置了一个git repo来管理当前站点。 However we don't want all the files so we added some to the .gitignore right away. 但是,我们不需要所有文件,因此我们立即将一些文件添加到了.gitignore中。 However, there are still some files that got into the repo we want removed from the repo, but kept on the server. 但是,仍有一些文件进入了要从存储库中删除但仍保留在服务器上的文件。

The thing is if I add it to the .gitignore it does not remove it from the repo. 问题是,如果我将其添加到.gitignore中,它不会将其从存储库中删除。 I've read several similar questions on here. 我在这里阅读了几个类似的问题。 I am worried if I do this wrong I could delete thousands of images from our server. 我担心如果我做错了,我会从服务器中删除数千张图像。

So how do I add it to the .gitignore, remove the files from tracking in the repo, without deleting them from the server. 因此,如何将其添加到.gitignore中,从回购中删除跟踪中的文件,而不从服务器中删除它们。

git rm --cached file

seems like it would delete the file or am I wrong? 好像会删除文件,还是我错了?

You answered the question yourself, my friend. 你自己回答了这个问题,我的朋友。

git rm --cached file would remove from version control, while keeping it in the working repository. git rm --cached file将从版本控制中删除,同时将其保留在工作库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM