~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/en/mini-tutorial/index.txt

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Bazaar in five minutes
3
3
======================
4
4
 
 
5
.. contents::
 
6
 
5
7
Introduction
6
8
============
7
9
 
8
10
Bazaar is a distributed version control system that makes it easier for
9
 
people to work together on software projects.
 
11
people to work together on software projects. 
10
12
 
11
13
Over the next five minutes, you'll learn how to put your files under
12
14
version control, how to record changes to them, examine your work, publish
13
15
it and send your work for merger into a project's trunk.
14
16
 
 
17
If you'd prefer a more detailed introduction, take a look at 
 
18
`Learning More`_.
 
19
 
15
20
 
16
21
Installation
17
22
============
26
31
For other platforms and to install from source code, see the Download_
27
32
and Installation_ pages.
28
33
 
29
 
.. _installation instructions for Windows: http://wiki.bazaar.canonical.com/WindowsDownloads
30
 
.. _installation instructions for Mac OS X: http://wiki.bazaar.canonical.com/MacOSXBundle
31
 
.. _Download: http://wiki.bazaar.canonical.com/Download
32
 
.. _Installation: http://wiki.bazaar.canonical.com/InstallationFaq
 
34
.. _installation instructions for Windows: http://bazaar-vcs.org/WindowsDownloads
 
35
.. _installation instructions for Mac OS X: http://bazaar-vcs.org/MacOSXBundle
 
36
.. _Download: http://bazaar-vcs.org/Download
 
37
.. _Installation: http://bazaar-vcs.org/InstallationFaq
33
38
 
34
39
 
35
40
Introducing yourself
36
41
====================
37
42
 
38
 
Bazaar records changes to source code, and it records who made the change.
39
 
The person is identified by their name and email address.  (If you're
40
 
concerned about spam, you don't need to use a real address that you
41
 
actually read, but the convention is that it looks like an email address.)
 
43
Before you start working, it is good to tell Bazaar who you are. That
 
44
way your work is properly identified in revision logs.
42
45
 
43
 
Before you start working, let's tell Bazaar who you are.  Using your name
44
 
and email address, instead of John Doe's, type::
 
46
Using your name and email address, instead of John Doe's, type::
45
47
 
46
48
  $ bzr whoami "John Doe <john.doe@gmail.com>"
 
49
  
 
50
Bazaar will now create or modify a configuration file, including your
 
51
name and email address.
47
52
 
48
 
You can check what identity is stored in Bazaar's configuration::
 
53
Now, check that your name and email address are correctly registered::
49
54
 
50
55
  $ bzr whoami
51
56
  John Doe <john.doe@gmail.com>
52
57
 
53
58
 
54
 
Starting a new project
55
 
======================
56
 
 
57
 
Let's suppose we want to store a new project under Bazaar.  First, we'll
58
 
make a *repository directory* to hold all our work related to this
59
 
project, where developers can create branches to test development of
60
 
specific features or, more generally, modifications to the working file
61
 
set.  
62
 
 
63
 
After creating the repository, change to that directory, and create the
64
 
project's main trunk branch.
65
 
 
66
 
::
67
 
 
68
 
  $ bzr init-repo sample
69
 
  Shared repository with trees (format: 2a)
70
 
  Location:
71
 
    shared repository: sample
72
 
  $ bzr init sample/trunk
73
 
  $ cd sample/trunk
74
 
  Created a repository tree (format: 2a)                                         
75
 
  Using shared repository: /home/john/sample/
76
 
 
77
 
 
78
 
Adding files
79
 
============
80
 
 
81
 
Now that we have the trunk, we need to move to that directory and
82
 
create some example files for the first version of that project.  Create
83
 
a file ``test1.txt`` using a text editor (like emacs, nano, or notepad),
84
 
and save it.  Then we'll "add" the file, which tells bzr we want it to
85
 
track changes::
86
 
 
87
 
  bzr add test1.txt
88
 
 
89
 
and then commit, which saves a snapshot of all versioned files::
90
 
 
91
 
  bzr commit -m "Added first line of text"
 
59
Putting files under version control
 
60
===================================
 
61
 
 
62
Let's create a directory and some files to use with Bazaar::
 
63
 
 
64
 $ mkdir myproject
 
65
 $ cd myproject
 
66
 $ mkdir subdirectory
 
67
 $ touch test1.txt test2.txt test3.txt subdirectory/test4.txt
 
68
 
 
69
**Note for Windows users:** use Windows Explorer to create your
 
70
directories, then right-click in those directories and select 
 
71
``New file`` to create your files.
 
72
 
 
73
Now get Bazaar to initalize itself in your project directory::
 
74
 
 
75
  $ bzr init
 
76
  
 
77
If it looks like nothing happened, don't worry. Bazaar has created a
 
78
branch_ where it will store your files and their revision histories.
 
79
 
 
80
.. _branch: http://bazaar-vcs.org/Branch
 
81
 
 
82
The next step is to tell Bazaar which files you want to track. Running
 
83
``bzr add`` will recursively add everything in the project::
 
84
 
 
85
 $ bzr add
 
86
 added subdirectory
 
87
 added test1.txt
 
88
 added test2.txt
 
89
 added test3.txt
 
90
 added subdirectory/test4.txt
 
91
 
 
92
Next, take a snapshot of your files by committing them to your branch. Add 
 
93
a message to explain why you made the commit::
 
94
 
 
95
  $ bzr commit -m "Initial import"
 
96
  
 
97
As Bazaar is a distributed version control system, it doesn't need to 
 
98
connect to a central server to make the commit. Instead, Bazaar stores your 
 
99
branch and all its commits inside the directory you're working with; look
 
100
for the ``.bzr`` sub-directory.
92
101
 
93
102
 
94
103
Making changes to your files
95
104
============================
96
105
 
97
 
 
98
106
Let's change a file and commit that change to your branch.
99
107
 
100
 
Edit ``test1.txt`` in your favourite editor, then use ``bzr add`` to tell bzr
101
 
to track changes to this file ::
102
 
 
103
 
  $ echo test test test > test1.txt 
104
 
  $ bzr add test1.txt
105
 
  adding test1.txt
106
 
 
107
 
`bzr diff` shows the changes between the last revision in this branch, and your
108
 
current tree (or, with the ``-r`` option, between any two trees). ::
 
108
Edit ``test1.txt`` in your favourite editor, then check what have you done::
109
109
 
110
110
 $ bzr diff
111
111
 === modified file 'test1.txt'
117
117
Commit your work to the Bazaar branch::
118
118
 
119
119
  $ bzr commit -m "Added first line of text"
120
 
  Committing to: /home/john/sample/trunk/                             
121
 
  added test1.txt
122
 
  Committed revision 1.
 
120
  Committed revision 2.
 
121
 
123
122
 
124
123
Viewing the revision log
125
124
========================
127
126
You can see the history of your branch by browsing its log::
128
127
 
129
128
  $ bzr log
 
129
  ------------------------------------------------------------
 
130
  revno: 2
 
131
  committer: John Doe <john.doe@gmail.com>
 
132
  branch nick: myproject
 
133
  timestamp: Mon 2007-10-08 17:56:14 +0000
 
134
  message:
 
135
    Added first line of text
 
136
  ------------------------------------------------------------
130
137
  revno: 1
131
138
  committer: John Doe <john.doe@gmail.com>
132
 
  branch nick: trunk
 
139
  branch nick: myproject
133
140
  timestamp: Mon 2006-10-08 17:46:22 +0000
134
141
  message:
135
142
    Initial import
136
143
 
137
144
 
138
 
Publishing your branch on Launchpad
139
 
===================================
140
 
 
141
 
Launchpad is a suite of development and hosting tools for
142
 
software projects. You can use it to publish your branch.  (You can 
143
 
also publish branches onto your own server or other hosting services.)
144
 
 
145
 
The steps to publishing branches on Launchpad are:
146
 
 
147
 
1. Create a Launchpad account: visit the `Launchpad login page`_ and choose to create a new account.
148
 
    
149
 
.. _Launchpad login page: https://launchpad.net/+login
150
 
    
151
 
2. Bazaar uses the SSH encryption and authentication protocol to connect
152
 
   to Launchpad.  You need to first `create an SSH key`_ on your own computer,
153
 
   by running the command::
154
 
    
155
 
       $ ssh-keygen
156
 
 
157
 
.. _create an SSH key: https://help.launchpad.net/YourAccount/CreatingAnSSHKeyPair    
158
 
       
159
 
3. `Upload your SSH public key to Launchpad`_.
160
 
 
161
 
.. _Upload your SSH public key to Launchpad: https://launchpad.net/~/+editsshkeys
162
 
    
163
 
4. `Make a team for your project`_.  Even if you're starting as the only
164
 
   developer on this project, creating a new one now will let you more
165
 
   easily add other people later.
166
 
 
167
 
.. _Make a team for your project: https://help.launchpad.net/Teams/CreatingAndRunning
168
 
      
169
 
5. `Create a project`_.
170
 
  
171
 
.. _Create a project: https://help.launchpad.net/Projects/Registering
172
 
 
173
 
6. Tell Bazaar your Launchpad account name.  If your account is john.doe, type ::
174
 
  
175
 
      $ bzr launchpad-login john.doe
176
 
 
177
 
7. `Push the branch for your project`_.  Once you've committed your changes 
178
 
   locally, you can publish them as the trunk of your new project by saying
179
 
    
180
 
       $ bzr push lp:~sample-developers/sample/trunk
181
 
       
182
 
   (Of course, using the team and project names you just chose.)
183
 
 
184
 
.. _Push the branch for your project: https://help.launchpad.net/Code/UploadingABranch
 
145
Publishing your branch with sftp
 
146
================================
 
147
 
 
148
There are a couple of ways to publish your branch. If you already have
 
149
an SFTP server or are comfortable setting one up, you can publish your
 
150
branch to it.
 
151
 
 
152
Otherwise, skip to the next section to publish with Launchpad_, a free
 
153
hosting service for Bazaar.
 
154
 
 
155
.. _Launchpad: https://launchpad.net/
 
156
 
 
157
Let's assume you want to publish your branch at ``www.example.com/myproject``::
 
158
 
 
159
 $ bzr push --create-prefix sftp://your.name@example.com/~/public_html/myproject
 
160
 2 revision(s) pushed.
 
161
 
 
162
Bazaar will create a ``myproject`` directory on the remote server and
 
163
push your branch to it.
 
164
 
 
165
Now anyone can create their own copy of your branch by typing::
 
166
 
 
167
 $ bzr branch http://www.example.com/myproject
 
168
 
 
169
**Note:** to use sftp, you may need to install ``paramiko`` and
 
170
``pyCrypto``. See http://bazaar-vcs.org/InstallationFaq for details.
 
171
 
 
172
 
 
173
Publishing your branch with Launchpad
 
174
=====================================
 
175
 
 
176
Launchpad is a suite of development and hosting tools for free 
 
177
software projects. You can use it to publish your branch.
 
178
 
 
179
If you don't have a Launchpad account, follow the `account signup guide`_
 
180
and `register an SSH key`_ in your new Launchpad account.
 
181
 
 
182
.. _account signup guide: https://help.launchpad.net/CreatingYourLaunchpadAccount
 
183
.. _register an SSH key: https://launchpad.net/people/+me/+editsshkeys
 
184
 
 
185
Replacing ``john.doe`` with your own Launchpad username, type::
 
186
 
 
187
 $ bzr push bzr+ssh://john.doe@bazaar.launchpad.net/~john.doe/+junk/myproject
 
188
 
 
189
**Note:** ``+junk`` means that this branch isn't associated with any particular
 
190
project in Launchpad.
 
191
 
 
192
Now, anyone can create their own copy of your branch by typing::
 
193
 
 
194
 $ bzr branch http://bazaar.launchpad.net/~john.doe/+junk/myproject
 
195
 
 
196
You can also see information about your branch, including its revision
 
197
history, at https://code.launchpad.net/people/+me/+junk/myproject
 
198
 
185
199
 
186
200
Creating your own copy of another branch
187
201
========================================
188
202
 
189
 
To work with someone else's code, you can make your own copy of their
 
203
To work with someone else's code, you can make your own copy of their 
190
204
branch. Let's take a real-world example, Bazaar's GTK interface::
191
205
 
192
 
  $ bzr init-repo ~/bzr-gtk
193
 
  $ bzr branch lp:~bzr/bzr-gtk/trunk ~/bzr-gtk/john
194
 
  Branched 292 revision(s).
 
206
  $ bzr branch http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk bzr-gtk.john
 
207
  Branched 292 revision(s).                                                        
195
208
 
196
209
Bazaar will download all the files and complete revision history from the
197
 
bzr-gtk project's trunk branch and create a copy called ``john``.
 
210
bzr-gtk project's trunk branch and create a copy called bzr-gtk.john.
198
211
 
199
 
Now, you have your own copy of the branch and can commit changes with
200
 
or without a net connection. You can share your branch at any time by
201
 
publishing it and, if the  bzr-gtk team want to use your work, Bazaar
 
212
Now, you have your own copy of the branch and can commit changes with 
 
213
or without a net connection. You can share your branch at any time by 
 
214
publishing it and, if the  bzr-gtk team want to use your work, Bazaar 
202
215
makes it easy for them to merge your branch back into their trunk branch.
203
216
 
204
217
 
214
227
  $ bzr merge
215
228
  Merging from saved parent location: http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk
216
229
  All changes applied successfully.
217
 
 
 
230
            
218
231
Check what has changed::
219
232
 
220
233
  $ bzr diff
221
 
 
222
 
If different branches have made changes to the same areas of the same
223
 
files, then merging them may generate conflicts.  When this happens,
224
 
Bazaar puts text markers like ``<<<<<<<`` into the files, and records them
225
 
in a list of conflicted files.  You should edit the files to reflect the
226
 
way you want to resolve the conflicts, use ``bzr diff`` to check the
227
 
changes, and then ``bzr resolve`` to mark them as resolved.
228
 
 
 
234
 
229
235
If you're happy with the changes, you can commit them to your personal
230
236
branch::
231
237
 
233
239
  Committed revision 295.
234
240
 
235
241
 
 
242
Merging your work into the parent branch
 
243
========================================
 
244
 
 
245
After you've worked on your personal branch of bzr-gtk, you may want to
 
246
send your changes back upstream to the project. The easiest way is to
 
247
use a merge directive.
 
248
 
 
249
A merge directive is a machine-readable request to perform a 
 
250
particular merge.  It usually contains a patch preview of the merge 
 
251
and either contains the necessary revisions, or provides a branch 
 
252
where they can be found.
 
253
 
 
254
Replacing ``mycode.patch``, create your merge directive::
 
255
 
 
256
 $ bzr send -o mycode.patch
 
257
 Using saved parent location: http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk
 
258
 
 
259
You can now email the merge directive to the bzr-gtk project who, if
 
260
they choose, can use it merge your work back into the parent branch.
 
261
 
 
262
 
236
263
Learning more
237
264
=============
238
265
 
243
270
 
244
271
  $ bzr help
245
272
 
 
273
To learn about Bazaar commands::
 
274
 
 
275
  $ bzr help commands
 
276
 
246
277
To learn about the ''foo'' topic or command::
247
278
 
248
279
  $ bzr help foo
249
 
 
250
 
Licence
251
 
=======
252
 
 
253
 
Copyright 2007-2011 Canonical Ltd. Bazaar is free software, and you
254
 
may use, modify and redistribute both Bazaar and this document under
255
 
the terms of the GNU General Public License version 2 or later. See
256
 
<http://www.gnu.org/licenses/>.