索引文件小于预期

今天早上,我开始从 git 得到这个错误:

索引文件小于预期

致命 Git 状态,瓷器失败

知道发生了什么,以及如何解决吗?

70472 次浏览

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.

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

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.