Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to undo commit

Hi I want to undo my last commit. What I did is I made some changes to file then I commit them but I have not push them to main repo yet. After git commit -m "comment" command I ran git status and I got this message

Your branch is ahead of 'origin/demo' by 1 commit

So now I want to undo my last commit so how can I do that?

like image 201
Om3ga Avatar asked Mar 16 '12 13:03

Om3ga


2 Answers

If you want to undo it completely:

git reset --hard HEAD^

If you want to undo it and keep your changes staged (before commit):

git reset --soft HEAD^

If you want to undo it and keep your files modified (before stage):

git reset --mixed HEAD^
like image 101
ralphtheninja Avatar answered Sep 23 '22 17:09

ralphtheninja


To revert your commit by creating another commit (assuming master is your working branch):

git revert master

To undo it, ie, pretend it never happened:

git reset --hard master~
like image 43
koush Avatar answered Sep 25 '22 17:09

koush