Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lost local commit when checking out a remote branch

I checked out the master branch, and did some changes. Then I committed my changes on the master branch but did not push it to repository.

What I did next is check out the remote master again. Then could not see my local commit anymore.

How could I get my local commit back?

like image 593
srssdu Avatar asked Jun 21 '26 22:06

srssdu


1 Answers

You need to reset the HEAD. Use the following to revert to the previous commit.

git reflog

This will give the list of all the commits with head values. Choose the HEAD for the commit you made to the local master branch.

Then, do the following,

git reset --hard HEAD@<i>
like image 93
Animesh Sharma Avatar answered Jun 23 '26 12:06

Animesh Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!