Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix Git "object not found" for good

From one pull to the next, every git pull on the server ends up in this:

$ git pull
remote: Counting objects: 53, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 32 (delta 19), reused 0 (delta 0)
Unpacking objects: 100% (32/32), done.
error: unable to find 71682baccff823caa21420b16dd231c6b9c1b133
fatal: object 71682baccff823caa21420b16dd231c6b9c1b133 not found

Same with git fetch. I could solve this for one pull by copying the file .git/object/71/682baccff823caa21420b16dd231c6b9c1b133 to the server, but after some more pulls, the error was still there, every time with the newest commit object on the branch.

How can this happen? And how can I fix it for good?

A complete git clone is not a good solution since this repository is on a running server project and has more files around without git control.

Is it possible to clone into a new directory and then copy the .git directory into the old folder? Or is there any other solution without touching the directories?

like image 908
Lanbo Avatar asked Mar 12 '13 19:03

Lanbo


2 Answers

I'm running a development team, with a corrupt git repository, as we've not time to fix it yet. I've found a number of things keep the ball moving, which might help.

Firstly have a single machine with [gc] auto=0 and unpack the entire repo, to objects

Secondly git 1.8 seems to handle problems better than 1.7, so have a machine with git 1.8 with access to the file systems containing the source.

Thirdly always git fetch from the 1.8 machine and then git pull from the 1.7 machine

Fourthly when even 1.8 can't git pull, you need to run git fsck |grep missing and manually copy the objects from the unpacked repo into the object store on the damaged repo (where missing 0c0ef24... will be in objects/0c/0ef24...)

It's a mystery to me why git fetch/pull doesn't realise these are missing from the local git and get them from origin, but it seems manually doing the fetch makes git happy again. Once you've manually fixed a git repo run git gc (but not on the unpacked machine or you'll need to find the missing objects before you can manually fix things again, which is annoying)

What would be really handy is a command to tell git to get a specific object from origin, but I guess it would be even better if it did it without needing to be asked :-)

Hope that helps.

like image 71
Simon Bazley Avatar answered Oct 23 '22 13:10

Simon Bazley


I could fix the problem by

  1. Try to fetch (with the error)
  2. Copy the object file over like above
  3. git merge with the commit of the missing object file.

Now it seems solved, the error does not appear again.

like image 27
Lanbo Avatar answered Oct 23 '22 13:10

Lanbo