I heard that the only way to create a branch in a Mercurial repository is to make changes in the working copy, then commit them to a new branch.
In Subversion, I can create a branch without having to make changes (by copying trunk
to a path under tags
) - is it possible to do this in Mercurial as well?
I've currently only seen TortoiseHg, so it's possible this can only be done via the command-line tool and I don't know it.
My workflow for this is:
Many thanks in advance.
Creating a branch Branching can happen by committing a changeset within a single repository or by committing diverging changes in distinct (but related) repositories. Two repositories are said to be related if they were once cloned from the same repository but later may have diverged.
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.
If you want to remove a tag that you no longer want, use hg tag --remove . You can also modify a tag at any time, so that it identifies a different revision, by simply issuing a new hg tag command. You'll have to use the -f option to tell Mercurial that you really want to update the tag.
It depends on what you mean by branch.
A named branch can be created by giving it a name and then committing, it'll end up as a new changeset in the history, but you don't need to explicitly change any of the files in the working folder to be allowed to commit.
hg branch NEWNAME hg commit -m "Created branch NEWNAME"
You can also do this using the TortoiseHg dialog.
However, if you want to create another unnamed branch, ie. just another head, then yes, you need to change something. And really, why would you want to just create an empty changeset with no changes? Just to signal that "this is where I'll place my branch when I have some changes"?
You might want to check out the bookmarks extension (which is soon to be part of core Mercurial).
If you're familiar with how branches work in git, then it's almost the same.
And just like branches in git, you may create a bookmark without committing anything.
$ hg bookmark my-feature
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