Sunday, April 17, 2011

Branch from the past in mercurial

I'm a single developer using Mercurial to create a program. I have so far committed at every step of developing, and I have messed things up and want to work on something else.

How shall I go to a previous state (ie. rollback) and then create a branch, maintaining the newer states?

Does rollback ever delete anything? Should that be all I do? Just rollback untill I'm at the place where I want, edit, then commit? Will I be able to merge the changesets later, or at least look at them? Of course I can just save this repository, rollback, and then create new changesets, then merge the two repositories?

I'm new to SCM and of course DSCM, so be gentle :)

From stackoverflow
  • You don't want to use hg rollback, that only erases exactly one change (the most recent). See You Can Only Roll Back Once in the hg book.

    To make a branch from an earlier revision, you need to find the revision number you want to branch from and run:

    hg clone -r <revnum> <source repository> <destination repository>

    You can then do your changes in the newly-cloned repository (which will not contain any of the history that came after the revision number you specified) and then merge those changes back into the original later, if you wish.


Post a Comment