When working with multiple branches, it is important to be able to compare them. You can see the differences between branches with different levels of detail. You can get a quick summary of the missing revisions between two branches, or view the differences between any two revisions in the same way as you compare revisions within the same branch.
The command line is more powerful, and it gives you full control over the input parameters and the level of detail in the output. On the other hand, Bazaar Explorer is somewhat limited in terms of input options, but it has a much easier to use interface.
When using the commands that compare branches, the basis of the comparison is the current branch by default, and the other branch to be compared must be specified as a parameter. The ordering of branches in the comparison is relevant, as comparisons depend on the perspective.
"Missing revisions" are revisions that exist in one branch but not in the other. You can view the list of missing revisions by using the bzr missing
command. For example:
$ cd /sandbox/hello/fix-c/ $ bzr missing ../say-hello-to-x/ --line You have 2 extra revisions: 8: Janos Gyerik 2013-03-03 use more modern include-style 7: Janos Gyerik 2013-03-03 c impl should add newline You are missing 2 revisions: 8: Janos Gyerik 2013-03-03 python impl can say hello to X 7: Janos Gyerik 2013-03-03 bash impl can say hello to X
The command shows the missing revisions relative to the current branch. In this example, we are in the fix-c
branch directory and compare it to the say-hello-to-x
branch. Thus we have two extra revisions and two missing revisions.
The missing revisions are shown using the same format as the log
command. For brevity, we used the --line
flag in this example, but all the other log format options work too.
To see the extra or missing revisions in only one of the branches, use the --mine-only
or --theirs-only
flags. For example:
$ bzr missing ../say-hello-to-x/ --line --mine-only You have 2 extra revisions: 8: Janos Gyerik 2013-03-03 use more modern include-style 7: Janos Gyerik 2013-03-03 c impl should add newline $ bzr missing ../say-hello-to-x/ --line –theirs-only You are missing 2 revisions: 8: Janos Gyerik 2013-03-03 python impl can say hello to X 7: Janos Gyerik 2013-03-03 bash impl can say hello to X
Instead of --mine-only
, you can use the shorter aliases, namely --mine
or --this
. Instead of --theirs-only
, you can use the shorter aliases, namely --theirs
or --other
.
You can view the differences between two branches by using the bzr diff
command in the same way as you compared the revisions within the same branch. However, you must specify the other branch by using either the --new
or --old
flags, depending upon which branch should be the basis for comparison.
Without the additional parameters, the command shows the differences in the entire project. To view the differences only to a set of files, specify the files or subdirectories as parameters. For example, to see the changes going from the fix-c
branch to the say-hello-to-x
branch affecting only the README
file, as follows:
$ bzr diff --new ../say-hello-to-x/ README.md === modified file 'README.md' --- README.md 2013-03-03 14:19:48 +0000 +++ README.md 2013-03-07 20:53:05 +0000 @@ -9,3 +9,9 @@ - C - Java - Python + + +Variation: "say hello to X" +--------------------------- +- Bash +- Python
That is, the say-hello-to-x
branch added some lines in the file. Sometimes, it can be useful to view the differences in the other direction; that is, to see the changes going from the say-hello-to-x
branch to the fix-c
branch:
$ bzr diff --old ../say-hello-to-x/ README.md === modified file 'README.md' --- README.md 2013-03-03 14:57:13 +0000 +++ README.md 2013-03-07 20:55:52 +0000 @@ -9,9 +9,3 @@ - C - Java - Python - - -Variation: "say hello to X" ---------------------------- -- Bash -- Python
We simply replaced --new
with --old
to reverse the direction of the differences.
Remember that you can always replace the diff
command with cdiff
to highlight the differences using colors, or qdiff
to view the differences in Bazaar Explorer instead. For example:
The cdiff
command is provided by the
bzrtools
plugin, and it requires a terminal application that supports colors. The
qdiff
command is provided by the qbzr
plugin.
Note that the revision
parameter is always applied to the current branch. One way to compare against a specific revision in another branch is to do it in two steps—first, create a temporary branch based on the other branch at the desired revision, and then compare the current branch against the temporary branch.
A very useful interface in Bazaar Explorer for viewing and managing multiple branches is the Repository view. To open this view, use the Open... option in the File menu or the Ctrl + O keyboard shortcut in Windows and Linux or Cmd + O in Mac OS X, then navigate to the shared repository location, and click on Choose.
When the view opens, it simply shows a list of the branches in the shared repository. For example:
Let's explore the different functions that are accessible from this main view.
A very nice function in Bazaar Explorer is to show multiple branches at the same time in the Log view. You can select multiple branches in the list by pressing the Ctrl key and clicking in Windows and Linux, or pressing the Cmd key and clicking in Mac OS X. To view all the branches, simply select nothing (by clicking anywhere within the empty area) and click on the Log button:
In this example, all the branches are shown in the tree, with the branch tips highlighted with the location of the branch. This is a great way for viewing the revisions in the different branches at a glance.
The other functions of the Log view work as usual, such as filtering and viewing differences in each revision. However, this also means that you can only see the differences in a single revision, and at the time of this writing, there is no user interface for comparing two arbitrary revisions.
When you click on a branch in the Repository view, the details panel under the list of branches shows more details about the branch using three tabs:
For example, the say-hello-to-x
branch has two revisions that are not yet in the parent:
18.189.186.109