Monday, March 28, 2011

Mercurial Mq: Modify a changeset

Mercurial is an awesome distributed version control system.  If you work on a project that cares about clean changesets, you may run into the need to modify a changeset after you have committed it.  This generally isn't allowed, and it's a potentially dangerous thing to do.

It's dangerous because changing history modifies the identity of the repository.  So if you pushed the changeset, then modified it, your repository will no longer be compatible with the remote one.  And that would be bad.

But if you haven't shared the changeset yet, you CAN modify it.  All you need is to enable the mq extension.  You can use this extension to turn an existing changeset into a patch, and then you can modify that patch.  When you're done, you can finish the patch, turning it back into a finalized changeset.  You can also edit more than one changeset this way by importing them, then popping them off the queue one at a time.

Here's an example:
hg qimport -r 123 -r 124
hg qpop

# make changes to files

hg qrefresh
hg qpush

# make changes to files

hg qrefresh
hg qfinish -a

If you want to update the changeset comment, you can do that by editing the respective .diff file in the .hg\patches directory.  For example, .\hg\patches\123.diff.  Just open that sucker up, modify the comments on top and save it when you're done.  Couldn't be simpler!

No comments:

Post a Comment