James Andino
James Andino

Reputation: 25789

Recovering files from Git objects

I obliterated all my work and would prefer not to explain how.
The only thing I have left are the git objects. More then anything I would like to recover some of the loss packed Image files. From the size of the object files I can tell which ones they are. Is there a way to turn them back into usable files?

Upvotes: 7

Views: 3714

Answers (1)

knittl
knittl

Reputation: 265546

first thing: make a backup! then work on a copy of that backup.

if the git objects are still in the correct directory (.git/objects/xx/xxx…) you can use git fsck --full for git to discover them — it will probably list every object in your repository. now look for the ones labeled commit and tag, those are the ones you want to recover.

i would probably use a script which creates a branch for each commit object found (e.g. simply increnting numbers rescue-1, rescue-2, etc.). afterwards use gitk --all to visualize all your branches and pick the top (most recent) one. create a new branch there rescued-master.

checkout your new master branch and run git branch --no-merge. you should get a list of branched off commits, not contained in master. you probably want to give them a new branch name too.

after you're done, delete all the numbered rescue- branches.

hope that helps and gives a a starting point.

Upvotes: 6

Related Questions