What is Bazaar and how do I use it?

Bazaar is a revision management system - allowing a number of people to make changes to the same source material. This system also allow us to revert to an earlier version or indeed undo all the changes we have made. It is also very well integrated with Launchpad.

There are graphical tools available but this tutorial concentrates on using Bazaar from the command line, so you’ll need to open a terminal (Applications→Accessories→Terminal).

Installing

OK, lets install Bazaar and another program we need called ssh, type:

sudo apt-get install bzr ssh

Identifying yourself

Bazaar needs to know a little about you, allowing changes you make to be integrated with Launchpad. There are two things we need here - your Launchpad username and your ssh key. A ssh key is a method of encrypion and you generate the key by typing:

ssh-keygen -t rsa

Then goto https://launchpad.net/~USERNAME/+editsshkeys and follow he instructions. Lastly, so that Launchpad links your changes with your user name, we need to edit a file, type

gedit ~/.ssh/config

Add the following:

Host *launchpad.net
User USERNAME

Now we’ll let Bazaar know - type:

bzr whoami 'NAME <EMAIL>'
bzr launchpad-login USERNAME

Checking out

You need a copy of the material you want to work on, this is referred to as “checking out”, type:

bzr branch http://ADDRESS

Bazaar will download the branch into the current directory. Most launchpad code pages list command and address. Bazaar also creates a directory to store it in.

Updating checked out files

Now you can go about making changes to your local copy. In order to ensure you have the most up to date copy, you need to “update check-out”:

bzr update

This will tell you if any changes are available and if you want to merge them into your work - type:

bzr merge

Add new files

At this point, once you’ve made some changes - you might have added some new files. In order to add these to the project you need to tell Bazaar - type:

bzr add FILENAME

Undo changes

You may have made mistakes, these can be reverted by typing:

bzr revert

Producing patches

Team members can commit their changes but what if you are just fixing something you’ve noticed in a team you aren’t part of? Then you can create a patch and send it to the relevant team.

bzr diff FILENAME FILENAME.PATCH

Committing changes

When you’re happy with your changes, you can “commit” your changes. This means that any alterations you make from this point on can be reverted to this point.

bzr commit

Pushing changes

At this point, you’re pretty much done - unless you are a team member. These changes are only on your computer - to share them you need to “push” your changes:

bzr push bzr+ssh://username@bazaar.launchpad.net/ADDRESS

Binding a branch to commit

This is a little cumbersome and its easier to have Bazaar push changes when you commit and this can be done with:

bzr bind bzr+ssh://USERNAME@bazaar.launchpad.net/ADDRESS

Apply a received patch

This only leaves us with two other things we might want to do, first commit a patch that we have received from someone else. First change to the directory that contains the file to be patched and type:

patch -p0 < PATCHNAME

Reverting to an earlier state

Lastly and most importantly we might want to revert to an earlier state. This is done using the bzr revert command and adding a revision number, for example to revert to revision five type:

bzr revert -r 5
coding/bzr.txt · Last modified: 2010/12/19 11:53 (external edit)
Kleine Websites, die ein Wiki als CMS verwenden.de