0

Please help! I've been working between several computers and wanted to keep track of my non-programming schoolwork. I set up an initial repository on Github, initiated that on my local machine, and then proceeded to add all files in my school directory, commit those files, and then attempted to push them to the repository. However, I did not realize how large the GIS files were, so the push kept failing. I wanted to go backward so that I could create a .gitignore file to skip over the large files, and tried to following command to clear out the commit:

git reset --hard HEAD~

I had no clue that this wouldn't just untrack the files, but delete them from my file system. Now I have lost my entire school directory.

Can anyone suggest how to recover any of the files? I can't find an answer elsewhere.

EDIT: The answer below worked great, here's the result:

D:\Documents\College\Masters\[MyUniversity]>git reflog
99b0b97 (HEAD -> master, origin/master) HEAD@{0}: reset: moving to 99b0b97
99b0b97 (HEAD -> master, origin/master) HEAD@{1}: reset: moving to HEAD~
a291e5a HEAD@{2}: reset: moving to HEAD
a291e5a HEAD@{3}: commit: added all files
99b0b97 (HEAD -> master, origin/master) HEAD@{4}: commit (initial): first commit

D:\Documents\College\Masters\[MyUniversity]>git reset --hard a291e5a
Updating files:   0% (37/8608)            
1
  • Please forgive the initial freakout... I panicked and forgot about my automatic backups. I have a backup of everything, but it would still be a good thing to know if there is a way to undo a git reset.
    – jtoepp
    Commented Jan 17, 2020 at 21:29

1 Answer 1

2

get the revision of the commit using git reflog and then reset to it:

git reset --hard the-id-of-the-commit-from-reflog
1
  • Fantastic, thank you! Resetting to the second revision restored my files. I updated my question above to show the result.
    – jtoepp
    Commented Jan 17, 2020 at 21:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.