Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-hub for windows revert

Tags:

git

github

I am in a very stupid situation now. Playing with git-hub for windows I have reverted my last two local commits, and I can't undo this (revert command). A lot of code have gone. Is it posible restore reverted commits? I am new at git.

like image 432
capone Avatar asked Nov 24 '25 03:11

capone


1 Answers

No worries. You can get your code back.

One way is to revert the commits that reverted your work. List your last commits using git log then git revert your previous reverts.

Another is to reset your master to a point before your reverts. This will be the cleanest way if the two last commands were the two reverts. Then you can do

git reset --hard HEAD~2

As Srdjan Grubor points out, if you cannot find your commits using git log you can go look for them in git reflog which shows you where your HEAD has been lately, even after such commands as git reset.

like image 181
Klas Mellbourn Avatar answered Nov 25 '25 17:11

Klas Mellbourn