Q: You accidentally committed a 500 MB video file three commits ago. The file was deleted in a later commit, but the repo is still huge. Why, and how do you actually remove it?
Deleting a file in a new commit does not remove it from history. Git stores every version of every file as an immutable blob object. The ...
🛠️ Production Runbook & Step-by-Step Resolution
Initial Diagnostics & Root Cause Analysis
Deleting a file in a new commit does not remove it from history. Git stores every version of every file as an immutable blob object. The 500 MB blob is still in the object database, reachable from the old commit. Every clone downloads it.
- Force-push all branches:
git push --force --all && git push --force --tags. - Every teammate must re-clone (or
git fetch origin && git reset --hard origin/main). Their old local commits reference the rewritten SHAs and will cause confusion. - GitHub/GitLab may still cache the old objects — contact support to trigger garbage collection on the server, or wait for the platform's scheduled GC.
Remediation & Permanent Safeguards
Finding the large objects: Or use git-sizer for a comprehensive report. Removing the file from all history: The modern tool is git filter-repo (replaces the deprecated git filter-branch): This rewrites every commit that ever contained big-video.mp4, removing the file entirely. All commit SHAs from that point onward change. After rewriting: Prevention: set up Git LFS for large binaries, and add a pre-receive hook or CI check that rejects files above a size threshold.
git rev-list --objects --all | \
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | \
sed -n 's/^blob //p' | sort -rnk2 | head -20
- Force-push all branches: git push --force --all && git push --force --tags.
- Every teammate must re-clone (or git fetch origin && git reset --hard origin/main). Their old loc...
- GitHub/GitLab may still cache the old objects — contact support to trigger garbage collection on ...