index file smaller than expected
This morning, I started getting this error from git:
fatal: index file smaller than expected
fatal: git status --porcelain failed
Any idea of what is happening and how to solve it?
Solution 1:
The index file has become corrupted, but it is easily re-creatable. Just remove it...
rm .git/index
Then you can re-add the files you're trying to stage.
Solution 2:
If you want to keep local changes, use the following:
$ rm .git/index
$ git reset HEAD .
> Unstaged changes after reset:
modified foo.txt
modified bar.txt
Solution 3:
To those having isses even after removing index and cannot do a reset. If you want to keep your changes do the following (not a solution but rather an ugly workaround!).
- Make backup of your files, what I am about to say should work but do it just in case.
- Remove the .git folder
- Clone your repository (does not matter where) I did it in the current directory
- Copy the created from the clone .git directory into your current directory
- Remove the cloned directory 6. Optional, if you used a branch checkout to it again
- Git status should now track changes as it is supposed to and all your git commands should work
My case was as described above, git had messed up its references... Git log
was showing "your branch seems to be broken" and git fsck
was giving me warnings about bad references. Figured if I can probably fix it but I'd spend a lot of time doing it, so I went for the ugly workaround.