Expected effect:
The file is committed while any further changes thereto get ignored.
There might be problems. Like what happens when we switch branches? How to ensure that if we DO want to change the file for everybody, how to ensure this?
I didn't test the above. Just for your consideration.
Adding a file to .gitignore doesn't remove it from git. It just ignores it in the "working tree", and when doing bulk adds (IE: git add . or git commit -a).
If you need to remove the file from the git cache but not from the file system (aka, if you had a file checked in and then added it to .gitignore), you can run:
The use case in my post is admittedly pretty specific, but we don't want to add the config files to .gitignore because the files are needed for the codebase to run properly. These config files also happen to have debugging options in them, so you have to modify the git working tree to enable them.
You are perfectly correct. And that's the point. One can "freeze" the file at the state it's been at the moment of adding to .gitignore.
I was addressing the following fragment from TS:
we have some configuration files tracked in git that we modify locally to enable debugging options. We don't want to ignore these files and have to manage them in a different system outside of git, but we also don't want the debugging options checked in.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've noticed one effect when adding a file to
.gitignore
. It wasn't removed from repo.Steps To Reproduce:
git add <file> && git commit -m "Initialize <file>"
.gitignore
Expected effect:
The file is committed while any further changes thereto get ignored.
There might be problems. Like what happens when we switch branches? How to ensure that if we DO want to change the file for everybody, how to ensure this?
I didn't test the above. Just for your consideration.
Adding a file to
.gitignore
doesn't remove it from git. It just ignores it in the "working tree", and when doing bulk adds (IE:git add .
orgit commit -a
).You still can stage such changes with
git add -f
.Correct.
If you need to remove the file from the git cache but not from the file system (aka, if you had a file checked in and then added it to
.gitignore
), you can run:git rm --cached path/to/file
Cool I learned something new today
But I'm a little confused about your use case. It seems to me that adding the file to
.gitignore
would do the trick.The use case in my post is admittedly pretty specific, but we don't want to add the config files to
.gitignore
because the files are needed for the codebase to run properly. These config files also happen to have debugging options in them, so you have to modify the git working tree to enable them.You are perfectly correct. And that's the point. One can "freeze" the file at the state it's been at the moment of adding to
.gitignore
.I was addressing the following fragment from TS: