21

I seem to have a corrupted repo that I have no idea how to fix...

$ git pull
remote: Counting objects: 141, done.
remote: Compressing objects: 100% (90/90), done.
error: unable to unpack ff7fca002656ad848c44bf134088d638a01d5217 header
error: inflateEnd: stream consistency error (no message)
fatal: SHA1 COLLISION FOUND WITH ff7fca002656ad848c44bf134088d638a01d5217 !
fatal: index-pack failed
Unable to write to standard output: The pipe is being closed.

And this is the output from the fsck:

$ git fsck
error: unable to unpack 024e257c1a13532e7d5579b0ea4bb5915d21e4a6 header
error: inflateEnd: stream consistency error (no message)
fatal: loose object 024e257c1a13532e7d5579b0ea4bb5915d21e4a6 (stored in super/sectet/path/to/repo/.git/objects/02/4e257c1a13532e7d5579b0ea4bb5915d21e4a6) is corrupt

Any ideas on how to approach this? I basically want to get whatever is in the remote and push my few commits on top of that.

ddinchev
  • 33,683
  • 28
  • 88
  • 133
  • 1
    Make a fresh clone of the remote, copy the changed files into fresh working copy, make a new commit and push. – merlin2011 May 30 '14 at 22:08
  • 1
    See also [this question](http://stackoverflow.com/questions/4864740) (possible duplicate, but I'll withhold judgement) – mpontillo May 30 '14 at 22:09
  • I already read that question, it's a bit unrelated I think :( Will try reapplying the commits on a fresh repo clone... – ddinchev May 30 '14 at 22:10
  • I'm pretty sure (but not positive) that this means you have a corrupted pack file. The more interesting question is how to fix it, which I don't know. – torek May 30 '14 at 22:40
  • Maybe related?: [How would git handle a SHA-1 collision on a blob?](http://stackoverflow.com/q/9392365/456814). –  May 31 '14 at 04:03

4 Answers4

46

I ran into the same issue and ran:

git prune
git gc  

which mentioned:

error: bad ref for refs/remotes/origin/ticketName

So i removed the reference and that fixed the issue:

rm .git/refs/remotes/origin/ticketName
Rizier123
  • 58,877
  • 16
  • 101
  • 156
depperm
  • 10,606
  • 4
  • 43
  • 67
  • 2
    If the outdated refs get too annoying you can also do a git pull -f origin, which forces the update of the local db. Then also do the things stated in this answer. – Chaim Eliyah Jul 17 '15 at 16:53
  • I tried prune and got `error: could not read asdf34tuj3wg9wg09w5g fatal: bad tree object asdf34tuj3wg9wg09w5g` if i do gc I get `warning:reflog of 'refs/stash' references pruned commits` before those two lines and then `error: failed to run repack` after those two – Aequitas Oct 28 '15 at 22:50
  • 2
    For Windows: del .git/refs/remotes/origin/ticketName – Haseeb Jadoon Apr 27 '16 at 13:53
  • I did this, removing the bad reference, and then had to do `git gc` again. Then I was able to fetch without problems. – bcr Jun 07 '16 at 20:37
8

I think the repo got corrupted by either EGit or SourceTree (which I use in parallel) and has nothing to do with actually hash collisions. I solved it, as suggested by comments, by cloning the remote as a new repo, and copying my changes over.

ddinchev
  • 33,683
  • 28
  • 88
  • 133
6

I have a similar issue and solved it by running:

$ git prune
Output: fatal: unable to parse object: refs/heads/prod-283

and just delete the reference above:

$ rm -f .git/refs/heads/prod-283

and finally I am able to run git pull

rfajarachmad
  • 61
  • 1
  • 1
  • thanks, this solved an issue I had. I did not want to clone the repository since it was too large. – tmp dev Oct 26 '17 at 20:59
0

I ran the following commnads:

git prune
git gc 

and removed file .git\refs\remotes\origin\master (the one listed in error: bad ref)

and ran

git gc --prune=now

which fixed the issue.

kumar
  • 1,814
  • 1
  • 24
  • 35