Accidentally Deleted my files

The situtation I have right now is that I have a folder “Java” and inside I placed “Pokemon Arena” folder, which I wanted to turn into it’s own repo.  I used this line of code, not knowing what I was doing… _ git filter-branch --prune-empty --subdirectory-filter Pokemon\ Arena\ nt/ master _ (master was also the name of my old branch, thinking i’ve rewrote the branch). I then proceeded to commit and force push, losing all of my java files. I’m new to github, would greatly appreciate the help and support :slight_smile:

I think you pretty much rewrote the entire Git history of your repo. However, the accepted answer here: mentions some kind of backup folder. I do reccommend that you first make a backup locally of the current state before executing more commands in order not to lose more things.


Would I use

git reset --hard refs/original/refs/heads/master

To restore ?

I don’t know if it will work, however if you’ve copied the folder containing the repo locally you have nothing to lose.  Be absolutely sure to have a copy of the repo folder!


Thank you for your help! It restored everything back to where it was. Lesson learned to always have back ups of my files ;D

How did you do it to restore all the deleted files,would you mind helping me ?

Wow! I’m a git newb and found myself in the same position. When trying to commit and push changes I’d find that the new files I created were all gone. Literally a whole day’s worth of work down the drain. But the command you posted DID THE TRICK! Like magic, my files are back! Thank goodness!!!

1 Like

I just about jumped off the roof literally when my 2 month old project was deleted after I reverted my initial commit.  I was in the process of getting this project out to our Gitlab server and noticed that the commit had files I had in the gitignore but I guess I need to specify the full path.  Any way I reverted the commit and then  all my files went poof.  So for those that are frantic, here is what I did:

git reset --hard HEAD@{integer}

In my case, integer was 0.  Once I ran the command:

HEAD is now at a35df4a Initial commit

All is good.  I have just copied everything to my NAS:-)  Not taking any chances. 

1 Like