~bzr-pqm/bzr/bzr.dev

974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
1
==================
2
Bazaar-NG Tutorial
3
==================
4
5
current for bzr 0.0.6pre, July 2005
6
7
1171 by Martin Pool
- typo fixes from kfish
8
*NOTE* For a more current and user-editable version of this 
9
document, see the wiki at http://bazaar.canonical.com/IntroductionToBzr
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
10
11
12
Introduction
13
============
14
15
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.
16
17
 * 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.
18
19
 * By recording comments on every revision, you produce an annotated history of the project, describing what, who, why, and when.
20
21
 * 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.
22
23
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.  
24
By branching, Bazaar-NG allows multiple people to cooperate on the evolution of a project, without all needing to work in strict
25
lock-step.  Branching can be useful even for a single developer.
26
27
Bazaar-NG installs a single new command,
28
*bzr*.  Everything else is a subcommand of this.  You can get
29
some help with ``bzr help``.  There will be more in the future.
30
31
32
33
Introducing yourself to bzr
34
===========================
35
36
One function of a version control system is to keep track of who
37
changed what.  In a distributed system that requires an identifier for
38
each author that is globally unique.  Most people already have one of
39
these: an email address.
40
1185.74.6 by James Blackwell
Minor fixes to tutorial
41
To tell bzr which email address to use, three options exist:
42
43
  * Set $EMAIL or $BZREMAIL to the email address that you would like
44
45
  * Add the following to ~/.bazaar/bazaar.conf :
46
     [DEFAULT]
47
     email=Your Name <name@isp.com>
48
49
  * On a Brancy by branch basis by adding to ~/.bazaar/branches.conf:
50
     [/the/location/for/a/branch]
51
     email=Your Name <name@isp.com>
52
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
53
``$HOME/.bzr.conf/email``, or the environment variable ``$BZREMAIL``.
54
If neither of these are set, bzr will use the ``$EMAIL``
55
variable, or use your username and hostname.
56
57
To check this has taken effect, or if you forget your own name, use
58
the ``whoami`` ("who am i?") command::
59
60
  % bzr whoami
61
1185.74.6 by James Blackwell
Minor fixes to tutorial
62
Some people want to avoid sharing their email address so as not to get
63
spam.  bzr will never disclose your email address unless you tell it to by
64
publishing an archive or transmitting a changeset.  It's recommended that
65
you do use a real address, so that people can contact you about your work,
66
but it's not required.  You can use an address which is obfuscated, which
67
bounces, or which goes through an anti-spam service such as
68
spamgourmet.com.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
69
70
71
72
Creating a branch
73
==================
74
75
76
History is by default stored in the .bzr directory of the branch.
77
There will be a facility to store it in a separate repository, which
78
may be remote.  We create a new branch by running *bzr init* in
79
an existing directory::
80
81
    % mkdir tutorial
82
    % cd tutorial
83
    % ls -a
84
    ls -a
85
    ./  ../
86
    % pwd
87
    /home/mbp/work/bzr.test/tutorial
88
    %
89
    % bzr init
90
    % ls -aF
91
    ./  ../  .bzr/
92
    %
93
94
As for CVS, there are three classes of file: unknown, ignored, and
95
versioned.  The *add* command makes a file versioned: that is,
96
changes to it will be recorded by the system::
97
98
    % echo 'hello world' > hello.txt
99
    % bzr status
100
    ?       hello.txt
101
    % bzr unknowns
102
    hello.txt
103
    % bzr add -v hello.txt
104
    A       hello.txt
105
    % bzr unknowns
106
107
108
If you add the wrong file, simply use ``bzr remove`` to make
109
it unversioned again.  This does not delete the working copy.
110
111
112
Reviewing changes
113
=================
114
115
Once you have completed some work, you will want to *commit*
116
it to the version history.  It is good to commit fairly often:
117
whenever you get a new feature working, fix a bug, or improve some
118
code or documentation.  It's also a good practice to make sure that
119
the code compiles and passes its test suite before committing, to make
120
sure that every revision is a known-good state.  You can also review
121
your changes, to make sure you're committing what you intend to, and
122
as a chance to rethink your work before you permanently record it. 
123
124
Two bzr commands are particularly useful here: *status* and
125
*diff*.  The *status* command
126
shows a listing with one line per file, indicating whether it has been
127
Added, Deleted, Modified, or Renamed in the current revision.  Unknown
128
files are shown as '?'.  With the ``--all`` option, the status
129
command also shows unmodified versioned files as '.', and ignored
130
files as 'I'::
131
132
    % bzr status
133
    A       hello.txt
134
135
The *diff* command shows the full text of changes to all
136
files as a standard unified diff.  This can be piped through many
137
programs such as ``patch``, ``diffstat``,
138
``filterdiff`` and ``colordiff``::
139
140
    % bzr diff
141
    *** added file 'hello.txt'
142
    --- /dev/null 
143
    +++ hello.txt 
144
    @@ -1,0 +1,1 @@
145
    +hello world
146
147
With the ``-r`` option, the tree is compared to an earlier
148
revision.
149
150
[TODO: options to run external diff; to get context diff or other
151
formats; to diff only selected files; to compare two historical
152
revisions.]
153
154
155
156
Committing changes
157
==================
158
159
When the working tree state is satisfactory, it can be
160
*committed* to the branch, creating a new revision holding a
161
snapshot of that state.  
162
163
The ``commit`` command takes a message describing the changes
164
in the revision.  It also records your userid, the current time and
165
timezone, and the inventory and contents of the tree.  The commit
166
message is specified by the ``-m`` or ``--message`` option.
167
You can enter a multi-line commit message; in most shells you can
168
enter this just by leaving the quotes open at the end of the line. ::
169
170
    % bzr commit -m "added my first file"
171
172
[TODO: commit message interactively, through an editor or from a
173
file.]
174
175
[TODO: commit only selected files, including renamed/added/deleted
176
files.]
177
178
179
180
Removing uncommitted changes
181
============================
182
183
If you've made some changes and don't want to keep them, use the
184
``revert`` command to go back to the previous head version.  It's a
185
good idea to use ``bzr diff`` first to see what will be removed. 
186
By default the revert command reverts the whole tree; if file or
187
directory names are given then only those ones will be affected.
188
revert also clears the list of pending merges revisions.
189
190
191
192
193
194
Ignoring files
195
==============
196
197
Many source trees contain some files that do not need to be
198
versioned, such as editor backups, object or bytecode files, and built
199
programs.  You can simply not add them, but then they'll always crop
200
up as unknown files.  You can also tell bzr to ignore these files by
201
adding them to a file called ``.bzrignore`` at the top of the
202
tree.
203
204
This file contains a list of file wildcards (or "globs"), one
205
per line.  Typical contents are like this::
206
207
    *.o
208
    *~
209
    *.tmp
210
    *.py[co]
211
212
If a glob contains a slash, it is matched against the whole path
213
from the top of the tree; otherwise it is matched against only the
214
filename.  So the previous example ignores ``*.o`` in all
215
subdirectories, but this example ignores only config.h at the top
216
level and HTML files in ``doc/``::
217
218
    ./config.h
219
    doc/*.html
220
221
To get a list of which files are ignored and what pattern they matched, use ``bzr ignored``::
222
223
    % bzr ignored
224
    config.h                                           ./config.h
225
    configure.in~                                      *~
226
227
It is OK to have an ignore pattern match a versioned file, or to
228
add an ignored file.  Ignore patterns have no effect on versioned
229
files; they only determine whether unversioned files are reported as
230
unknown or ignored.
231
232
The ``.bzrignore`` file should normally be versioned, so that new
233
copies of the branch see the same patterns::
234
235
    % bzr add .bzrignore
236
    % bzr commit -m "Add ignore patterns"
237
238
239
Examining history
240
=================
241
242
bzr log
243
-------
244
245
The ``log`` command shows a list of previous revisions.
246
247
248
Branch statistics
249
=================
250
251
The ``bzr info`` command shows some summary information about
252
the working tree and the branch history.  
253
254
255
Versioning directories
256
======================
257
258
bzr versions files and directories in a way that can keep track of
259
renames and intelligently merge them::
260
261
    % mkdir src
262
    % echo 'int main() {}' > src/simple.c
263
    % bzr add src
264
    % bzr status
265
    A       src/
266
    ?       src/simple.c
267
    % bzr add src/simple.c
268
    % bzr status
269
    A       src/
270
    A       src/simple.c
271
272
273
Deleting and removing files
274
===========================
275
276
You can delete files or directories by just deleting them from the
277
working directory.  This is a bit different to CVS, which requires
278
that you also do *cvs remove*.
279
280
*bzr remove* makes the file un-versioned, but does not
281
delete the working copy.  This is useful when you add the wrong file,
282
or decide that a file should actually not be versioned. ::
283
284
    % rm -r src
285
    % bzr remove -v hello.txt
286
    ?       hello.txt
287
    % bzr status
288
    ?       hello.txt
289
    D       src/
290
    D       src/simple.c
291
292
293
Branching
294
=========
295
296
Often rather than starting your own project, you will want to
297
submit a change to an existing project.  You can get a copy of an
298
existing branch by copying its directory, expanding a tarball, or by a
299
remote copy using something like rsync.  You can also use bzr to fetch
300
a copy.  Because this new copy is potentially a new branch, the
301
command is called *branch*::
302
1185.1.13 by Robert Collins
and the tutorial patch came back, the very next day
303
    % bzr branch http://bazaar-ng.org/bzr/bzr.dev
304
    % cd bzr.dev
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
305
306
This copies down the complete history of this branch, so we can
307
do all operations on it locally: log, annotate, making and merging
308
branches.  There will be an option to get only part of the history if
309
you wish.
310
311
312
313
Following upstream changes
314
==========================
315
316
You can stay up-to-date with the parent branch by *pulling*
317
in their changes::
318
319
    % bzr pull
320
1171 by Martin Pool
- typo fixes from kfish
321
This only works if your local branch includes only changes from the
322
parent branch.  Otherwise, the branches are said to have *diverged*,
323
and they must be merged instead.