Mike Woelmer

Experimenting with F#, silverlight, and distributed version control

How to setup external diff and merge tools for Bazaar

Bazaar is a great distributed version control system, but when it comes to diff and merging, command-line tools fall flat.  Thankfully there are plugins and external tools available to make it easier.  Here is a step by step guide to get them installed on your machine. 

kdiff

When Bazaar encounters a conflict, it does a three-way merge (the common parent, your changes, and the other persons changes).  This makes merging easier because you can see what the file looked like before the conflict occurred.  The diff/merge tool that I use is KDiff3.  It can do three-way merges and two-way diffs. 

  1. Install KDiff3 to a location that does not have a space in the path.
  2. Add the KDiff3 install directory to your PATH environment variable (this is needed for the extmerge plugin that we will be installing later)
  3. You may have to reboot your computer for the PATH to take effect.
  4. If you don't already have one, create a file called bazaar.conf in the %APPDATA%\Bazaar\2.0 directory.  On my Vista OS this expands to c:\users\yourusername\AppData\Roaming\Bazaar\2.0.  Now add the following alias to the file using your install directory for kdiff3:
  5. [ALIASES]
        kdiff = diff --using c:/tools/kdiff3/kdiff3.exe

    Note: We have to tell bazaar that we are using an external tool when we perform a diff.  This creates an alias so that you do not have to type the following “bzr diff –-using kdiff3.exe somefilename” every time you want to see a diff.  All you have to type now is “bzr kdiff somefilename”.  You can change the name of the alias (kdiff) to be whatever you want (except for the word diff of course).

  6. Open a command prompt and navigate to your Bazaar plugin folder.  On my machine it is in the following location C:\Program Files\Bazaar\plugins.  Now type the following command:

bzr branch lp:bzr-extmerge extmerge

Note: This installs a plugin called External Merge.  It allows external tools to be used for merging.  KDiff3 is one of the tools it supports.

How to use it.

To see changes you have made to a file.  See bzr –help diff for more options for prior revisions and such.

            bzr kdiff somefilename.cs

If bazaar tells you that you have a conflict after merging, type these commands.  Note: emerge and the extmerge command can be used interchangeably.  You can also create an alias if you don’t like the name.

            bzr emerge –all  (finds all conflicts and displays them one by one)

            or

            bzr emerge somefilename.cs

When you are finished merging, run the following.

            bzr resolve –all   (resolves all conflicts in the tree)

            or

            bzr resolve somefilename.cs

When you are all finished, KDiff3 will leave a file called somefilename.orig which is your original file before merging.  To prevent accidentally adding this file to your repository, you can add the *.orig extention to your global ignore file.

Comments

nickj said:

spot on - worked first time :-)

# March 4, 2009 10:10 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)