How do I git reset --hard HEAD on Mercurial?

The Hg Manual’s GitConcepts page explains how to do many actions git users are familiar with in Mercurial.

Mercurial doesn’t have any built-in git reset --hard behavior. However, the strip extension provides a strip command which does. To use, first enable strip in your ~/.hgrc file::

[extensions]
strip =

Note: this extension is shipped in new in Mercurial 2.8. Prior versions provided the strip command in the mq extension.

Now you can run commands like hg strip or even hg help strip. To remove a changeset and all of its children, simply specify that changeset as an argument to hg strip. For example, to remove the last commit you just made (after you used commands which caused hg rollback to report that there is no longer any transaction to rollback), you can remove the tip revision. Each time you run this command, another revision will be removed. hg strip’s actions should be considered irreversible; unfamiliar users should make backups of their repositories before using.

$ hg strip tip

For example, with revsets syntax, I indicate that I want to remove any commits of mine which result in extra heads being shown when I run hg heads. If you specify a particular revision in the below expression other than tip, everything in the current branch that is not an ancestor of your chosen revision will be trimmed. This seems closest to the behavior I want when I issue the command git reset --hard HEAD.

$ hg strip "branch(tip) and not(ancestors(tip)::tip)"

This is close:

hg update --clean


From git, commands:

git reset --hard     # reset to last commit    
git clean -df        # delete untracked files

are equal to

hg update --clean    # reset to last commit  
hg purge             # delete untracked files

If you've not yet commited, and it sounds like you haven't you can undo all the merge work with hg update --clean.

However, in newer mercurial's there's a handy command to re-merge a single file: hg resolve path/to/file.ext. From the hg help resolve:

The available actions are: ...

 4) discard your current attempt(s) at resolving conflicts and

restart the merge from scratch: "hg resolve file..." (or "-a" for all unresolved files)