What exactly *is* a branch?

Martin Geisler mg at lazybytes.net
Wed Jun 23 21:00:04 UTC 2010


Daniel Carrera <dcarrera at gmail.com> writes:

> I have a new question:
>
> On Wed, Jun 23, 2010 at 7:45 PM, Steve Losh <steve at stevelosh.com> wrote:
>>    Branch, named
>>        A collection of changesets which have the same branch name. ...
>
> What happens if two people both make a named branch and choose the
> same name?

If that happens, then that is a sign that people should talk more with
one another. It's just like if both Joe and Mike decide to fix Issue 42
without telling each other -- such duplication of effort is solved by
communicating somehow.

This is also why named branches are not meant for short-lived
experiments: you don't want branches called 'test', 'my-test' and so on.
Name them after some system such as issue numbers, stable/default,
version numbers, etc.

> Let's say we are at revision "A". Joe and Mike both have a clone. Then
> Joe runs "hg branch foo", makes a change and commits revision "B",
> while at the same time Mike runs "hg branch foo", makes a different
> change, and commits revision "C":
>
> A -> [ B (branch: foo) ]
> A -> [ C (branch: foo) ]
>
> Does Mercurial consider both of these to be different heads of the
> same branch? You realize that you could have a dozen completely
> unrelated changes, branching off in all directions, and they could all
> be called "branch foo".

Yes -- the named branch "foo" is simply the collection of all changesets
with branch = "foo" in their metadata. This set need not be connected,
it can have several heads, etc.

By the way, when you do 'hg heads' in Mercurial 1.5+, you are given the
branch heads, that is, changesets on the current branch (the current
branch is the branch of '.', the working directory parent revision) with
no children on this branch.

Use 'hg heads -t' for the older topological notion of heads which did
not take branches into account.


Speaking of branches, you should also know the term "closed branch" and
"closed (branch) head":

    Head, closed branch
        A changeset that marks a head as no longer interesting. The
        closed head is no longer listed by "hg heads". A branch is
        considered closed when all its heads are closed and consequently
        is not listed by "hg branches".

-- 
Martin Geisler

Mercurial links: http://mercurial.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20100623/4b8aa10d/attachment.asc>


More information about the Mercurial mailing list