17

I'm running Git 1.6.4.2. Garbage collection is failing saying "error: unable to find <SHA1>".

I've managed to determine that the missing object is a blob, and there is no way that I can get the blob file back. It seems that two scripts that run "git add" and "git commit" were running at the same time and managed to interfere with each other so that one committed a newer version of a file than the other, and the older version's blob vanished.

So I'm trying to roll back my repository to take out the commit that refers to the tree that refers to the missing blob.

I know which branch the commit was on, so I ran "git reset" on it to rewind to the parent of the duff commit. And I know that the branch was merged somewhere else, so I rewound that branch too. So as far as I know, the duff commit/tree/blob are not referenced by anything. But if I run git prune --expire=now followed by git gc then I still get an error about the missing object.

How can I query the Git database to find every tree object that contains the duff blob id? And how do I then find out what is causing Git prune to retain it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kbro
  • 4,754
  • 7
  • 29
  • 40
  • Tried `git fsck`? http://book.git-scm.com/4_maintaining_git.html – Marcin Gil Sep 08 '11 at 11:36
  • I'm not certain I understand what's happened. Can you report what `git fsck` says? – CB Bailey Sep 08 '11 at 11:37
  • 1
    After a bit more digging it turns out that my question is answered here: http://stackoverflow.com/questions/7201720/how-to-delete-a-blob-from-git-repo git prune wasn't pruning the stuff I'd wound back because the reflog was still referring to it - git reflog expire --exires=now --all fixed that and the referenced post gives a mechanism for running git lstree on every commit to find the referenced blob – kbro Sep 08 '11 at 11:37
  • Incidentally, git fsck said nothing at all - it didn't even tell me that I had a missing blob! – kbro Sep 08 '11 at 11:41
  • http://stackoverflow.com/questions/7201720/how-to-delete-a-blob-from-git-repo holds the answer – kbro Sep 08 '11 at 11:48
  • 2
    suggest you make your 'comment' an Answer. – Philip Oakley Sep 08 '11 at 12:25

2 Answers2

13

After a bit more digging it turns out that my question is answered here: How to delete a blob from a Git repo - git prune wasn't pruning the stuff I'd wound back because the reflog was still referring to it. Running

git reflog expire --expire=now --all

fixed that. Also, the referenced post gives a mechanism for running git lstree on every commit to find the referenced blob.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kbro
  • 4,754
  • 7
  • 29
  • 40
8

I had the same problem (missing blob) and the solution with

git reflog expire --expire=now --all

didn't do the trick. I found my solution in How can I fix a broken repository?.

This simple line,

git hash-object -w <file>

Fixed the missing blob.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lolo101
  • 400
  • 4
  • 7
  • `git hash-object -w ` allows you to reinsert a missing file in the repo. This is diametrically opposed to my problem. I wanted to remove a duff file from the repo, and `git prune` wasn't doing it because the reflog was still pointing to it. – kbro May 06 '15 at 09:29