Undo git reset –hard before first commit

Yeah I did an oopsie maybe. I hope this question gets enough attention because the title sounds like many different other questions here on Stackoverflow, but none of the answers I’ve found worked. But let me explain first:

(Tired,) I decided to add all my .config files to git and push them. (I was stupid+tired enough to not backup).
I created a new repository with git init and added everything with git add -A. I then thought that making a .gitignore with some directories would be smart before adding and commiting everything, so I wanted to undo my git add -A.

That’s where the mistake happened, I used git reset --hard instead git rm --cached * to unstage the files.

Unfortunately, git did a git rm on everything, since there was no previous commit. And that’s where I am now. All config files gone. Many solutions like git update-ref -d HEAD, git reset (--hard) HEAD~1 and
git reset followed by git ls-files -d -z | xargs -0 git checkout -- don’t because there is no commit and no branch created yet.

I also tried to find the deleted directories and files in the .git directory or trash, but this didn’t work either.

Does one of you have an idea how I could get my config files back? All I want to do is to undo the git reset…

>Solution :

Git is about commits. That’s all it’s about. If there was a "good" commit that contains the stuff you’re looking for, then just find it in the reflog and check it out. But you cannot recover what was never committed.

Leave a Reply