How to Make Git Forget About a Tracked File Which is Now in .gitignore
Steps to removing the file from Git
Now let’s see what steps you need to make Git completely forget about that file that was tracked from .gitignore:
- Removing the file from the index
As Git will continue to track any files that are already being tracked, you should remove the file from index to stop tracking it:
git rm --cached <file>
- Tracking files
Track the files that should be tracked:
git add .
- Preventing the file be committed to repository
If the file that is ignored would be modified, after modifying and executing the second step, it would be added to the index. Next commit would commit it to the repository. For avoiding this execute the following:
git update-index --assume-unchanged <path&filename>
Tracked, Untracked and Ignored Files
Git accepts three kinds of files: tracked, untracked, and ignored. Ignored files are the ones that are ignored by Git. Tracked files are the files that were in the last snapshot. They can be unmodified, modified, or staged. Untracked files are the files in your working directory that were not in your last snapshot and are not in your index.