git 索引文件小于预期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10076036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:25:03  来源:igfitidea点击:

index file smaller than expected

git

提问by karellm

This morning, I started getting this error from git:

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

fatal: index file smaller than expected

fatal: git status --porcelain failed

致命:索引文件小于预期

致命: git status --porcelain 失败

Any idea of what is happening and how to solve it?

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

回答by meagar

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.

然后您可以重新添加您尝试暂存的文件。

回答by Scott Paradis

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

回答by Misho Janev

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 shouldwork 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
  1. 备份您的文件,我将要说的应该可行,但以防万一。
  2. 删除 .git 文件夹
  3. 克隆您的存储库(在哪里无关紧要)我是在当前目录中完成的
  4. 将克隆创建的 .git 目录复制到当前目录中
  5. 删除克隆的目录 6. 可选,如果您再次使用分支结帐到它
  6. Git 状态现在应该按照预期跟踪更改,并且您的所有 git 命令都应该可以工作

My case was as described above, git had messed up its references... Git logwas showing "your branch seems to be broken" and git fsckwas 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.

我的情况如上所述,git 弄乱了它的引用……Git log显示“您的分支似乎已损坏”,git fsck并警告我有关错误引用的警告。想过我是否可以修复它,但我会花很多时间去做,所以我选择了丑陋的解决方法。