index file smaller than expected

前端 未结 3 1035
滥情空心
滥情空心 2021-02-01 00:25

This morning, I started getting this error from git:

fatal: index file smaller than expected

fatal: git status --porcelain failed

相关标签:
3条回答
  • 2021-02-01 00:54

    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.

    0 讨论(0)
  • 2021-02-01 00:56

    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.

    0 讨论(0)
  • 2021-02-01 01:01

    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
    
    0 讨论(0)
提交回复
热议问题