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 500 MB blob is still in the object database, reachable from the old commit.
Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: Understanding of Git's object model and history rewriting for large files.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
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 ...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring accidentally committed video
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring accidentally committed video Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring accidentally committed video
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring accidentally committed video Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.