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

27,573

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
27,573
richzilla
Author by

richzilla

Updated on April 27, 2020

Comments

  • richzilla
    richzilla about 4 years

    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?

  • Martin Geisler
    Martin Geisler about 12 years
    Nope, that's Git that has this weird behavior for git checkout (in Mercurial, hg checkout is an alias for hg update).
  • Martin Geisler
    Martin Geisler about 12 years
    I find it better to add *.orig to my .hgignore file and then just leave the .orig files around. Maybe I'll need them one day :) If they bother you, then you can use the purge extension to clean them up.