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

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?

Answers


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.


hg revert fileName will revert that file back to the revision you are at. If you want to revert all changes you can run hg revert --all.

Both of these will produce fileName.orig files so you can keep the changes you are wanting to revert just in case. If you want to revert the file and not have all the .orig files you can add the -C option: hg revert fileName -C hg revert --all -C


I believe you can type hg revert /path/to/file/<file name> and it will just update that file.


Need Your Help

Run a program at start-up on python in windows

python windows python-2.7 executable

I am developing a key-logger on python (only for curiosity sake) .