Ignore files that have already been committed to a Git repository
caching, git, git-rm, gitignore, version-control
Solution
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: `git rm --cached filename`
To untrack every file that is now in your `.gitignore`:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
To undo `git rm --cached filename`, use `git add filename`.
Make sure to commit all your important changes before running `git add .` Otherwise, you will lose any changes to other files.
Please be careful, when you push this to a repository and pull from somewhere else into a state where those files are still tracked, the files will be DELETED
Problem
I have an already initialized Git repository that I added a `.gitignore` file to. How can I refresh the file index so the files I want ignored get ignored?
Related problems
- .gitignore is ignored by Git
- git rm --cached file vs git reset file
- How do I make Git forget about a file that was tracked, but is now in .gitignore?
- Can I get a list of files marked --assume-unchanged?
- Git: Ignoring Version-Controlled Files
- How to revert a "git rm -r ."?
- How to prevent git stash dropping changes to files with the "assume unchanged" bit?
- How do I make Git forget about a file that was tracked, but is now in .gitignore?