Over a million developers have joined DZone.
Platinum Partner

Mercurial Will Beam You Into A Heaven of Merging

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

I never understood why mercurial should be so fantastic and why merging is so much easier with hg compared to subversion. This week changed my point of view.

In subversion I couldn’t keep in mind the command to copy a revision difference e.g. into the current trunk. I nearly always was forced to do a manual and error-prone merging. Now that I am using hg for some of my free time projects and even partially at work I get very comfortable with hg. Especially the fast and network independent commits are awesome when working with hg.

Then, this week, I read an article about merging and I started to understand how merging works (much easier) with hg.

Lets get started. Assume your users or your QA found an issue in your current release. In hg it is easy to fix such an issue.

  1. go back to the state where you want to fix that issue or stay at the tip:
    hg update -C <oldRevisionNumber>

    or a go there via a named branch:

    hg update -C releaseXY
  2. now create a named branch for the issue:
    hg branch issueXY

    optionally do:

    hg commit -m "start working on issueXY"
  3. NOW FIX THE ISSUE in the code and commit:
    hg commit -m "fixed issueXY"

    optionally add

  4. Go back where you want to have the fixed code. Most of the time this will be ‘default’ (svn users known as ‘trunk’) but it also could be the releaseXY branch:
    hg update default
  5. Now do the actually merging
    hg merge issueXY

    In my case I had to merge manually 4 files, but for that kdiff3 poped up (you can change this application of course). So merging was really easy and done after 2 minutes! The fix where I changed over 25 files was easily applied.

  6. … and commit the merge:
    hg commit -m "merged fix of issueXY into development sources"

This is very straightforward and worked very well in practice! I would have never thought that merging could be that easy … until I did it myself. So, try it out! Only 6 steps into the heaven of mergurial!


  • You can always go back to the issue via:
    hg update -C issueXY
  • Before commiting things check that you are on the correct branch:
    hg branch
  • Get all branches:
    hg branches
  • View 5 commits of the logs if glog does not work for you:
    hg log -l 5
  • The steps 4 until 6 could be applied to several branches, of course
From http://karussell.wordpress.com/2010/06/17/mercurial-will-beam-you-in-the-heaven-of-merging/

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}