-2

I just initialized .git folder to my project with git init command. It was a problem and I just wanted to make git reset --hard and try again. But reset --hard command deleted all the files that I haven't committed yet. Right now it is a empty folder with just a .git folder :(.

Can I go back to initialized time that does not have any changes yet with git. Because there is also nothing in the recycle bin.

Alen Paul Varghese
  • 1,278
  • 14
  • 27

1 Answers1

2

You ran git add . before git reset --hard, right? If so, the good news is that you could still find the contents of the deleted files.

git cat-file --batch-check --batch-all-objects | grep blob

The command lists all the blob objects in the format of <sha1value> blob <size_in_byte>. They represent the contents of the added files. You can use git show <sha1value> or git cat-file -p <sha1value> to print the content.

The bad news is that there is no way to automatically bring back the names of directories and files. They are stored upon git commit, which you didn't run. If the directory structure is simple and the amount of the files is small, you could restore them by memory.

git show $sha1value > $filename
ElpieKay
  • 27,194
  • 6
  • 32
  • 53