How to do "replace with the latest from head" for a file with Mercurial?

git, mercurial, replace, version-control

Solution

For Mercurial, use `hg revert`. See `hg help revert`.

Edit

To clarify, `hg revert` changes files to a previous revision. `hg update` changes the parent changeset to a different revision. In both cases, uncommitted changes are preserved unless `-C` is used.

Problem

In CVS, sometimes I do "replace with the latest from head" to abandon local changes to a file as the local changes might be messed up and one would like to start afresh with that file, while keeping any uncommitted local changes made to other files. How to do the equivalent in Mercurial and Git?

Original source

Related problems