Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

undo

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?

like image 850
richzilla Avatar asked Apr 24 '12 20:04

richzilla


People also ask

How do I revert a file in Mercurial?

To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.

How do I revert last commit in Mercurial?

If you want to revert just the latest commit use: hg strip --keep -r . Using strip will revert the state of your files to the specified commit but you will have them as pending changes, so you can apply them together with your file to a new commit.

What is hg revert?

hg revert changes the file content only and leaves the working copy parent revision alone. You typically use hg revert when you decide that you don't want to keep the uncommited changes you've made to a file in your working copy.

How do you revert the last push in Heartgold?

hg rollback reverts the last transaction, so you'd be left with unfinished merge, which you have to use hg update -C to get out. If you don't want *b (you have it in another clone), then enable the built-in MQ extension and run hg strip -r <*b> . It will get rid of *b and *merge.


2 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.

like image 84
Sam Avatar answered Oct 09 '22 20:10

Sam


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

like image 23
Nicholas Tuck Avatar answered Oct 09 '22 19:10

Nicholas Tuck