I was trying to solve a problem I was having with Django and used the command git reset --hard HEAD~50
not knowing it would revert all my files. I just lost a month of code. I'm looking for a fix right now but I wanted to post here instead of touching anything right now. It might be a simple fix but please help.
Asked
Active
Viewed 41 times
0

torek
- 448,244
- 59
- 642
- 775

Russell Hertel
- 121
- 3
- 14
-
2try running `git reflog` to see if you can fast forward to the last commit. Your working changes are gone since your last commit, but you should be able to move your git HEAD to the last saved commit – Jeremy Mar 01 '22 at 22:33
-
@eshirvana Thats the one Im looking at right now. Does it seem like a reliable option? – Russell Hertel Mar 01 '22 at 22:35
-
2Before you start making any additional changes, make a complete copy of your repository into a new directory. That way you can try different strategies for recovery without worrying about accidentally making recovery impossible. Recovering via `git reflog` and a subsequent `git reset`, as described in the linked question, should be easy and painless, but it pays to be careful when you find yourself in an unexpected situation. – larsks Mar 01 '22 at 22:37
-
1This is probably obvious to you by now - but in cases like this it really helps to push your commits to an online remote as well. You'll be able to recover from this locally, most likely, but for cases where you can't, you should have an off site backup. If someone in my team tells me they lost a month of code because they didn't have an off-site backup, I'd have to consider firing them. – Grismar Mar 01 '22 at 22:37
-
1...or using it as a teaching moment to help a junior developer grow into an senior developer (and ensure they don't make the mistake in the future!) – larsks Mar 01 '22 at 22:38
-
1@RussellHertel seems like it ! seems a lot of people got their problem solved by that answer. Nevertheless it's always a good idea to have backup – eshirvana Mar 02 '22 at 01:04
-
Yes, That solved it. Thank You so much everyone and for your fast responses. I'm 17 and trying to get a company off the ground and still learning and what you guys have done for me means a lot. Thank You! – Russell Hertel Mar 02 '22 at 01:54