I'm using Mercurial and I've got into a terrible mess locally, with three heads. I can't push, and I just want to delete all my local changes and commits and start again with totally clean code and a clean history.
In other words, I want to end up with (a) exactly the same code locally as exists in the tip of the remote branch and (b) no history of any local commits.
I know hg update -C
overwrites any local changes. But how do I delete any local commits?
To be clear, I have no interest in preserving any of the work I've done locally. I just want the simplest way to revert back to a totally clean local checkout.
A simple way to 'uncommit' your last commit is to use hg strip -r -1 -k. In case the link breaks, the documentation mentioned by @phb states: hg rollback Roll back the last transaction (DANGEROUS) (DEPRECATED) Please use 'hg commit --amend' instead of rollback to correct mistakes in the last commit.
When the simplest way (a new hg clone
) isn't practical, I use hg strip
:
% hg outgoing -l 1 % hg strip $rev # replace $rev with the revision number from outgoing
Repeat until hg outgoing
stays quiet. Note that hg strip $rev
obliterates $rev
and all its descendants.
Note that you may have to first enable strip
in your Mercurial settings.
PS: an even smarter approach is to use the revset language, and do:
% hg strip 'roots(outgoing())'
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