Modern QA2026Fixing Accidentally Committed Files — tiles
Log inJoin
52 / 57 · 17 Git & Version Control · Gitignore and Practical Tips← prev⊞ allnext →☰ Read as one page

7.4Fixing Accidentally Committed Files

If someone already committed a file that should be ignored, adding it to .gitignore does not remove it from tracking. You must explicitly untrack it.

# Remove file from Git tracking without deleting it locally
git rm --cached test-results/report.html

# Remove an entire directory from tracking
git rm -r --cached test-results/

# After removing, add to .gitignore and commit
echo "test-results/" >> .gitignore
git add .gitignore
git commit -m "chore: stop tracking test results, add to .gitignore"

For large files that have been in the history for a while and are bloating the repo, you may need git filter-branch or BFG Repo-Cleaner to rewrite history. This is a destructive operation -- coordinate with the team first.