Mercurial revert/backout a single file
Solution 1
As of TortoiseHg 2.8.1
- Commit in case something goes wrong
- Right click the revision you want to roll back to, select Browse At Revision
- Find the file you want to revert to this revision, right click, 'Revert to this revision (Ctrl+Shift+R)
- Repeat 3 for all files you want to revert
Solution 2
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:
- Commit your current repository in case something goes wrong.
- Open the relevant changeset in "TortoiseHG Explorer"
- In the file listing, right-click on the file you which to revert.
- Select "Revert to Revision" from the context menu.
- 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.
- Hit "OK".
- 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.
Solution 3
Open Repository Browser
, go to the interested changeset. You will see a list of changed files. Choose the file you are intersted and Click on Revert file contents
Solution 4
CLI-version, applicable to any (fresh) version of TortoiseHG
In order to undo changes only in FILE, introduced in changeset CSET, use this form of backout
hg backout -r CSET --include FILE
Solution 5
I've discovered the answer to the second part at least. To view the contents of a single file at an old revision do the following in TortoiseHg:
- Right click on the file and select repository explorer.
- Click on the revision you'd like to revert back to.
- Right click on the file in the bottom left pane. Select either view at revision or save at revison.
![Giles Roberts](https://i.stack.imgur.com/CnRHr.jpg?s=256&g=1)
Giles Roberts
My areas of expertise are C#, JavaScript, jQuery, SQL Server and the ASP .NET MVC framework. I also have a broad range of experience and have worked with Angular, AWS, Azure, Delphi, PHP, Ruby, MySQL, Firebird, Python and Lisp.
Updated on June 05, 2022Comments
-
Giles Roberts about 2 years
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.