I have a configuration file in my project that is server specific so does not want to be included in Git as every time we deploy it overwrites the settings for the server. To resolve this problem the file was deleted from Git... nice idea but now every time the project is deployed the servers configuration file is deleted.
So I'm now stuck with a problem. What I really wanted was the file to be in .gitignore
and never added to the project, but once it was added I can't see a way to remove it from the project without it firing off a delete on the existing file with every deploy.
Is there way I can remove a file from a project without deleting it. Effectively retrospectively ignoring a file that was already added?
The easy and safe way to address this is to add the files you want to exclude to .gitignore
.
If the file is already being tracked (previously added and committed) you will also need to delete it from the repository. This can be done without deleting the local file which you want to keep by telling git to only delete the tracked version.
git rm --cached <file>
is the command that will do this. When you commit that change along with the .gitignore
update, the repository will stop tracking and start ignoring that file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With