Mercurial Will Beam You Into A Heaven of Merging
Join the DZone community and get the full member experience.Join For Free
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.
- 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
- now create a named branch for the issue:
hg branch issueXY
hg commit -m "start working on issueXY"
- NOW FIX THE ISSUE in the code and commit:
hg commit -m "fixed issueXY"
- 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
- 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.
- … 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:
- Get all 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
Opinions expressed by DZone contributors are their own.