33

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
Vikas
  • 24,082
  • 37
  • 117
  • 159
  • 1
    See [this](http://stackoverflow.com/questions/25527812/git-corrupted-repo-how-to-pick-a-git-object-from-a-clean-repository) and [this](http://stackoverflow.com/questions/4254389/git-corrupt-loose-object) – pRaNaY Jun 10 '16 at 04:24
  • When I opened a file `8b/0fd4094630fea108b60faa15535ffbc85d87cb`, its `0000 0000` or `NULL NULL NULL...` – Vikas Jun 10 '16 at 04:39

2 Answers2

53

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 .git first. Then I use git fsck command

$ 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/fe6f16c7e8246d61150f0bc42629dbb532b5ce and continuing these steps until I get following output:

$ 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)

Voila! Now I was able to pull and push!

P.S. learned from here

Community
  • 1
  • 1
Vikas
  • 24,082
  • 37
  • 117
  • 159
  • 1
    After deleting those objects getting unresolved deltas for deleted objects – Dinesh Chitta Mar 17 '17 at 03:59
  • 1
    @Vicas: Can you please elaborate on what exactly did you mean by "...removed all three refs..."? Do you mean simply deleting these files? Deleting their contents? – MeirG May 02 '17 at 16:53
  • @Vikas: Sorry, I misspelled... Please see above. Thanks! – MeirG May 03 '17 at 06:06
  • Is it necessary to delete the references in .git/refs/remotes/origin? After following the first two steps I was able to run "git status" successfully. – Axel Aug 07 '17 at 14:49
  • after I've got only `dangling blob` logs I've runned `git prune` and all these logs gone away. – Anatoliy Litinskiy Aug 12 '20 at 13:06
2

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

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • Indeed. What a find. How Malwarebytes corrupted the HEAD of the master branch (local and remote) is a mystery. I wasn't even committing, fetching nor pushing (although PHPStorm was running). But it blue screened my Win10, a very rare occurrence. Time to kick Malwarebytes of my system. – Dimitri Mostrey May 22 '23 at 06:15
  • @DimitriMostrey: Yes, it turns out it also blocks random websites such as my own which isn't very cool, plus the constant nags to buy premium haha. I guess it's good riddance. – BullyWiiPlaza May 22 '23 at 10:31