Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert an unnecessary "git reset HEAD~1"

Tags:

git

After running git reset HEAD~1, I noticed that actually there was nothing else to do and the commit was fine. Is there a way to revert this command?

like image 572
cahen Avatar asked Jun 05 '13 16:06

cahen


People also ask

How do I undo git reset HEAD 1?

So, to undo the reset, run git reset HEAD@{1} (or git reset d27924e ). If, on the other hand, you've run some other commands since then that update HEAD, the commit you want won't be at the top of the list, and you'll need to search through the reflog .

How do I revert back to a git head?

To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).

How do I get my changes back after resetting git hard?

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

Does git reset HEAD keep changes?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


1 Answers

You can use:

git reset HEAD@{1} 

This uses the last entry in the reflog. See git reflog if you did other things in between.

like image 138
michas Avatar answered Oct 12 '22 22:10

michas