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
  • 30,595
  • 22
  • 143
  • 179
Jay
  • 633
  • 2
  • 15
  • 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.

James Graham
  • 39,063
  • 41
  • 167
  • 242