A Guide to Branching in Mercurial

Martin Geisler mg at lazybytes.net
Sat Sep 5 07:55:07 CDT 2009


"Alexander Schatten" <ml_alexanderschatten at gmx.at> writes:

Hi Alexander

> thanks for your detailed answer; this was also my understanding. I
> just think, that this is a significant issue of this blog-post.
>
>
> May I add one question here, though, that I was already struggling
> with and that is in my opinion related. Assume this situation:
>
>
> (1) I have a piece of Code version controlled and I am, say, at Rev.
> 10. Everything is fine so far.
>
> (2) Now I continue a "risky" feature development, say until Rev. 15.
> Then I figure this leads nowhere, I have broken the system, whatever.
>
> (3) Hence I go back to rev. 10 (hg update 10). This was the last
> stable version. Then I continue working from here (Rev. 16, 17, ...).
> In effect I made a branche. This is why I have SCM, right?
>
> Now: the thing is: this unnamed branch Rev. 11-15 will allways annoy
> me in the future, because I cannot push and I definitly do not want to
> merge crappy code into my main line of dev.
>
> What should be done in such a situation? Name the crappy branch? But
> then I have 100 names for each crappy side-stream that distract me? Is
> it possiblelto "end" such an unnamed branch, like "set it deprecated"
> so that it is not named, but not interfering any longer?

It depends on which kind of person you are:

* Some people don't want to throw away anything and want to keep the
  dead-end code as an example of what not to do.

  If that's you, then you want to merge the bad code into the good code,
  but do so in a way that keep the good code around:

    hg merge --config ui.merge=internal:local good bad
    hg revert --all good
    hg commit -m 'Dummy merge with bad.'

  That way you tell Mercurial and the rest of the world how you want
  revisions 'good' and 'bad' to be merged -- you want them to be merged
  without a trace of 'bad'.

* On the other hand, if you like your history to look all shiny and
  without dead-ends, then use 'hg clone -r good' to extract the good
  part from your clone (or strip from the mq extension).

  Or put your code in different clones from the beginning and delete the
  clone if you become unhappy with it. This is an especially good idea
  if you intend to publish your risky features somewhere like Bitbucket.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial/attachments/20090905/34c97ecc/attachment.pgp 


More information about the Mercurial mailing list