index file smaller than expected

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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 - Git

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 - Git

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!).

  1. Make backup of your files, what I am about to say should work but do it just in case.
  2. Remove the .git folder
  3. Clone your repository (does not matter where) I did it in the current directory
  4. Copy the created from the clone .git directory into your current directory
  5. Remove the cloned directory 6. Optional, if you used a branch checkout to it again
  6. 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkarellmView Question on Stackoverflow
Solution 1 - Gituser229044View Answer on Stackoverflow
Solution 2 - GitScott ParadisView Answer on Stackoverflow
Solution 3 - GitMisho JanevView Answer on Stackoverflow