Does gitignore work for files that were previously versions?

I have a file in my branch that I would ignore. I added it to .gitignore , but by changing it, it is still displayed under deltas in git status . gitignore works for previously unversioned files.

Is the reason gitignore is not working in this case, the fact that the file in question was already a version? How to get around this and ignore it on an ongoing basis?

+4
source share
2 answers

Yes, this does not work, because the file is already tracked by Git.

An approach would be to first delete the file and commit.

Then re-add the file (along with the entry in .gitignore) and commit again.

Another potential approach: How to make Git "forget" about a file that has been tracked but is now located in .gitignore?

+4
source

Files that have already been added to version control are not ignored, even if they are under .gitignore

To start ignoring these files, you must first remove them from version control. They can be removed using the git rm --cached <file> command. The --cached option removes files from version control by storing them on disk. Now <file> should stop appearing in the list of updated files.

+3
source

All Articles