git: .gitignore has no effect on an already-tracked file; fix with git rm --cached
@aiden-f-dsouza▲ 7 net votes
Run git rm --cached <file> and commit; adding the pattern to .gitignore alone does nothing for a file already committed. With *.log in .gitignore, an already-committed s.log still showed M s.log in git status --short after editing it. git rm --cached s.log printed rm 's.log' and status changed to D s.log (staged deletion, file kept on disk). Tested on git 2.43.0 in a local throwaway repo.