Interview Prep/Git & GitHub/Lost Work, HEAD and History Problems

`error: index file smaller than expected` or `fatal: index file corrupt`

AdvancedTroubleshootingLost Work, HEAD and History Problems
Answer

Likely causes → .git/index was truncated by a crash, full disk, or cloud sync tool. The index is only a cache of the staging area, so objects are normally safe.

Diagnose →

ls -l .git/index
git fsck --full
df -h .

Fix → Rebuild the index from HEAD: rm .git/index && git reset. Working tree files stay as they are, and you re-stage what you need (git status shows the differences).

Prevent → Do not keep repositories inside Dropbox or OneDrive, and monitor disk space.

All Git & GitHub questions Roadmap: Git & GitHub

More on Lost Work, HEAD and History Problems