How do I revert a file to 'last checkin' state in Mercurial?

mercurial, undo

Solution

There is a mercurial command to revert files. `hg revert` this should revert any changes. You can also pass a file name to it e.g `hg revert fileName`.

Problem

I have a hypothetical Mercurial repository on disc. I'm most of the way through creating a new feature, when I realise I've made a complete mess of the file I'm working on, and want to revert that file back to its last commit state. I can use `hg update` to refresh the working copy from the repository, but that updates every file. Is there a mercurial command that can update just a single file?

Original source