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.
When the simplest way (a new
hg clone) isn’t practical, I usehg strip:Repeat until
hg outgoingstays quiet. Note thathg strip $revobliterates$revand all its descendants.Note that you may have to first enable
stripin your Mercurial settings.PS: an even smarter approach is to use the revset language, and do: