Contents
✅ Repair Git Broken Object / EntryNotFound (WSL / VS Code)
1️⃣ Backup working tree
tar czf /tmp/repo-backup.tar.gz .
2️⃣ Fetch remote state
git fetch origin
3️⃣ Create clean branch from remote
git checkout -B recoverBranch origin/main
4️⃣ Restore file content from broken branch
git checkout main -- .
Copies tracked files only.
(tar restore is safer if corruption is severe.)
5️⃣ Rebuild objects
git add .
git commit -m "Recover working tree from broken main"
6️⃣ Replace broken main
git checkout main
git reset --hard recoverBranch
7️⃣ Cleanup dangling / corrupted objects
git reflog expire --expire=now --all
git gc --prune=now
8️⃣ Verify
git fsck --full
Must output nothing.
9️⃣ Push
git push origin main --force
Use --force only if history changed.
✅ What you learned (important)
EntryNotFound+missing blob= Git object DB corruption.git rm --cacheddoes not fix object corruption.- Never merge corrupted history.
- Always rebuild commits from file content.
git fsckis the truth source.
✅ Prevention tips (WSL + VS Code)
- Avoid editing same repo from Windows + WSL simultaneously.
- Don’t keep uploads / runtime files in Git.
- Add to
.gitignore:
uploads/
.vscode-server/
- Run occasionally:
git fsck --full