I have a web project which I have been working on for some time. I use GIT with SourceTree to keep track of changes but foolishly had no proper backups in place.
I had about 50 commits and wanted to wipe the slate clean and start with a new initial state so I deleted the .git folder, however I messed things up in SourceTree which ended up deleting all the project files (although the folders remain for some reason).
I still have the .git folder which I deleted. My question is, can I recover the last known project state from this folder, and how would I go about doing this?
Say you have a folder like this (assuming windows here, but makes no difference):
c:\myrepo\.git
with "myrepo" being empty otherwise, just having .git folder which has its full contents, you can just do
cd c:\myrepo
git reset --hard HEAD
Which should recover all your files.
Note: Advise to do "CD into the .git folder and type git status" is wrong, that is expected to reply with "Fatal - this operation must be run in a work tree".
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