My development repository at some point lost an object.
$ git fsck
fatal: failed to read object 2dddc84156fa30e4614a7ea5a1895885011b8db8: Invalid argument
$ git cat-file -t 2dddc84156fa30e4614a7ea5a1895885011b8db8
error: unable to find 2dddc84156fa30e4614a7ea5a1895885011b8db8
fatal: git cat-file 2dddc84156fa30e4614a7ea5a1895885011b8db8: bad file
A freshly cloned repository has that object.
$ git cat-file -t 2dddc84156fa30e4614a7ea5a1895885011b8db8
tree
I would like to keep my development repository, it has unpushed branches and stashes.
How can I patch that object into my broken repository?
git-repair can repair various forms of damage to git repositories. It is a complement to git fsck, which finds problems, but does not fix them. As well as avoiding the need to rm -rf a damaged repository and re-clone, using git-repair can help rescue commits you've made to the damaged repository and not yet pushed out.
Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.
I recently had a bunch of missing objects in a local repository and an uncorrupted reference repository to restore it from. Here's the magic I came up with that worked for me:
cd <path-to-local-repo>
git unpack-objects < <reference-repo-path>/objects/pack/pack-<hash>.pack
It turns out that all of the objects I needed were in a pack file in the reference repository instead of in separate "loose" object files. This simple incantation unpacks that pack file into the local database, filling in the holes. After doing
git gc
to cleanup any dangling commits (i.e. due to rebasing, amend commits, etc.) my git fsck is now clean.
What you can try, is to get the file .git/objects/2d/ddc84156fa30e4614a7ea5a1895885011b8db8
from the freshly cloned repository and copy it to your development repo ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With