1
******************************
2
Learn Bazaar in twenty minutes
3
******************************
7
Martin Pool <mbp@sourcefrog.net>
9
:Date: November 2004, London
12
*Bazaar* is an open source distributed version control system. A
13
version control system helps you develop software (or other documents)
15
In Bazaar, branches hold a history of their changes. All working
16
copies are branches, and all branches are working copies.
18
Let's get a copy of someone else's published project::
20
$ baz branch http://baz.alice.org/hello-2.6
22
This creates a directory called ``hello-2.6`` in your current
23
directory, containing Alice's *Hello World* 2.6 tree and a history of
24
her changes. We'll leave this directory containing a pristine copy of
25
her work for future reference.
27
We want to add a new feature. Branching and merging is are cheap and
28
easy in Baz, so development of each new feature should be done on a
29
new branch -- this lets you merge them in different orders, and leave
30
aside new development to fix a bug if you want. It's good to choose a
31
meaningful name for your development branches so that you can keep
32
them straight. So let's make an additional branch, based off our
33
local copy of Alice's branch::
35
$ baz branch ./hello-2.6 ./hello-2.6-goodbye
37
This command completed quickly: we didn't need to fetch anything from
38
Alice's server to make a new branch.
40
Now we have a second directory containing another copy of the source,
41
with a different name. Of course both are still the same as Alice's
42
source. Time to hack::
44
$ cd hello-2.6-goodbye
47
We add a new and much-desired ``--goodbye`` option, build and test
48
it. Having got to a good state, we think we're ready to commit our
49
changes. Many people find it helpful to review the changes before
50
committing them, just to make sure there were no accidental mistakes::
54
This shows the changes relative to the version we started with. If
55
that looks OK, we're ready to commit::
57
$ baz commit -m 'Add --goodbye option'
59
This records the changes into this branch. We can see that they got
64
This will show our change as the most recent, preceded by all our
65
development. If we only want to see our own changes, we can filter
66
the log in various ways::
68
$ baz log --author bruce@
69
$ baz log --date today
71
(That second one might include anything Alice did before we started.)
73
Since our changes were committed, we don't have anything outstanding,
74
as we can see with this command::
79
Thinking about it a bit more, we decide that it's too messy to mix the
80
"Goodbye" implementation in with "Hello world". We start up our
81
editor and split it our into a new separate file, ``bye.c``. By
82
default, Baz assumes unknown files in the working directory are
83
scratch files -- the same behaviour as CVS and Subversion. We need to
84
tell Baz that this file should be versioned, and then we can commit::
87
$ baz commit -s 'Refactor bye() into separate file'
89
Of course this commits all our changes as a single atomic
90
transaction. If we wanted, we could tell Baz to build the program
91
before committing to help ensure we never get a broken build.
93
We're ready to publish our improved Hello World, but first we want to
94
make sure we've integrated anything Alice has done while we were
95
working. First we update our mirror of Alice's branch::
97
$ baz sync ../hello-2.6
99
This pulls the history of her branch onto our machine; we could
100
disconnect from the network at this point and do all the merging work
101
without needing to connect to ``alice.org``.
103
Now we'll pull Alice's new changes into our branch. We can use a
104
mirror of her branch, or we can go straight to her public branch. In
105
fact, we can merge from different copies of the same branch at
106
different times, and Baz will still understand which changesets have
107
already been merged. Either of these commands will work::
109
$ baz merge ../hello-2.6
110
$ baz merge http://baz.alice.org/hello-2.6
112
This pulls down any changesets on Alice's branch that aren't in ours,
113
and applies them to our tree. Since we've made changes in parallel
114
with Alice, those changes might conflict. Baz by default will insert
115
CVS-style conflict markers into your branch if that happens, but you
116
can also ask it to run a graphical merge tool or to tell emacs to do
117
the merge. Baz will help you merge changes other than file text, such
118
as a file being renamed in one branch.
120
By running ``baz diff`` we can see the effect of her changes on our
121
tree. By running ``baz log --pending`` we can see a description of
122
all of the changes that were pulled in. Once the changes have been
123
reconciled (which will often happen automatically), we can commit this
126
$ baz commit -s 'Merge from Alice'
128
Baz records that our change incorporates those patches from Alice::
132
Now that we have the feature we wanted, we can publish our branch on
133
the web. We could copy it up using ``baz branch``, but because Baz
134
branches are simply directories we can just rsync it onto a web
135
server, even if the web server doesn't have Baz installed::
137
$ rsync -av ./hello-2.6-goodbye webserver.com:public_html/
139
We send an email to Alice asking her to merge from this location.
140
Typically she'll want to have a look at those changes before accepting
141
them, and she can do that by running ``merge`` then ``diff``, as we
142
did before. If she likes the change, she can merge it, possibly
143
applying some fixes in the process. Next time we merge from her,
144
we'll see our changes are in.
150
.. compile-command: "rest2html short-demo.txt > short-demo.html"