Recovering deleted git repository

Using PhotoRec to recover lost data
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Message
Author
User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Recovering deleted git repository

#11 Post by cgrenier »

I have quickly check several git tree and only found files beginning by 0x7801.
pack files https://git-scm.com/docs/pack-format may also interesting to recover

Code: Select all

pack  0 "PACK" 0x00000002
Feel free to work on adding git support to PhotoRec: copy src/file_gz.c to src/file_git.c, edit the copy, edit also src/Makefile.am and src/file_list.c...

gituser
Posts: 8
Joined: 14 Oct 2021, 11:53

Re: Recovering deleted git repository

#12 Post by gituser »

cgrenier wrote: 18 Oct 2021, 17:53 Feel free to work on adding git support to PhotoRec: copy src/file_gz.c to src/file_git.c, edit the copy, edit also src/Makefile.am and src/file_list.c...
But what would be the result? A bunch of recovered object and pack files with a new extension like ".gitobject", which need to be later sorted by the user, or is it possible to gather them together somewhere in a recup_dir.XXX/.git/ folder making a repository which, with enough luck, can even be operational like in my case? Can I control the output folder where the recovered file is placed and rebuild the whole repository folder structure inside the recup_dir?

User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Recovering deleted git repository

#13 Post by cgrenier »

PhotoRec by-itself will not sort the recovered files. If PhotoRec recovers files from 2 or more git repositories, additional scripts will be needed to sort the mess.

gituser
Posts: 8
Joined: 14 Oct 2021, 11:53

Re: Recovering deleted git repository

#14 Post by gituser »

cgrenier wrote: 28 Oct 2021, 10:10 PhotoRec by-itself will not sort the recovered files. If PhotoRec recovers files from 2 or more git repositories, additional scripts will be needed to sort the mess.
Object files from two repositories can be placed in a single repository, git works just fine with commits and branches from different source trees in a single repository. They are always referenced by their hashes. Under sorting I mean extraction the full path to an object inside the .git folder. For a git object not only a filename but also a folder can be extracted from its hash value. I.e. call file_rename(file_recovery ...) with a name containing "/". For example for an object with hash c66c2c22a...b9 pass a real .git/objects/c6/6c2c22a...b9 file path as its filename instead of an artificial single level c66c2c22a...b9.gitobject filename. If this is not possible than ok.. I can return "c66c2c22a...b9.gitobject" and add a note to the manual on how to sort them.

Locked