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?
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 .
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).
We can use the command git fsck to recover the files after a hard reset.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With