There's this file that was being tracked at one time by git
, but now the file is on the .gitignore
list.
However, that file keeps showing up in git st
after it's edited, so how would you force git
to completely forget about it?
There's this file that was being tracked at one time by git
, but now the file is on the .gitignore
list.
However, that file keeps showing up in git st
after it's edited, so how would you force git
to completely forget about it?
move it out, commit, then move it back in. This has worked for me in the past. There is probably a 'gittier' way to accomplish this.
Move or copy the file to a safe location, so you don't lose it. Then git rm the file and commit. The file will still show up if you revert to one of those earlier commits, or another branch where it has not been removed. However, in all future commits, you will not see the file again. If the file is in the git ingore, then you can move it back into the folder, and git won't see it.
I accomplished this by using git filter-branch. The exact command I used was taken from the man page:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
This command will recreate the entire commit history, executing git rm
before each commit and so will get rid of the specified file. Don't forget to back it up before running the command as it will be lost.
.gitignore
will prevent untracked files from being added (without an add -f
) to the set of files tracked by git, however git will continue to track any files that are already being tracked.
To stop tracking a file you need to remove it from the index. This can be achieved with this command.
git rm --cached <file>
The removal of the file from the head revision will happen on the next commit.