Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

git - Remove and untrack files from repo but keep them on remote server

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.

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.

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

edit:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...