Undo a git reset --hard origin/master

25.1k views Asked by At

Working on local master branch:

git commit -m "Lots of important commits"
git reset --hard origin/master

How can I retrieve the commits that have been lost as a result of the git reset (from the remote)?

EDIT: note this is not about retrieving uncommitted changes.

1

There are 1 answers

1
Gabriele Petronella On BEST ANSWER

If you committed it, nothing is lost.

If you have the reference of the commit, you can just git reset --hard <sha> to that precise commit.

In case you don't you can always use git reflog to retrieve the sha before performing the hard reset.

For instance if git reset --hard origin/master is the last command you run, you can do

git reset HEAD@{1}