Fix Git "object not found" for good

14,676

Solution 1

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.

Solution 2

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.

Share:
14,676
Lanbo
Author by

Lanbo

Updated on June 27, 2022

Comments

  • Lanbo
    Lanbo almost 2 years

    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?