views:

42

answers:

3

I just switched over from SVN where after a few changes to the trunk I would merge a range of revisions (from my last merge from the trunk to the branhc - HEAD) into a branch. I want to do the same with Mercurial using TortoiseHG but I can't figure out how. I just committed two changesets to the trunk, now I need the branch to integrate those changes. Thanks in advance!

+1  A: 

In hg (or any DVCS) you can merge any changeset with any other changeset (except ancestors). If you open repository log from TortoiseHG (View Changelog from Explorer context menu or hgtk log from command line), you can update to any changeset, then select "merge with".

In your specific case you would update to your branch head, then merge with trunk head.

Geoffrey Zheng
My case was not quite as straightforward as this due to the SVN conversion, but going forward this is the exact approach I will be taking.
Chris
@Chris: would you care to share the details of your setup? What kind of branching structure do you have?
Geoffrey Zheng
I was trying to merge my trunk into my branch but since my repository was created from an SVN repo using HG CONVERT, HG didn't know that I had incorporated changes from the trunk along the way. I performed the merge from the trunk to the branch choosing to keep all my changes from the branch. I committed. This made HG recognize that my trunk had been merged to the branch. Then I performed the new changes on the trunk, committed, and now when I merged HG knew that those new changes were the only ones that needed to be merged. Now HG knows exactly what's what in my repository.
Chris
+2  A: 

This is what I typically do:

hg up trunk #assuming trunk is your main branch
hg merge -r myawesomebranch
#party
Paul Nathan
A: 

I've written a guide about working with branches in Mercurial. It boils down to this:

$ hg update mybranch # unless you are already at the tip of the branch
$ hg merge default   # merge in latest changes from "trunk"
$ hg commit -m 'Merge with default'

When mybranch is done, you close it and merge it into default:

$ hg commit --close-branch -m 'Ready for merge'
$ hg update default
$ hg merge mybranch
$ hg commit -m 'Integrated mybranch'

The cool thing about Mercurial is that you use the same commands no matter which direction you are merging. Subversion's merge tracking system requires you to add special command line flags when you merge in one direction, but not in the other (I cannot remember which direction is which without looking it up in the manual).

Martin Geisler