Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial revert/backout a single file

Tags:

mercurial

In Mercurial I have an old changeset which is all good apart from the alterations to a single file. How would I revert the alterations to that single file?

Even just being able to view the state of the file at the previous changeset would be good then I could cut & paste.

My Mercurial client is TortoiseHg.

like image 325
Giles Roberts Avatar asked Nov 03 '10 06:11

Giles Roberts


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.

What does hg revert do?

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.


2 Answers

As of TortoiseHg 2.8.1

  1. Commit in case something goes wrong
  2. Right click the revision you want to roll back to, select Browse At Revision
  3. Find the file you want to revert to this revision, right click, 'Revert to this revision (Ctrl+Shift+R)
  4. Repeat 3 for all files you want to revert
like image 110
Zero Avatar answered Oct 05 '22 22:10

Zero


Raghuram's answer is no longer correct due to stylistic(~) changes to TortoiseHG. "Repository Browser" has been renamed "TortoiseHG Workbench", but, more importantly, "Revert file contents" is no longer an action on the context menu.

As of version 2.0.4, you'll want to:

  1. Commit your current repository in case something goes wrong.
  2. Open the relevant changeset in "TortoiseHG Explorer"
  3. In the file listing, right-click on the file you which to revert.
  4. Select "Revert to Revision" from the context menu.
  5. You'll be presented with a confirmation dialog that contains a checkbox labeled "Revert all files to this revision". Make sure that it's unchecked.
  6. Hit "OK".
  7. Verify that only that file was reverted. If everything was reverted, update to the revision created in step 1.

The first time I tried this, I'm not sure what I did wrong, but I reverted the whole repository instead of the single file. So, definitely make sure you commit a new revision before trying it.

like image 40
geppy Avatar answered Oct 05 '22 21:10

geppy