Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo "git revert head"?

Tags:

git

I wanted to discard changes in the current branch and without committing, I accidentally entered the command git revert HEAD. The changes in the prev branch (committed earlier) appear to be lost?

How can I undo agit revert HEAD command?

like image 376
swetha pvl Avatar asked Mar 01 '26 13:03

swetha pvl


2 Answers

You can do

git reset --hard HEAD~1

It will take you to the commit before the current HEAD.

like image 102
Bidhan Avatar answered Mar 04 '26 03:03

Bidhan


If you did not do a git push after reverting the commit, then Bidhan's answer is spot on. However, if you have pushed since then, you will want to revert your revert by simply doing git revert HEAD again.

like image 30
David Deutsch Avatar answered Mar 04 '26 03:03

David Deutsch



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!