This script will restore all the objects in your .git/objects
folder.
To start, you must identify what the "root object" is. This will be a tree
object that lists out the files that are in the root of your git repository.
Once you have that object identified, this script will recursively walk through the tree and restore all the files that git knows/knew about.
background
I started working on a new project and got quite a bit of work done locally before initializing a git repo or creating any commits.
When I decided it was time to commit, I ran git init && git add . && git commit
. At this point, I realized that there were some files I wanted to add to the .gitignore
, so I cancelled the commit and composed my .gitignore
file. At this point, I decided I'd re-add everything (now that I was ignoring stuff I didn't need) and ran git reset --hard
.
YIKES
This wiped out all the code I had written.
No attempts to recover would work (git reflog
was empty, git fsck
couldn't find any objects, git rev-log
had nothing). All I had what was left of the .git/objects
directory.
After some reading and understanding of how the git object data is stored and written, it became clear that I could recover my data by parsing these files by hand.
The attached script does exactly that.
What a Monday.
there are just 3 unique hashes and I have tried all - have pasted my results above
the ones starting with 1d0 and 90c threw error - scrn shot shows that err
the 0nly hash that returned without error was b66 >> but my files were not recovered from .git/objects folder.
I see 180MB+ as size of .git/ and objects folder have several sub-folders with 2 digit folder names. why is this GIT so complicated. what kind of technology that moves my files into whatever folder without my permission.