Reputation: 15440
How would I "rollback" the last commit in git without deleting any changes?
This is something I've done often in hg:
Upvotes: 23
Views: 3664
Reputation: 683
Try this:
git reset --soft HEAD^
I found it to be the same of 'hg rollback', because:
You can also create a rollback
git alias like this:
git config --global alias.rollback 'reset --soft HEAD^'
So, you can now just type git rollback
to have exactly the same command that you have on Mercurial.
Upvotes: 22
Reputation: 440
I was trying to do an hg rollback in my git repository and I managed using
git reset HEAD~
this left me with my changes in the working directory but now unstaged. Source
Upvotes: 1
Reputation: 13406
With git you may actually prefer to use the --amend
option in that case.
git commit --amend
and edit the notesIf you need to rollback for other reasons take a look at git revert
Upvotes: 20
Reputation: 2959
In this specific instance I would git commit --amend
. If you haven't pushed yet and you've already committed other changes then you can also use git rebase -i
to edit whichever commit you want.
Upvotes: 3