1

Backout works by applying a changeset that's the opposite of the changeset to be backed out. That new changeset is committed to the repository, and eventually merged.

https://www.mercurial-scm.org/wiki/Backout

How can I backout without commiting the changeset? I just want the changeset reverted in a working directory.

jestro
  • 2,524
  • 4
  • 27
  • 46
  • Possible duplicate of [Using hg revert in Mercurial](https://stackoverflow.com/questions/2239331/using-hg-revert-in-mercurial) – torek Feb 13 '19 at 19:51
  • Did you already commit changes, or do you just have modified files in your working directory which are not yet committed? – StayOnTarget Feb 14 '19 at 12:32

2 Answers2

2

Try hg backout --no-commit REV

This will perform the backout but leave the changes uncommited.

Craig
  • 756
  • 3
  • 8
1

Assuming you have already committed a new changeset but not yet pushed it; let's say your history looks like this:

A--B--C--★

where C is the recently committed changeset you wish to do away with, but leave its modifications in the working folder. And ★ is the working directory (not an actual changeset itself).

There is more than one way to do this. One approach is the following...

hg up B

This leaves your history looking like this:

A--B--★
    \
     C

Then do

hg revert -r C

which in effect copies whatever changes were in C into your working folder.

Then you could do (optional)

hg strip C

which eradicates C from history:

A--B--★

An advantage of this approach is that it removes C entirely, like it never existed.

(I mentioned that using strip is optional in this sense: if you did leave C in place, it causes little harm. And you'd never need to push it if it is marked secret. But personally I would clean it up by stripping.)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81