At some point in time you have a mercurial named branch, let's call it, default, and you create a named branch from default, let's call it, foo, and you make some commits on foo. That work kind of looks like this:
hg update default hg branch foo hg commit -m "created branch foo" # work, work hg commit # work work hg commit
Meanwhile others are making commits on default. Now someone else is told to do some work on foo and they want to see if and what might need to be merged from foo's parent branch. If they knew that foo came from default they could just run:
hg merge --preview default
but they don't know where foo came from. They could run:
hg glog
or fire up tortoisehg and trace the line back to foo's parent, but is there a command they could run that would just tell them the parent branch of foo?
Branches occur if lines of development diverge. The term "branch" may thus refer to a "diverged line of development". For Mercurial, a "line of development" is a linear sequence of consecutive changesets. Combining a line of development into an existing one is called merging. Creating a branch.
Mercurial's main branch is called "default" and is analogous to "trunk" in SVN, "HEAD" in CVS, and "master" in Git. If you try to use some other name for your "main" branch, users will get a more or less random branch when they clone and commit things in the wrong place, which is generally undesirable.
From the main menu, select Hg | Mercurial | Update to. In the Switch Working Directory dialog that opens, specify the target working directory: To switch to another line of development, choose Branch and select the desired branch from the list.
Thanks for the revset examples. I fiddled around and found this solution that I kind of like:
hg log -r "parents(min(branch(foo)))"
which will print the revision that the first commit on the foo branch was based on. You can look for the branch (or lack thereof indicating the default branch) in that changeset and that is the parent branch of foo (at least the way parent branch is defined in the question).
But I have this nagging feeling...parents() could return more than one changeset. Could the first commit on a branch ever have two parents? I can't think of how that could happen.
You could use revsets to find this information, provided you're using Mercurial v1.6.0 or later. For example:
hg update BRANCH hg log -r "max(ancestors(BRANCH) and not branch(BRANCH))"
this will print out a single revision, the "branch point" of your feature branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With