Fixing "fatal index file smaller than expected" error

Earlier today I accidentally corrupted my git index file and got the following error message fatal index file smaller than expected

Luckily, I didn't have any staged changes, so I ran the following commands to reset and fix it.

$ rm .git/index
$ git reset HEAD .

more Git posts