Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: Revert a single hunk

How do I revert a single hunk in Mercurial, similar to the way it's done in darcs, i.e. it asks me for each hunk and file whether I want to revert it? Is it possible using TortoiseHg?

Thanks

like image 966
Deniz Dogan Avatar asked May 18 '09 08:05

Deniz Dogan


People also ask

How do you undo the last commit in Heartgold?

You can manually trigger a rollback with 'hg rollback'. This will undo the last transactional command. If a pull command brought 10 new changesets into the repository on different branches, then ' hg rollback ' will remove them all. Please note: there is no backup when you rollback a transaction!

How do I revert 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.

How to discard uncommitted changes in Mercurial?

The revert command allows discarding unwanted uncommitted changes. Reverting changes to a single file.


1 Answers

Actually mercurial refers to "chunks", at least in the Shelve tool. Which brings me to favorite way to revert them (and favorite features of TortoiseHg).

Just move the chunks you want to revert onto a shelf you create solely with the intention to delete. This works really well as long as the chunks are identified as you need them to be. If not, you've got no choice but to do something manually.

If you use TortoiseHg Workbench or VisualHg, it is very easy to get to the Shelve tool: there is a button next to the diff mode toggle buttons. If you are not familiar with shelves, do yourself a favor and start using it. It has saved me much aggravation when I've forgotton to commit early, or decided to leave out experimental code from a commit.

like image 111
Andre Luus Avatar answered Sep 18 '22 15:09

Andre Luus