0

I have a project where I am using git. My code has not been pushed to a server. It was on my local machine only.

I want to undo the last commit, so I executed git reset --hard HEAD~1 But that command deleted the files from the project instead of undoing the last commit. How can I undo the git reset --hard HEAD~1 command to my work isn't lost?

When I executed the it reset --hard HEAD~1 I got HEAD is now at 7a524b86f not sure

pkamb
  • 33,281
  • 23
  • 160
  • 191
Jay
  • 1,168
  • 13
  • 41
  • The problem is that my code is not on the server. It was on my local machine only – Jay Oct 10 '21 at 03:55

1 Answers1

0

Case 1: If your change made only on client, you cannot come back.

Case 2: If your change made has on server, you didn't push, therefore, you can get back.

Case 3: If your change made on server, you pushed, therefore, you can get back.

Case 4: Your commit has exists on another branches, you can git cherry-pick come back.

Trick: If you use IntelliJ IDEA, WebStorm, PyCharm, you can use feature local history to get back.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 1
    The changes were on my local machine only! please tell me I did not loose 2 weeks worth of work! – Jay Oct 10 '21 at 03:34
  • You cannot get back, because it stands on client, no exist on server. – Vy Do Oct 10 '21 at 03:35
  • does that delete all the files from my local PC? Is there a temp place it get placed in? Lots of code will be lost of I can't get it back. I am using visual studio – Jay Oct 10 '21 at 03:40
  • No out-of-the-box local history feature for Visual Studio IDE, see https://stackoverflow.com/a/13018711/3728901 . – Vy Do Oct 10 '21 at 03:43
  • If you didn't commit the code, it's gone. – Daniel Mann Oct 10 '21 at 03:44