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

richzilla picture richzilla · Apr 24, 2012 · Viewed 26.3k times · Source

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?

Answer

Sam picture Sam · Apr 24, 2012

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.