0

I had a ton of files, pictures and documents in a git directory that was used for profile pictures and etc... I did an update to my production server and broke the site so I went and did a git reset --hard to the last working revision which lost all of the pictures and documents.

Is there a way to undo git's actions? I am hoping there is a way to get back to the way it was. Thank you for your time.

rapid3642
  • 913
  • 2
  • 14
  • 26
  • check this link, https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1 – cristian franco Aug 08 '17 at 23:48
  • Thank you so much for the link, but I saw that they said if you did --hard it wont be able to be recovered. So I might be literally screwed here :/ – rapid3642 Aug 08 '17 at 23:51
  • 1
    If you *did* add these files, even without later doing `git commit`, the files are at least temporarily squirreled away in the repository. If not, you are indeed s-word-ed. – torek Aug 08 '17 at 23:53
  • I did NOT add them, :( lol geez. The messes I cause :/ . Definitely a learning experience. – rapid3642 Aug 09 '17 at 00:01
  • git reset shouldn't do anything to untracked files afaik... you must have done something else beyond a reset – Devon Bessemer Aug 09 '17 at 01:37
  • Oh yeah? So If I have untracked files they shouldnt be deleted or removed when doing a git reset --hard? – rapid3642 Aug 09 '17 at 04:24
  • Your correct the files were NOT deleted, I thought that git reset --hard would delete everything in the git repository including files that have not been added to git in order to restore it to the complete state of the git commit i was restoring from. No files are deleted and the project is perfectly safe. thank you so much for your knowledge and insight on this :) Please make this an answer and I will accept it. I will use this as a learning experience and make sure to do lots of research before panic on here. :) – rapid3642 Sep 03 '17 at 20:32

2 Answers2

0

to undo git reset --hard try do a git reset --hard HEAD@{1} but if you did more things since you screwed up it might not work. do a git reflog to find the latest position of HEAD and do git reset --hard HEAD@{that_number_you_find}

OLIVER.KOO
  • 5,654
  • 3
  • 30
  • 62
0

you can see you moves with git log and the identificator of the commit if you see you commit you can get the files

cristian franco
  • 266
  • 2
  • 13