Om3ga
Om3ga

Reputation: 32843

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?

Upvotes: 5

Views: 4753

Answers (2)

koush
koush

Reputation: 2962

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~

Upvotes: 1

ralphtheninja
ralphtheninja

Reputation: 133008

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^

Upvotes: 17

Related Questions