0

I am new to Git and not sure how to recover deleted files. I made some changes to python code on my local machine and then pushed it to GitHub. Realised it might be a bad idea to add to the main repository (and decided to fork the repository instead) so deleted those commits using git reset --hard. I realised that deleting commit from GitHub removed all the changed files from my local machine too so all my work is lost.

$ git log --diff-filter=D --summary | grep delete doesn't return anything

rgoy
  • 1
  • Deleting *commits* is very different from (and more difficult to *recover* from) than deleting *files*. Commits are meant to stick around forever, so Git makes it hard to truly delete them. As long as you still have your original repository, you probably still have the commits, captured through what Git calls your "reflogs". Note that stuff pushed to GitHub *does not* include your reflogs, though! – torek Jun 29 '17 at 23:20
  • Thanks! Indeed reflog captures those commits - how can I recover them? – rgoy Jun 29 '17 at 23:31
  • There are many options. See, e.g., https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1 – torek Jun 29 '17 at 23:38
  • Thank you so much! – rgoy Jun 29 '17 at 23:57
  • Possible duplicate of [How can I undo git reset --hard HEAD~1?](https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1) – 1615903 Jun 30 '17 at 05:56

0 Answers0