Mercurial: Merge(TortoiseHG)

  1. Update to the branch you want to merge into.
  2. Right-click on the changeset you want to merge into the current branch. It doesn’t have to be a tip changeset, and it can be useful to do multiple merges if you know there’s a nasty merge in one of them.
  3. The dialog isn’t phrased very well, as it calls the top the Merge target(other) when we would be more inclined to think of it as the merge source, and the current working directory as the target. Don’t worry, it will do what we want it to do.
  4. Click Merge.
  5. If there are any conflicts Mercurial can’t resolve, you should see an open source 3-way merge tool appear. It’s called KDiff, and was installed by TortoiseHG.
    • If you’ve worked with a merge tool before, then you should be able to figure it out. Basically, base (the left-most panel) is the common parent. The middle panel (local) is your current working directory), and other (the right-most pane) is the changes from the branch being merged in.
    • Mercurial will show both conflicts it has resolved, as well as those it can’t determine. There are arrows in the toolbar to navigate through the conflicts. You have to resolve the red ones (i.e. those that it can’t resolve.).
    • The bottom-pane shows what the file will look like once you exit the merge tool. You can edit the source by hand, as well as have it incorporate the lines from more than one version.
  6. Once all conflicts are resolved, Tortoise will show a dialog with a few choices.
    • Undo does as it implies. It reverts any changes to your repository to the state it was in before the merge.
    • Close keeps the merge in the state it’s currently in, and leaves the changes in your working directory. This gives you an opportunity to confirm the code, ensure everything compiles, and that all tests run before committing your changes.
    • Commit also does as it implies. It commits your merge right away, and will prompt you for a commit message.

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply