git 致命:无法读取对象 xxx:参数无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37739797/
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-09 04:15:41  来源:igfitidea点击:

git fatal: failed to read object xxx: Invalid argument

git

提问by Vikas

I am getting the following error if I pull for fetch from remote

如果我从远程拉取获取,我会收到以下错误

$ git pull
remote: Counting objects: 85, done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 85 (delta 63), reused 69 (delta 48)
Unpacking objects: 100% (85/85), done.
error: inflate: data stream error (unknown compression method)
fatal: failed to read object 8b0fd4094630fea108b60faa15535ffbc85d87cb: Invalid argument
error: http://myremoterepo.com/project.git did not send all necessary objects

I can commit locally. When I check status:

我可以在本地提交。当我检查状态时:

> $ git status On branch vikas Your branch is based on 'origin/master',
> but the upstream is gone.   (use "git branch --unset-upstream" to
> fixup) nothing to commit, working directory clean

回答by Vikas

Finally I was able to fix this issue. I think issue happened when my computer shutdown due to power cut.

最后我能够解决这个问题。我认为问题发生在我的电脑因停电而关机时。

I was able to commit any changes in any of my local branch. This means my pack file is no corrupted but some refs are invalid.

我能够在我的任何本地分支中提交任何更改。这意味着我的包文件没有损坏,但有些参考无效。

Back up your .gitfirst. Then I use git fsckcommand

备份你的.git第一个。然后我使用git fsck命令

$ git fsck --full
error: inflate: data stream error (unknown compression method)
error: unable to unpack 38fe6f16c7e8246d61150f0bc42629dbb532b5ce header
error: inflate: data stream error (unknown compression method)
fatal: loose object 38fe6f16c7e8246d61150f0bc42629dbb532b5ce (stored in .git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ce) is corrupt

I deleted the file .git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ceand continuing these steps until I get following output:

我删除了文件.git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ce并继续执行这些步骤,直到得到以下输出:

$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (168543/168543), done.
error: refs/remotes/origin/staging: invalid sha1 pointer 0000000000000000000000000000000000000000
error: refs/remotes/origin/development: invalid sha1 pointer 0000000000000000000000000000000000000000
error: refs/remotes/origin/master: invalid sha1 pointer 0000000000000000000000000000000000000000
error: bad ref for refs/remotes/origin/staging
broken link from  commit 8b0fd4094630fea108b60faa15535ffbc85d87cb
              to  commit bac9f287963b1abb9e4b376b44b4a6500018e9fe
Checking connectivity: 169821, done.
dangling blob 750718546640b5b14c19cbdb9958d7bcc4b1114c
dangling blob e313786318d4c76004728f15a25c6fa68c88b67e
dangling blob ee3fd85992b48173f6c344a9f4a2f9667d4e1940
dangling blob cd4898a3ec525e559292337c0bc6b68a77270b52
dangling blob 9973506f35af1bf4e7790be57b02c70852843f92
dangling blob 47ca4080b9a528efe23c9f7dce994815f5f9162a
dangling blob 39d6807d215a7e74fb987d951a90e1d3e24a97eb
dangling blob c0d650286c3702d56b827eded27eaa9515212847
dangling commit 53db70d776ec7a59c10db106ef2585abea1ffddd
...

Now I removed all three refs (.git/refs/remotes/origin/master, .git/refs/remotes/origin/staging, .git/refs/remotes/origin/development)

现在我删除了所有三个参考 ( .git/refs/remotes/origin/master, .git/refs/remotes/origin/staging, .git/refs/remotes/origin/development)

Voila! Now I was able to pull and push!

瞧!现在我可以拉和推了!

P.S. learned from here

PS从这里学到的

回答by BullyWiiPlaza

I got this error while having Malwarebytesrunning. A PC reboot did not help. Stopping the Malwarebytesprocess fixed it, though. Therefore, try disabling/stopping your virus scanner since that might also cause this problem.

我在Malwarebytes跑步时遇到了这个错误。PC 重启没有帮助。不过,停止该Malwarebytes过程修复了它。因此,请尝试禁用/停止您的病毒扫描程序,因为这也可能导致此问题。