Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a git reset --hard origin/master [duplicate]

Tags:

git

git-reset

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.

like image 381
chrisjleu Avatar asked Nov 13 '14 17:11

chrisjleu


People also ask

How do I undo git reset hard origin?

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.

Can you recover from git reset hard?

We can use the command git fsck to recover the files after a hard reset.

How do I undo git origin master?

There is no command to explicitly undo the git pull command. The alternative is to use git reset, which reverts a repository back to a previous commit.


1 Answers

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}
like image 62
Gabriele Petronella Avatar answered Oct 10 '22 01:10

Gabriele Petronella