Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Recover Local Commit

Tags:

git

github

I've been working on a project.

I ended up having several errors start happening on me. Thinking that I did something stupid, I wanted to check a previous commit.

So I first did this:

git add .
git commit -am 'half baked code'

I did not push it up (since I wasn't sure if I broke anything).

I then did:

git checkout xdfsfsfs 

grabbing a previous commit where I know everything worked.

I'm not trying to get back to my unpushed local commit.

git reset --hard

seems to bring me back to the latest commit on github, but not to the local commit.

git log doesn't show my commit

Is there anyway for me to recover the local commit? Or do I just need to re-code it? :)

like image 487
Tom Hammond Avatar asked Jan 24 '26 09:01

Tom Hammond


1 Answers

You're looking for git reflog

This shows all actions undertaken in git even if not saved.

To fix this you're going to want to do

git reflog

Find the sha of the commit you made previously

git checkout SHA

git checkout -b mycommit

now you can merge this into your master or wherever it needs to go.

like image 124
Pandelis Avatar answered Jan 26 '26 00:01

Pandelis



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!