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?
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^
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~
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