~bzr-pqm/bzr/bzr.dev

1031 by Martin Pool
- move in tutorial from web site
1
==================
2
Bazaar-NG Tutorial
3
==================
4
5
current for bzr 0.0.6pre, July 2005
6
7
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.
12
13
14
15
Introduction
16
============
17
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.
19
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.
21
22
 * By recording comments on every revision, you produce an annotated history of the project, describing what, who, why, and when.
23
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.
25
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.
29
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.
33
34
35
36
Introducing yourself to bzr
37
===========================
38
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.
43
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.
48
49
To check this has taken effect, or if you forget your own name, use
50
the ``whoami`` ("who am i?") command::
51
52
  % bzr whoami
53
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.
61
62
63
64
Creating a branch
65
==================
66
67
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::
72
73
    % mkdir tutorial
74
    % cd tutorial
75
    % ls -a
76
    ls -a
77
    ./  ../
78
    % pwd
79
    /home/mbp/work/bzr.test/tutorial
80
    %
81
    % bzr init
82
    % ls -aF
83
    ./  ../  .bzr/
84
    %
85
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::
89
90
    % echo 'hello world' > hello.txt
91
    % bzr status
92
    ?       hello.txt
93
    % bzr unknowns
94
    hello.txt
95
    % bzr add -v hello.txt
96
    A       hello.txt
97
    % bzr unknowns
98
99
100
If you add the wrong file, simply use ``bzr remove`` to make
101
it unversioned again.  This does not delete the working copy.
102
103
104
Reviewing changes
105
=================
106
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. 
115
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
122
files as 'I'::
123
124
    % bzr status
125
    A       hello.txt
126
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``::
131
132
    % bzr diff
133
    *** added file 'hello.txt'
134
    --- /dev/null 
135
    +++ hello.txt 
136
    @@ -1,0 +1,1 @@
137
    +hello world
138
139
With the ``-r`` option, the tree is compared to an earlier
140
revision.
141
142
[TODO: options to run external diff; to get context diff or other
143
formats; to diff only selected files; to compare two historical
144
revisions.]
145
146
147
148
Committing changes
149
==================
150
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.  
154
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. ::
161
162
    % bzr commit -m "added my first file"
163
164
[TODO: commit message interactively, through an editor or from a
165
file.]
166
167
[TODO: commit only selected files, including renamed/added/deleted
168
files.]
169
170
171
1052 by Martin Pool
- add revert command to tutorial
172
Removing uncommitted changes
173
============================
174
175
If you've made some changes and don't want to keep them, use the
176
``revert`` command to go back to the previous head version.  It's a
177
good idea to use ``bzr diff`` first to see what will be removed. 
178
By default the revert command reverts the whole tree; if file or
179
directory names are given then only those ones will be affected.
180
revert also clears the list of pending merges revisions.
181
182
183
184
1031 by Martin Pool
- move in tutorial from web site
185
186
Ignoring files
187
==============
188
189
Many source trees contain some files that do not need to be
190
versioned, such as editor backups, object or bytecode files, and built
191
programs.  You can simply not add them, but then they'll always crop
192
up as unknown files.  You can also tell bzr to ignore these files by
193
adding them to a file called ``.bzrignore`` at the top of the
194
tree.
195
196
This file contains a list of file wildcards (or "globs"), one
197
per line.  Typical contents are like this::
198
199
    *.o
200
    *~
201
    *.tmp
202
    *.py[co]
203
204
If a glob contains a slash, it is matched against the whole path
205
from the top of the tree; otherwise it is matched against only the
206
filename.  So the previous example ignores ``*.o`` in all
207
subdirectories, but this example ignores only config.h at the top
208
level and HTML files in ``doc/``::
209
210
    ./config.h
211
    doc/*.html
212
213
To get a list of which files are ignored and what pattern they matched, use ``bzr ignored``::
214
215
    % bzr ignored
216
    config.h                                           ./config.h
217
    configure.in~                                      *~
218
219
It is OK to have an ignore pattern match a versioned file, or to
220
add an ignored file.  Ignore patterns have no effect on versioned
221
files; they only determine whether unversioned files are reported as
222
unknown or ignored.
223
224
The ``.bzrignore`` file should normally be versioned, so that new
225
copies of the branch see the same patterns::
226
227
    % bzr add .bzrignore
228
    % bzr commit -m "Add ignore patterns"
229
230
231
Examining history
232
=================
233
234
bzr log
235
-------
236
237
The ``log`` command shows a list of previous revisions.
238
239
240
Branch statistics
241
=================
242
243
The ``bzr info`` command shows some summary information about
244
the working tree and the branch history.  
245
246
247
Versioning directories
248
======================
249
250
bzr versions files and directories in a way that can keep track of
251
renames and intelligently merge them::
252
253
    % mkdir src
254
    % echo 'int main() {}' > src/simple.c
255
    % bzr add src
256
    % bzr status
257
    A       src/
258
    ?       src/simple.c
259
    % bzr add src/simple.c
260
    % bzr status
261
    A       src/
262
    A       src/simple.c
263
264
265
Deleting and removing files
266
===========================
267
268
You can delete files or directories by just deleting them from the
269
working directory.  This is a bit different to CVS, which requires
270
that you also do *cvs remove*.
271
272
*bzr remove* makes the file un-versioned, but does not
273
delete the working copy.  This is useful when you add the wrong file,
274
or decide that a file should actually not be versioned. ::
275
276
    % rm -r src
277
    % bzr remove -v hello.txt
278
    ?       hello.txt
279
    % bzr status
280
    ?       hello.txt
281
    D       src/
282
    D       src/simple.c
283
284
285
Branching
286
=========
287
288
Often rather than starting your own project, you will want to
289
submit a change to an existing project.  You can get a copy of an
290
existing branch by copying its directory, expanding a tarball, or by a
291
remote copy using something like rsync.  You can also use bzr to fetch
292
a copy.  Because this new copy is potentially a new branch, the
293
command is called *branch*::
294
295
    % bzr branch http://bazaar-ng.org/bzr/main ./bzr-main
296
    % cd bzr-main
297
298
This copies down the complete history of this branch, so we can
299
do all operations on it locally: log, annotate, making and merging
300
branches.  There will be an option to get only part of the history if
301
you wish.
302
303
304
305
Following upstream changes
306
==========================
307
308
You can stay up-to-date with the parent branch by *pulling*
309
in their changes::
310
311
    % bzr pull
312
313
This only works if the local branch if your branch includes only
314
changes from the parent branch.  Otherwise, the branches are said to
315
have *diverged*, and they must be merged instead.