richzilla
richzilla

Reputation: 42012

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?

Upvotes: 33

Views: 30895

Answers (3)

Kodi
Kodi

Reputation: 787

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

Upvotes: 5

Nicholas Tuck
Nicholas Tuck

Reputation: 551

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

Upvotes: 15

Sam
Sam

Reputation: 424

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.

Upvotes: 40

Related Questions