How to properly close a branch?

Michael Jay Lippert mlippert255 at gmail.com
Wed Nov 10 19:42:45 CST 2010


On Wed, Nov 10, 2010 at 10:06 AM, Didly Bom <didlybom at gmail.com> wrote:

>
> Thanks a lot for your answer Gilles. Your explanation was very good and in
> principle it answers my questions.
>
> It is actually quite confusing that the "--close-branch" flag of the commit
> command does not close a branch but a head! Quite frankly I think that the
> flag should actually be called "--close-head"!
>
> With your explanation I did some tests to make sure that I understood how
> this works. However I still seem to not understand it perfectly because I
> got an error when I tried to push after having closed one of the two heads
> on my test repository.
>
> Let me try to tell you all the steps I performed. Hopefully I have not
> missed any of the steps. Note that I used TortoiseHg 1.1.5 (with Mercurial
> 1.7) for this test:
>
> - I created a brand new repo with a single file.
> - I did an initial commit to create the first changeset of the repo
> (revision 0).
> - I then created a clone of this repo.
> - In the clone I modified the file and committed the change (which created
> rev #1).
> - I updated to revision #0.
> - I modified the file and commited the change, creating a new head at rev
> #3.
> - I tried to push to the source repo. As expected this failed with the
> usual error "abort: push creates new remote heads on branch 'default'!",
> since there were 2 heads.
> - I then closed the head in revision #3. To do so I used the TortoiseHg
> commit tool, selected the branch button and clicked on "Close current
> branch".
> - At this point there was a single "non closed" head in the repository. To
> check this, on the Repository History view of the clone repository I
> filtered by "heads" and I saw a single revison (#2).
> - I updated to the remaining head.
> - I tried to push. Again I got the error "abort: push creates new remote
> heads on branch 'default'!"
>
> I was not expecting this last error. Since there is only a single
> "non-closed" head I would expect mercurial to send all the changesets to the
> source repo.
>
> Is this normal? Am I doing something wrong?
> BTW, this is the output of "hg log" on the clone repository:
>
> >hg glog
> o  changeset:   4:d179bc264f60
> |  tag:         tip
> |  user:        Angel
> |  date:        Tue Nov 09 14:30:11 2010 +0100
> |  summary:     Close
> |
> o  changeset:   3:e002e4249dfa
> |  parent:      1:57b7eb86e96d
> |  user:        Angel
> |  date:        Tue Nov 09 14:29:41 2010 +0100
> |  summary:     4b
> |
> | @  changeset:   2:2ce74e5015d7
> |/   user:        Angel
> |    date:        Tue Nov 09 14:28:58 2010 +0100
> |    summary:     4
> |
> o  changeset:   1:57b7eb86e96d
> |  user:        Angel
> |  date:        Tue Nov 09 14:27:37 2010 +0100
> |  summary:     3
> |
> o  changeset:   0:edc291cb2a9d
>    user:        Angel
>    date:        Tue Nov 09 14:27:01 2010 +0100
>    summary:     1
>
> I really would like to know how to avoid these "abort: push creates new
> remote heads on branch 'default'!" because in our project we sometimes end
> up with some "dangling" heads that we'd like to "close".
>
> Cheers,
>
> Angel
>
>
Angel,
The scenario you describe above doesn't create any named branches, so there
is no need to close a branch.

You do create multiple heads on the default branch. In order to avoid the
error "abort: push creates new remote heads on branch 'default'!" you need
to merge the 2 heads together.

If revision 3 was given a new branch name and revision 4 closed that named
branch, you still have 2 heads and still need to merge the closed head into
the default head.

I have always done this w/ the TortoiseHg GUI so I'm not sure of the
appropriate hg commands. I find the visual graph connecting the changesets
that TortoiseHg shows to be very helpful in understanding what's going on.

Someone more experienced please jump in and correct me if I've just given
incorrect information.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial/attachments/20101110/0f18a0ea/attachment.htm>


More information about the Mercurial mailing list