There is a file that was being tracked by git, but now the file should not be tracked and is added on the .gitignore list.
However, that file keeps showing up in git status after it's edited. How do we force git to completely forget about it and stop tracking it?
To stop tracking the files we need to remove that file from the index.
To achieve this git has provided us with some commands as listed below:
To untrack a single file
git rm --cached filename
To untrack every file
git rm -r - cached .
this code removes any changed files from the index, after this code run
git add .
Now, it's time to commit the changes;
git commit -m "update .gitignore file"
These mentioned codes will update the .gitignore file but what if we had added the wrong file or if we need to track some files again.
Undo
git rm --cached filename
use
git add filename
to track this file again.
Hope this will help us all.
Top comments (0)