jestro
jestro

Reputation: 2593

How can I backout of a Mercurial changeset in a working directory and not commit it to the repo?

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.

Upvotes: 1

Views: 120

Answers (2)

StayOnTarget
StayOnTarget

Reputation: 13007

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.)

Upvotes: 1

Craig
Craig

Reputation: 776

Try hg backout --no-commit REV

This will perform the backout but leave the changes uncommited.

Upvotes: 2

Related Questions