Undoing a commit in my personal repository

Greg Ward greg-hg at gerg.ca
Thu Apr 22 14:10:52 CDT 2010


On Thu, Apr 22, 2010 at 11:13 AM, Aardwolf <toiletpot at gmail.com> wrote:
>
> Suppose I have this situation:
>
> *) I did a commit in my repository
> *) I did pull and update
> *) There are also still a few uncommitted files in my working directory
>
> Now I want the following:
>
> *) Still have the uncommitted files in my working directory
> *) Also undo the commit in my repository: have those changes also be moved
> back again to my working directory and the commit be undone

Should be doable.

> hg rollback doesn't work, that seems to roll back the pull instead of the
> commit, and can't be done twice in a row.

Correct.  The help says as much.

> I've read somewhere that there exist things to change history. Changing
> history in my personal repository shouldn't affect anyone.

Also correct.

Here's what I would do.

1) *make a backup* of the entire repo + working directory -- I might
have the wrong procedure or you might make a mistake
2) enable the "mq" extension (this is where the "strip" command comes from)
3) hg help strip to understand what we're going to do in a moment
4) hg update REV where REV is the changeset you want to undo
5) save your uncommitted changes, just in case: hg diff > patch2
6) save the committed change that we're about to destroy: hg diff -c
REV > patch1
7) destroy history: hg strip REV
8) apply the destroyed change: hg patch --no-commit --force patch1

(The changes in patch2 should still be in your working dir.)  (Step 8
is equivalent to "patch -p1 < patch1", but should work on Windows as
well as Unix.)

Completely untested.  YMMV.

Greg


More information about the Mercurial mailing list