5
current for bzr 0.0.6pre, July 2005
8
*Note:* This tutorial is a work in
9
progress, and describes code that is itself still evolving.
10
If you have comments on either the design or the tutorial,
11
please send them to the bazaar-ng@lists.canonical.com mailing list.
18
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.
20
* 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.
22
* By recording comments on every revision, you produce an annotated history of the project, describing what, who, why, and when.
24
* 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.
26
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.
27
By branching, Bazaar-NG allows multiple people to cooperate on the evolution of a project, without all needing to work in strict
28
lock-step. Branching can be useful even for a single developer.
30
Bazaar-NG installs a single new command,
31
*bzr*. Everything else is a subcommand of this. You can get
32
some help with ``bzr help``. There will be more in the future.
36
Introducing yourself to bzr
37
===========================
39
One function of a version control system is to keep track of who
40
changed what. In a distributed system that requires an identifier for
41
each author that is globally unique. Most people already have one of
42
these: an email address.
44
[after 0.0.4] To tell bzr which email address to use, put it in the file
45
``$HOME/.bzr.conf/email``, or the environment variable ``$BZREMAIL``.
46
If neither of these are set, bzr will use the ``$EMAIL``
47
variable, or use your username and hostname.
49
To check this has taken effect, or if you forget your own name, use
50
the ``whoami`` ("who am i?") command::
54
Some people want to avoid sharing their email address so as not to
55
get spam. bzr will never
56
disclose your email address unless you tell it to by publishing an
57
archive or transmiting a changeset. It's recommended that you do use
58
a real address, so that people can contact you about your work, but
59
it's not required. You can use an address which is obfuscated, which
60
bounces, or which goes through an anti-spam service such as spamgourmet.com.
68
History is by default stored in the .bzr directory of the branch.
69
There will be a facility to store it in a separate repository, which
70
may be remote. We create a new branch by running *bzr init* in
71
an existing directory::
79
/home/mbp/work/bzr.test/tutorial
86
As for CVS, there are three classes of file: unknown, ignored, and
87
versioned. The *add* command makes a file versioned: that is,
88
changes to it will be recorded by the system::
90
% echo 'hello world' > hello.txt
95
% bzr add -v hello.txt
100
If you add the wrong file, simply use ``bzr remove`` to make
101
it unversioned again. This does not delete the working copy.
107
Once you have completed some work, you will want to *commit*
108
it to the version history. It is good to commit fairly often:
109
whenever you get a new feature working, fix a bug, or improve some
110
code or documentation. It's also a good practice to make sure that
111
the code compiles and passes its test suite before committing, to make
112
sure that every revision is a known-good state. You can also review
113
your changes, to make sure you're committing what you intend to, and
114
as a chance to rethink your work before you permanently record it.
116
Two bzr commands are particularly useful here: *status* and
117
*diff*. The *status* command
118
shows a listing with one line per file, indicating whether it has been
119
Added, Deleted, Modified, or Renamed in the current revision. Unknown
120
files are shown as '?'. With the ``--all`` option, the status
121
command also shows unmodified versioned files as '.', and ignored
127
The *diff* command shows the full text of changes to all
128
files as a standard unified diff. This can be piped through many
129
programs such as ``patch``, ``diffstat``,
130
``filterdiff`` and ``colordiff``::
133
*** added file 'hello.txt'
139
With the ``-r`` option, the tree is compared to an earlier
142
[TODO: options to run external diff; to get context diff or other
143
formats; to diff only selected files; to compare two historical
151
When the working tree state is satisfactory, it can be
152
*committed* to the branch, creating a new revision holding a
153
snapshot of that state.
155
The ``commit`` command takes a message describing the changes
156
in the revision. It also records your userid, the current time and
157
timezone, and the inventory and contents of the tree. The commit
158
message is specified by the ``-m`` or ``--message`` option.
159
You can enter a multi-line commit message; in most shells you can
160
enter this just by leaving the quotes open at the end of the line. ::
162
% bzr commit -m "added my first file"
164
[TODO: commit message interactively, through an editor or from a
167
[TODO: commit only selected files, including renamed/added/deleted
176
Many source trees contain some files that do not need to be
177
versioned, such as editor backups, object or bytecode files, and built
178
programs. You can simply not add them, but then they'll always crop
179
up as unknown files. You can also tell bzr to ignore these files by
180
adding them to a file called ``.bzrignore`` at the top of the
183
This file contains a list of file wildcards (or "globs"), one
184
per line. Typical contents are like this::
191
If a glob contains a slash, it is matched against the whole path
192
from the top of the tree; otherwise it is matched against only the
193
filename. So the previous example ignores ``*.o`` in all
194
subdirectories, but this example ignores only config.h at the top
195
level and HTML files in ``doc/``::
200
To get a list of which files are ignored and what pattern they matched, use ``bzr ignored``::
206
It is OK to have an ignore pattern match a versioned file, or to
207
add an ignored file. Ignore patterns have no effect on versioned
208
files; they only determine whether unversioned files are reported as
211
The ``.bzrignore`` file should normally be versioned, so that new
212
copies of the branch see the same patterns::
215
% bzr commit -m "Add ignore patterns"
224
The ``log`` command shows a list of previous revisions.
230
The ``bzr info`` command shows some summary information about
231
the working tree and the branch history.
234
Versioning directories
235
======================
237
bzr versions files and directories in a way that can keep track of
238
renames and intelligently merge them::
241
% echo 'int main() {}' > src/simple.c
246
% bzr add src/simple.c
252
Deleting and removing files
253
===========================
255
You can delete files or directories by just deleting them from the
256
working directory. This is a bit different to CVS, which requires
257
that you also do *cvs remove*.
259
*bzr remove* makes the file un-versioned, but does not
260
delete the working copy. This is useful when you add the wrong file,
261
or decide that a file should actually not be versioned. ::
264
% bzr remove -v hello.txt
275
Often rather than starting your own project, you will want to
276
submit a change to an existing project. You can get a copy of an
277
existing branch by copying its directory, expanding a tarball, or by a
278
remote copy using something like rsync. You can also use bzr to fetch
279
a copy. Because this new copy is potentially a new branch, the
280
command is called *branch*::
282
% bzr branch http://bazaar-ng.org/bzr/main ./bzr-main
285
This copies down the complete history of this branch, so we can
286
do all operations on it locally: log, annotate, making and merging
287
branches. There will be an option to get only part of the history if
292
Following upstream changes
293
==========================
295
You can stay up-to-date with the parent branch by *pulling*
300
This only works if the local branch if your branch includes only
301
changes from the parent branch. Otherwise, the branches are said to
302
have *diverged*, and they must be merged instead.