~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
==================
Bazaar-NG Tutorial
==================

current for bzr 0.0.6pre, July 2005


*Note:* This tutorial is a work in 
progress, and describes code that is itself still evolving. 
If you have comments on either the design or the tutorial, 
please send them to the bazaar-ng@lists.canonical.com mailing list.



Introduction
============

Bazaar-NG is a version control tool.  It manages trees of files and subdirectories.  In particular, it records *revisions* of trees, representing their state at a particular point in time, and information about those revisions and their relationships.  Recording and retrieving tree revisions is useful in several ways if you are writing software or documents or doing similar creative work.

 * Keeping previous revisions lets you go back if you make a mistake or want to check your work.  It acts as a high-level unlimited undo.

 * By recording comments on every revision, you produce an annotated history of the project, describing what, who, why, and when.

 * Using a version control tool can be an aid to thinking about a project: getting to a stable state at regular intervals and then writing a description of what you did is an easy way to stay organized and on track.

Bazaar-NG remembers the *ancestry* of a revision: the previous revisions that it is based upon.  A single revision may have more than one direct descendant, each with different changes, representing a divergence in the evolution of the tree.  
By branching, Bazaar-NG allows multiple people to cooperate on the evolution of a project, without all needing to work in strict
lock-step.  Branching can be useful even for a single developer.

Bazaar-NG installs a single new command,
*bzr*.  Everything else is a subcommand of this.  You can get
some help with ``bzr help``.  There will be more in the future.



Introducing yourself to bzr
===========================

One function of a version control system is to keep track of who
changed what.  In a distributed system that requires an identifier for
each author that is globally unique.  Most people already have one of
these: an email address.

[after 0.0.4] To tell bzr which email address to use, put it in the file
``$HOME/.bzr.conf/email``, or the environment variable ``$BZREMAIL``.
If neither of these are set, bzr will use the ``$EMAIL``
variable, or use your username and hostname.

To check this has taken effect, or if you forget your own name, use
the ``whoami`` ("who am i?") command::

  % bzr whoami

Some people want to avoid sharing their email address so as not to
get spam.  bzr will never
disclose your email address unless you tell it to by publishing an
archive or transmiting a changeset.  It's recommended that you do use
a real address, so that people can contact you about your work, but
it's not required.  You can use an address which is obfuscated, which
bounces, or which goes through an anti-spam service such as spamgourmet.com.



Creating a branch
==================


History is by default stored in the .bzr directory of the branch.
There will be a facility to store it in a separate repository, which
may be remote.  We create a new branch by running *bzr init* in
an existing directory::

    % mkdir tutorial
    % cd tutorial
    % ls -a
    ls -a
    ./  ../
    % pwd
    /home/mbp/work/bzr.test/tutorial
    %
    % bzr init
    % ls -aF
    ./  ../  .bzr/
    %

As for CVS, there are three classes of file: unknown, ignored, and
versioned.  The *add* command makes a file versioned: that is,
changes to it will be recorded by the system::

    % echo 'hello world' > hello.txt
    % bzr status
    ?       hello.txt
    % bzr unknowns
    hello.txt
    % bzr add -v hello.txt
    A       hello.txt
    % bzr unknowns


If you add the wrong file, simply use ``bzr remove`` to make
it unversioned again.  This does not delete the working copy.


Reviewing changes
=================

Once you have completed some work, you will want to *commit*
it to the version history.  It is good to commit fairly often:
whenever you get a new feature working, fix a bug, or improve some
code or documentation.  It's also a good practice to make sure that
the code compiles and passes its test suite before committing, to make
sure that every revision is a known-good state.  You can also review
your changes, to make sure you're committing what you intend to, and
as a chance to rethink your work before you permanently record it. 

Two bzr commands are particularly useful here: *status* and
*diff*.  The *status* command
shows a listing with one line per file, indicating whether it has been
Added, Deleted, Modified, or Renamed in the current revision.  Unknown
files are shown as '?'.  With the ``--all`` option, the status
command also shows unmodified versioned files as '.', and ignored
files as 'I'::

    % bzr status
    A       hello.txt

The *diff* command shows the full text of changes to all
files as a standard unified diff.  This can be piped through many
programs such as ``patch``, ``diffstat``,
``filterdiff`` and ``colordiff``::

    % bzr diff
    *** added file 'hello.txt'
    --- /dev/null 
    +++ hello.txt 
    @@ -1,0 +1,1 @@
    +hello world

With the ``-r`` option, the tree is compared to an earlier
revision.

[TODO: options to run external diff; to get context diff or other
formats; to diff only selected files; to compare two historical
revisions.]



Committing changes
==================

When the working tree state is satisfactory, it can be
*committed* to the branch, creating a new revision holding a
snapshot of that state.  

The ``commit`` command takes a message describing the changes
in the revision.  It also records your userid, the current time and
timezone, and the inventory and contents of the tree.  The commit
message is specified by the ``-m`` or ``--message`` option.
You can enter a multi-line commit message; in most shells you can
enter this just by leaving the quotes open at the end of the line. ::

    % bzr commit -m "added my first file"

[TODO: commit message interactively, through an editor or from a
file.]

[TODO: commit only selected files, including renamed/added/deleted
files.]




Ignoring files
==============

Many source trees contain some files that do not need to be
versioned, such as editor backups, object or bytecode files, and built
programs.  You can simply not add them, but then they'll always crop
up as unknown files.  You can also tell bzr to ignore these files by
adding them to a file called ``.bzrignore`` at the top of the
tree.

This file contains a list of file wildcards (or "globs"), one
per line.  Typical contents are like this::

    *.o
    *~
    *.tmp
    *.py[co]

If a glob contains a slash, it is matched against the whole path
from the top of the tree; otherwise it is matched against only the
filename.  So the previous example ignores ``*.o`` in all
subdirectories, but this example ignores only config.h at the top
level and HTML files in ``doc/``::

    ./config.h
    doc/*.html

To get a list of which files are ignored and what pattern they matched, use ``bzr ignored``::

    % bzr ignored
    config.h                                           ./config.h
    configure.in~                                      *~

It is OK to have an ignore pattern match a versioned file, or to
add an ignored file.  Ignore patterns have no effect on versioned
files; they only determine whether unversioned files are reported as
unknown or ignored.

The ``.bzrignore`` file should normally be versioned, so that new
copies of the branch see the same patterns::

    % bzr add .bzrignore
    % bzr commit -m "Add ignore patterns"


Examining history
=================

bzr log
-------

The ``log`` command shows a list of previous revisions.


Branch statistics
=================

The ``bzr info`` command shows some summary information about
the working tree and the branch history.  


Versioning directories
======================

bzr versions files and directories in a way that can keep track of
renames and intelligently merge them::

    % mkdir src
    % echo 'int main() {}' > src/simple.c
    % bzr add src
    % bzr status
    A       src/
    ?       src/simple.c
    % bzr add src/simple.c
    % bzr status
    A       src/
    A       src/simple.c


Deleting and removing files
===========================

You can delete files or directories by just deleting them from the
working directory.  This is a bit different to CVS, which requires
that you also do *cvs remove*.

*bzr remove* makes the file un-versioned, but does not
delete the working copy.  This is useful when you add the wrong file,
or decide that a file should actually not be versioned. ::

    % rm -r src
    % bzr remove -v hello.txt
    ?       hello.txt
    % bzr status
    ?       hello.txt
    D       src/
    D       src/simple.c


Branching
=========

Often rather than starting your own project, you will want to
submit a change to an existing project.  You can get a copy of an
existing branch by copying its directory, expanding a tarball, or by a
remote copy using something like rsync.  You can also use bzr to fetch
a copy.  Because this new copy is potentially a new branch, the
command is called *branch*::

    % bzr branch http://bazaar-ng.org/bzr/main ./bzr-main
    % cd bzr-main

This copies down the complete history of this branch, so we can
do all operations on it locally: log, annotate, making and merging
branches.  There will be an option to get only part of the history if
you wish.



Following upstream changes
==========================

You can stay up-to-date with the parent branch by *pulling*
in their changes::

    % bzr pull

This only works if the local branch if your branch includes only
changes from the parent branch.  Otherwise, the branches are said to
have *diverged*, and they must be merged instead.