~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tutorial.txt

  • Committer: Martin Pool
  • Date: 2005-07-07 10:22:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050707102201-2d2a13a25098b101
- rearrange and clear up merged weave

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
172
 
 
173
 
Ignoring files
174
 
==============
175
 
 
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
181
 
tree.
182
 
 
183
 
This file contains a list of file wildcards (or "globs"), one
184
 
per line.  Typical contents are like this::
185
 
 
186
 
    *.o
187
 
    *~
188
 
    *.tmp
189
 
    *.py[co]
190
 
 
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/``::
196
 
 
197
 
    ./config.h
198
 
    doc/*.html
199
 
 
200
 
To get a list of which files are ignored and what pattern they matched, use ``bzr ignored``::
201
 
 
202
 
    % bzr ignored
203
 
    config.h                                           ./config.h
204
 
    configure.in~                                      *~
205
 
 
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
209
 
unknown or ignored.
210
 
 
211
 
The ``.bzrignore`` file should normally be versioned, so that new
212
 
copies of the branch see the same patterns::
213
 
 
214
 
    % bzr add .bzrignore
215
 
    % bzr commit -m "Add ignore patterns"
216
 
 
217
 
 
218
 
Examining history
219
 
=================
220
 
 
221
 
bzr log
222
 
-------
223
 
 
224
 
The ``log`` command shows a list of previous revisions.
225
 
 
226
 
 
227
 
Branch statistics
228
 
=================
229
 
 
230
 
The ``bzr info`` command shows some summary information about
231
 
the working tree and the branch history.  
232
 
 
233
 
 
234
 
Versioning directories
235
 
======================
236
 
 
237
 
bzr versions files and directories in a way that can keep track of
238
 
renames and intelligently merge them::
239
 
 
240
 
    % mkdir src
241
 
    % echo 'int main() {}' > src/simple.c
242
 
    % bzr add src
243
 
    % bzr status
244
 
    A       src/
245
 
    ?       src/simple.c
246
 
    % bzr add src/simple.c
247
 
    % bzr status
248
 
    A       src/
249
 
    A       src/simple.c
250
 
 
251
 
 
252
 
Deleting and removing files
253
 
===========================
254
 
 
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*.
258
 
 
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. ::
262
 
 
263
 
    % rm -r src
264
 
    % bzr remove -v hello.txt
265
 
    ?       hello.txt
266
 
    % bzr status
267
 
    ?       hello.txt
268
 
    D       src/
269
 
    D       src/simple.c
270
 
 
271
 
 
272
 
Branching
273
 
=========
274
 
 
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*::
281
 
 
282
 
    % bzr branch http://bazaar-ng.org/bzr/main ./bzr-main
283
 
    % cd bzr-main
284
 
 
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
288
 
you wish.
289
 
 
290
 
 
291
 
 
292
 
Following upstream changes
293
 
==========================
294
 
 
295
 
You can stay up-to-date with the parent branch by *pulling*
296
 
in their changes::
297
 
 
298
 
    % bzr pull
299
 
 
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.