0

I have a file in which several separate blocks have changed in one changeset. (This is not the most recent changeset.)

Now I need to revert just one of these blocks to the status of the revision right before those changes. What is the recommended procedure for this? Does Mercurial/TortoiseHg offer any help, or should I just manually replace this block with the old contents?

Felix Dombek
  • 13,664
  • 17
  • 79
  • 131

1 Answers1

1

If you would want a complete changeset being undone, it could be done without manual work by using hg backout. From its help:

hg backout [OPTION]... [-r] REV

reverse effect of earlier changeset

Prepare a new changeset with the effect of REV undone in the current working directory. If no conflicts were encountered, it will be committed immediately.

If REV is the parent of the working directory, then this new changeset is committed automatically (unless --no-commit is specified).

Note: 'hg backout' cannot be used to fix either an unwanted or incorrect merge.

However as you only want a single hunk reverted, you can use hg backout and then you need to use the --interactive flag for the commit so that you can pick the right hunk(s) to be committed:

hg commit --message "Revert some stuff" --interactive

Last, revert the working dir to a now unmodified state - you don't want to change back the remaining hunks

planetmaker
  • 5,884
  • 3
  • 28
  • 37