A question that occurs frequently on the Q&A programming sites looks like this:
I want Git to ignore one of the files in the project. I added the file name and/or the file path to
.gitignore
and/or.git/info/exclude
butgit status
still shows the file as being modified.
It seems Git doesn’t ignore the file, it ignores me. I’m desperate, please help!
Is it quite so? Does Git ignore you?
Let’s see first what the documentation of .gitignore says:
A
gitignore
file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.
And the aforementioned notes, several screens below:
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.
To stop tracking a file that is currently tracked, usegit rm --cached
.
Is there something else to add?
I guess the answer is “No”. Everything should be clear from the fragments quoted above.
I would emphasize the “untracked files” expression and note that it is mentioned in both places. The gitignore files are consulted only when Git processes untracked files, i.e. files that are currently not in the repository.
The answer to the question is also included: adding the file name/path to .gitignore
doesn’t help
unless you also remove the file from the repository (untrack it) using the command:
git rm --cached <filepath>
Case closed.