Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > 27647990744ebd9cfe32398f37f67e20 > files > 2999

bzr-2.6.0-11.1.mga5.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Bazaar Tutorial &mdash; Bazaar 2.6.0 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/bzr.ico"/>
    <link rel="top" title="Bazaar 2.6.0 documentation" href="../index.html" />
    <link rel="up" title="Tutorials" href="index.html" />
    <link rel="next" title="Using Bazaar with Launchpad" href="using_bazaar_with_launchpad.html" />
    <link rel="prev" title="Bazaar in five minutes" href="../mini-tutorial/index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="using_bazaar_with_launchpad.html" title="Using Bazaar with Launchpad"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="../mini-tutorial/index.html" title="Bazaar in five minutes"
             accesskey="P">previous</a> |</li>
<li><a href="http://bazaar.canonical.com/">
    <img src="../_static/bzr icon 16.png" /> Home</a>&nbsp;|&nbsp;</li>
<a href="http://doc.bazaar.canonical.com/en/">Documentation</a>&nbsp;|&nbsp;</li>

        <li><a href="../index.html">Table of Contents (2.6.0)</a> &raquo;</li>

          <li><a href="index.html" accesskey="U">Tutorials</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="bazaar-tutorial">
<h1>Bazaar Tutorial<a class="headerlink" href="#bazaar-tutorial" title="Permalink to this headline">¶</a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>If you are already familiar with decentralized version control, then
please feel free to skip ahead to &#8220;Introducing Yourself to Bazaar&#8221;. If,
on the other hand, you are familiar with version control but not
decentralized version control, then please start at &#8220;How DVCS is
different.&#8221; Otherwise, get some coffee or tea, get comfortable and get
ready to catch up.</p>
</div>
<div class="section" id="the-purpose-of-version-control">
<h2>The purpose of version control<a class="headerlink" href="#the-purpose-of-version-control" title="Permalink to this headline">¶</a></h2>
<p>Odds are that you have worked on some sort of textual data &#8211; the sources
to a program, web sites or the config files that Unix system
administrators have to deal with in /etc. The chances are also good that
you have made some sort of mistake that you deeply regretted. Perhaps you
deleted the configuration file for your mailserver or perhaps mauled the
source code for a pet project. Whatever happened, you have just deleted
important information that you would desperately like to get back. If this
has ever happened to you, then you are probably ready for Bazaar.</p>
<p>Version control systems (which I&#8217;ll henceforth call VCS) such as
Bazaar give you the ability to track changes for a directory by turning
it into something slightly more complicated than a directory that we call
a <strong>branch</strong>. The branch not only stores how the directory looks right
now, but also how it looked at various points in the past. Then, when you
do something you wish you hadn&#8217;t, you can restore the directory to the way
it looked at some point in the past.</p>
<p>Version control systems give users the ability to save changes to a
branch by &#8220;committing a <strong>revision</strong>&#8221;. The revision created is essentially
a summary of the changes that were made since the last time the tree was
saved.</p>
<p>These revisions have other uses as well. For example, one can comment
revisions to record what the recent set of changes meant by providing an
optional log message. Real life log messages include things like &#8220;Fixed
the web template to close the table&#8221; and &#8220;Added SFTP suppport. Fixes #595&#8221;</p>
<p>We keep these logs so that if later there is some sort of problem with
SFTP, we can figure out when the problem probably happened.</p>
</div>
<div class="section" id="how-dvcs-is-different">
<h2>How DVCS is different<a class="headerlink" href="#how-dvcs-is-different" title="Permalink to this headline">¶</a></h2>
<p>Many Version Control Systems (VCS) are stored on servers. If one wants to
work on the code stored within a VCS, then one needs to connect to the
server and &#8220;checkout&#8221; the code. Doing so gives one a directory in which a
person can make changes and then commit. The VCS client then connects to
the VCS server and stores the changes. This method is known as the
centralized model.</p>
<p>The centralized model can have some drawbacks. A centralized VCS requires
that one is able to connect to the server whenever one wants to do version
control work. This can be a bit of a problem if your server is on some other
machine on the internet and you are not. Or, worse yet, you <strong>are</strong> on the
internet but the server is missing!</p>
<p>Decentralized Version Control Systems (which I&#8217;ll call DVCS after this
point) deal with this problem by keeping branches on the same machine as
the client. In Bazaar&#8217;s case, the branch is kept in the same place as
the code that is being version controlled. This allows the user to save
his changes (<strong>commit</strong>) whenever he wants &#8211; even if he is offline. The
user only needs internet access when he wants to access the changes in
someone else&#8217;s branch that are somewhere else.</p>
<p>A common requirement that many people have is the need to keep track of
the changes for a directory such as file and subdirectory changes.
Performing this tracking by hand is a awkward process that over time
becomes unwieldy. That is, until one considers version control tools such
as Bazaar. These tools automate the process of storing data by creating
a <strong>revision</strong> of the directory tree whenever the user asks.</p>
<p>Version control software such as Bazaar can do much more than just
storage and performing undo.  For example, with Bazaar a developer can
take the modifications in one branch of software and apply them to a
related branch &#8211; even if those changes exist in a branch owned by
somebody else. This allows developers to cooperate without giving
write access to the repository.</p>
<p>Bazaar remembers the &#8216;&#8217;ancestry&#8217;&#8217; 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. By branching, Bazaar allows multiple people to
cooperate on the evolution of a project, without all needing to work in
strict lock-step.  Branching can be useful even for a single developer.</p>
</div>
<div class="section" id="introducing-yourself-to-bazaar">
<h2>Introducing yourself to Bazaar<a class="headerlink" href="#introducing-yourself-to-bazaar" title="Permalink to this headline">¶</a></h2>
<p>Bazaar installs a single new command, <strong>bzr</strong>.  Everything else is a
subcommand of this.  You can get some help with <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">help</span></tt>. Some arguments
are grouped in topics: <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">help</span> <span class="pre">topics</span></tt> to see which topics are available.</p>
<p>One function of a version control system is to keep track of who changed
what.  In a decentralized system, that requires an identifier for each
author that is globally unique.  Most people already have one of these: an
email address. Bazaar is smart enough to automatically generate an email
address by looking up your username and hostname. If you don&#8217;t like the
guess that Bazaar makes, then three options exist:</p>
<ol class="arabic">
<li><p class="first">Set an email address via <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">whoami</span></tt>.  This is the simplest way.</p>
<p>To set a global identity, use:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr whoami &quot;Your Name &lt;email@example.com&gt;&quot;
</pre></div>
</div>
<p>If you&#8217;d like to use a different address for a specific branch, enter
the branch folder and use:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr whoami --branch &quot;Your Name &lt;email@example.com&gt;&quot;
</pre></div>
</div>
</li>
<li><p class="first">Setting the email address in the <tt class="docutils literal"><span class="pre">~/.bazaar/bazaar.conf</span></tt> <a class="footnote-reference" href="#id2" id="id1">[1]</a> by
adding the following lines.  Please note that  <tt class="docutils literal"><span class="pre">[DEFAULT]</span></tt> is case
sensitive:</p>
<div class="highlight-python"><div class="highlight"><pre>[DEFAULT]
email=Your Name &lt;email@isp.com&gt;
</pre></div>
</div>
<p>As above, you can override this settings on a branch by branch basis
by creating a branch section in <tt class="docutils literal"><span class="pre">~/.bazaar/locations.conf</span></tt> and
adding the following lines:</p>
<div class="highlight-python"><div class="highlight"><pre>[/the/path/to/the/branch]
email=Your Name &lt;email@isp.com&gt;
</pre></div>
</div>
</li>
<li><p class="first">Overriding the two previous options by setting the global environment
variable <tt class="docutils literal"><span class="pre">$BZR_EMAIL</span></tt> or <tt class="docutils literal"><span class="pre">$EMAIL</span></tt> (<tt class="docutils literal"><span class="pre">$BZR_EMAIL</span></tt> will take
precedence) to your full email address.</p>
</li>
</ol>
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[1]</td><td><em>(<a class="fn-backref" href="#id1">1</a>, <a class="fn-backref" href="#id5">2</a>)</em> On Windows, the users configuration files can be found in the
application data directory. So instead of <tt class="docutils literal"><span class="pre">~/.bazaar/branch.conf</span></tt>
the configuration file can be found as:
<tt class="docutils literal"><span class="pre">C:\Documents</span> <span class="pre">and</span> <span class="pre">Settings\&lt;username&gt;\Application</span> <span class="pre">Data\Bazaar\2.0\branch.conf</span></tt>.
The same is true for <tt class="docutils literal"><span class="pre">locations.conf</span></tt>, <tt class="docutils literal"><span class="pre">ignore</span></tt>, and the
<tt class="docutils literal"><span class="pre">plugins</span></tt> directory.</td></tr>
</tbody>
</table>
</div>
<div class="section" id="creating-a-branch">
<h2>Creating a branch<a class="headerlink" href="#creating-a-branch" title="Permalink to this headline">¶</a></h2>
<p>History is by default stored in the .bzr directory of the branch. In a
future version of Bazaar, there will be a facility to store it in a
separate repository, which may be remote.</p>
<p>We create a new branch by running <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">init</span></tt> in an existing directory:</p>
<div class="highlight-python"><div class="highlight"><pre>% mkdir tutorial
% cd tutorial
% ls -a
./  ../
% pwd
/home/mbp/work/bzr.test/tutorial
%
% bzr init
% ls -aF
./  ../  .bzr/
%
</pre></div>
</div>
<p>As with CVS, there are three classes of file: unknown, ignored, and
versioned.  The <strong>add</strong> command makes a file versioned: that is, changes
to it will be recorded by the system:</p>
<div class="highlight-python"><div class="highlight"><pre>% echo &#39;hello world&#39; &gt; hello.txt
% bzr status
unknown:
  hello.txt
% bzr add hello.txt
added hello.txt
% bzr status
added:
  hello.txt
</pre></div>
</div>
<p>If you add the wrong file, simply use <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">remove</span></tt> to make it
unversioned again.  This does not delete the working copy in this case,
though it may in others <a class="footnote-reference" href="#id4" id="id3">[2]</a>.</p>
<table class="docutils footnote" frame="void" id="id4" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[2]</td><td><em>(<a class="fn-backref" href="#id3">1</a>, <a class="fn-backref" href="#id6">2</a>)</em> <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">remove</span></tt> will remove the working copy if it is currently
versioned, but has no changes from the last committed version.  You
can force the file to always be kept with the <tt class="docutils literal"><span class="pre">--keep</span></tt> option to
<tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">remove</span></tt>, or force it to always be deleted with <tt class="docutils literal"><span class="pre">--force</span></tt>.</td></tr>
</tbody>
</table>
</div>
<div class="section" id="branch-locations">
<h2>Branch locations<a class="headerlink" href="#branch-locations" title="Permalink to this headline">¶</a></h2>
<p>All history is stored in a branch, which is just an on-disk directory
containing control files.  By default there is no separate repository or
database as used in svn or svk. You can choose to create a repository if
you want to (see the <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">init-repo</span></tt> command). You may wish to do this
if you have very large branches, or many branches of a moderately sized
project.</p>
<p>You&#8217;ll usually refer to branches on your computer&#8217;s filesystem just by
giving the name of the directory containing the branch.  bzr also supports
accessing branches over SSH, HTTP and SFTP, amongst other things:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr log bzr+ssh://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/
% bzr log http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/
% bzr log sftp://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/
</pre></div>
</div>
<p>By installing bzr plugins you can also access branches using the rsync
protocol.</p>
<p>See the <a class="reference internal" href="#publishing-your-branch">Publishing your branch</a> section for more about how to put your
branch at a given location.</p>
</div>
<div class="section" id="reviewing-changes">
<h2>Reviewing changes<a class="headerlink" href="#reviewing-changes" title="Permalink to this headline">¶</a></h2>
<p>Once you have completed some work, you will want to <strong>commit</strong> it to the
version history.  It is good to commit fairly often: whenever you get a
new feature working, fix a bug, or improve some code or documentation.
It&#8217;s also a good practice to make sure that the code compiles and passes
its test suite before committing, to make sure that every revision is a
known-good state.  You can also review your changes, to make sure you&#8217;re
committing what you intend to, and as a chance to rethink your work before
you permanently record it.</p>
<p>Two bzr commands are particularly useful here: <strong>status</strong> and <strong>diff</strong>.</p>
<div class="section" id="bzr-status">
<h3>bzr status<a class="headerlink" href="#bzr-status" title="Permalink to this headline">¶</a></h3>
<p>The <strong>status</strong> command tells you what changes have been made to the
working directory since the last revision:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr status
modified:
   foo
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">status</span></tt> hides &#8220;boring&#8221; files that are either unchanged or ignored.
The status command can optionally be given the name of some files or
directories to check.</p>
</div>
<div class="section" id="bzr-diff">
<h3>bzr diff<a class="headerlink" href="#bzr-diff" title="Permalink to this headline">¶</a></h3>
<p>The <strong>diff</strong> command shows the full text of changes to all files as a
standard unified diff.  This can be piped through many programs such as
&#8216;&#8217;patch&#8217;&#8216;, &#8216;&#8217;diffstat&#8217;&#8216;, &#8216;&#8217;filterdiff&#8217;&#8217; and &#8216;&#8217;colordiff&#8217;&#8216;:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr diff
=== added file &#39;hello.txt&#39;
--- hello.txt   1970-01-01 00:00:00 +0000
+++ hello.txt   2005-10-18 14:23:29 +0000
@@ -0,0 +1,1 @@
+hello world
</pre></div>
</div>
<p>With the <tt class="docutils literal"><span class="pre">-r</span></tt> option, the tree is compared to an earlier revision, or
the differences between two versions are shown:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr diff -r 1000..          # everything since r1000
% bzr diff -r 1000..1100      # changes from 1000 to 1100
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">--diff-options</span></tt> option causes bzr to run the external diff program,
passing options.  For example:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr diff --diff-options --side-by-side foo
</pre></div>
</div>
<p>Some projects prefer patches to show a prefix at the start of the path
for old and new files.  The <tt class="docutils literal"><span class="pre">--prefix</span></tt> option can be used to provide
such a prefix.
As a shortcut, <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">diff</span> <span class="pre">-p1</span></tt> produces a form that works with the
command <tt class="docutils literal"><span class="pre">patch</span> <span class="pre">-p1</span></tt>.</p>
</div>
</div>
<div class="section" id="committing-changes">
<h2>Committing changes<a class="headerlink" href="#committing-changes" title="Permalink to this headline">¶</a></h2>
<p>When the working tree state is satisfactory, it can be <strong>committed</strong> to
the branch, creating a new revision holding a snapshot of that state.</p>
<div class="section" id="bzr-commit">
<h3>bzr commit<a class="headerlink" href="#bzr-commit" title="Permalink to this headline">¶</a></h3>
<p>The <strong>commit</strong> command takes a message describing the changes in the
revision.  It also records your userid, the current time and timezone, and
the inventory and contents of the tree.  The commit message is specified
by the <tt class="docutils literal"><span class="pre">-m</span></tt> or <tt class="docutils literal"><span class="pre">--message</span></tt> option. You can enter a multi-line commit
message; in most shells you can enter this just by leaving the quotes open
at the end of the line.</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit -m &quot;added my first file&quot;
</pre></div>
</div>
<p>You can also use the <tt class="docutils literal"><span class="pre">-F</span></tt> option to take the message from a file.  Some
people like to make notes for a commit message while they work, then
review the diff to make sure they did what they said they did.  (This file
can also be useful when you pick up your work after a break.)</p>
</div>
<div class="section" id="message-from-an-editor">
<h3>Message from an editor<a class="headerlink" href="#message-from-an-editor" title="Permalink to this headline">¶</a></h3>
<p>If you use neither the <tt class="docutils literal"><span class="pre">-m</span></tt> nor the <tt class="docutils literal"><span class="pre">-F</span></tt> option then bzr will open an
editor for you to enter a message.  The editor to run is controlled by
your <tt class="docutils literal"><span class="pre">$VISUAL</span></tt> or <tt class="docutils literal"><span class="pre">$EDITOR</span></tt> environment variable, which can be overridden
by the <tt class="docutils literal"><span class="pre">editor</span></tt> setting in <tt class="docutils literal"><span class="pre">~/.bazaar/bazaar.conf</span></tt>; <tt class="docutils literal"><span class="pre">$BZR_EDITOR</span></tt> will
override either of the above mentioned editor options.  If you quit the
editor without making any changes, the commit will be cancelled.</p>
<p>The file that is opened in the editor contains a horizontal line. The part
of the file below this line is included for information only, and will not
form part of the commit message. Below the separator is shown the list of
files that are changed in the commit. You should write your message above
the line, and then save the file and exit.</p>
<p>If you would like to see the diff that will be committed as you edit the
message you can use the <tt class="docutils literal"><span class="pre">--show-diff</span></tt> option to <tt class="docutils literal"><span class="pre">commit</span></tt>. This will include
the diff in the editor when it is opened, below the separator and the
information about the files that will be committed. This means that you can
read it as you write the message, but the diff itself wont be seen in the
commit message when you have finished. If you would like parts to be
included in the message you can copy and paste them above the separator.</p>
</div>
<div class="section" id="marking-bugs-as-fixed">
<h3>Marking bugs as fixed<a class="headerlink" href="#marking-bugs-as-fixed" title="Permalink to this headline">¶</a></h3>
<p>Many changes to a project are as a result of fixing bugs. Bazaar can keep
metadata about bugs you fixed when you commit them. To do this you use the
<tt class="docutils literal"><span class="pre">--fixes</span></tt> option. This option takes an argument that looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit --fixes &lt;tracker&gt;:&lt;id&gt;
</pre></div>
</div>
<p>Where <tt class="docutils literal"><span class="pre">&lt;tracker&gt;</span></tt> is an identifier for a bug tracker and <tt class="docutils literal"><span class="pre">&lt;id&gt;</span></tt> is an
identifier for a bug that is tracked in that bug tracker. <tt class="docutils literal"><span class="pre">&lt;id&gt;</span></tt> is usually
a number. Bazaar already knows about a few popular bug trackers. They are
bugs.launchpad.net, bugs.debian.org, and bugzilla.gnome.org. These trackers
have their own identifiers: lp, deb, and gnome respectively. For example,
if you made a change to fix the bug #1234 on bugs.launchpad.net, you would
use the following command to commit your fix:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit -m &quot;fixed my first bug&quot; --fixes lp:1234
</pre></div>
</div>
<p>For more information on this topic or for information on how to configure
other bug trackers please read <a class="reference external" href="../user-reference/index.html#bug-tracker-settings">Bug Tracker Settings</a>.</p>
</div>
<div class="section" id="selective-commit">
<h3>Selective commit<a class="headerlink" href="#selective-commit" title="Permalink to this headline">¶</a></h3>
<p>If you give file or directory names on the commit command line then only
the changes to those files will be committed.  For example:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit -m &quot;documentation fix&quot; commit.py
</pre></div>
</div>
<p>By default bzr always commits all changes to the tree, even if run from a
subdirectory.  To commit from only the current directory down, use:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit .
</pre></div>
</div>
</div>
</div>
<div class="section" id="removing-uncommitted-changes">
<h2>Removing uncommitted changes<a class="headerlink" href="#removing-uncommitted-changes" title="Permalink to this headline">¶</a></h2>
<p>If you&#8217;ve made some changes and don&#8217;t want to keep them, use the
<strong>revert</strong> command to go back to the previous head version.  It&#8217;s a good
idea to use <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">diff</span></tt> first to see what will be removed. By default the
revert command reverts the whole tree; if file or directory names are
given then only those ones will be affected. <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">revert</span></tt> also clears the
list of pending merges revisions.</p>
</div>
<div class="section" id="ignoring-files">
<h2>Ignoring files<a class="headerlink" href="#ignoring-files" title="Permalink to this headline">¶</a></h2>
<div class="section" id="the-bzrignore-file">
<h3>The .bzrignore file<a class="headerlink" href="#the-bzrignore-file" title="Permalink to this headline">¶</a></h3>
<p>Many source trees contain some files that do not need to be versioned,
such as editor backups, object or bytecode files, and built programs.  You
can simply not add them, but then they&#8217;ll always crop up as unknown files.
You can also tell bzr to ignore these files by adding them to a file
called <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> at the top of the tree.</p>
<p>This file contains a list of file wildcards (or &#8220;globs&#8221;), one per line.
Typical contents are like this:</p>
<div class="highlight-python"><div class="highlight"><pre>*.o
*~
*.tmp
*.py[co]
</pre></div>
</div>
<p>If a glob contains a slash, it is matched against the whole path from the
top of the tree; otherwise it is matched against only the filename.  So
the previous example ignores files with extension <tt class="docutils literal"><span class="pre">.o</span></tt> in all
subdirectories, but this example ignores only <tt class="docutils literal"><span class="pre">config.h</span></tt> at the top level
and HTML files in <tt class="docutils literal"><span class="pre">doc/</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre>./config.h
doc/*.html
</pre></div>
</div>
<p>To get a list of which files are ignored and what pattern they matched,
use <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">ignored</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr ignored
config.h                 ./config.h
configure.in~            *~
</pre></div>
</div>
<p>It is OK to have either an ignore pattern match a versioned file, or to
add an ignored file.  Ignore patterns have no effect on versioned files;
they only determine whether unversioned files are reported as unknown or
ignored.</p>
<p>The <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file should normally be versioned, so that new copies
of the branch see the same patterns:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr add .bzrignore
% bzr commit -m &quot;Add ignore patterns&quot;
</pre></div>
</div>
</div>
<div class="section" id="bzr-ignore">
<h3>bzr ignore<a class="headerlink" href="#bzr-ignore" title="Permalink to this headline">¶</a></h3>
<p>As an alternative to editing the <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file, you can use the
<tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">ignore</span></tt> command. The <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">ignore</span></tt> command takes filenames and/or
patterns as arguments and then adds them to the <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file. If a
<tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file does not exist the <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">ignore</span></tt> command will
automatically create one for you, and implicitly add it to be versioned:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr ignore tags
% bzr status
added:
  .bzrignore
</pre></div>
</div>
<p>Just like when editing the <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file on your own, you should
commit the automatically created <tt class="docutils literal"><span class="pre">.bzrignore</span></tt> file:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr commit -m &quot;Added tags to ignore file&quot;
</pre></div>
</div>
</div>
<div class="section" id="global-ignores">
<h3>Global ignores<a class="headerlink" href="#global-ignores" title="Permalink to this headline">¶</a></h3>
<p>There are some ignored files which are not project specific, but more user
specific. Things like editor temporary files, or personal temporary files.
Rather than add these ignores to every project, bzr supports a global
ignore file in <tt class="docutils literal"><span class="pre">~/.bazaar/ignore</span></tt> <a class="footnote-reference" href="#id2" id="id5">[1]</a>. It has the same syntax as the
per-project ignore file.</p>
</div>
</div>
<div class="section" id="examining-history">
<h2>Examining history<a class="headerlink" href="#examining-history" title="Permalink to this headline">¶</a></h2>
<div class="section" id="bzr-log">
<h3>bzr log<a class="headerlink" href="#bzr-log" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">log</span></tt> command shows a list of previous revisions. The <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">log</span>
<span class="pre">--forward</span></tt> command does the same in chronological order to get most
recent revisions printed at last.</p>
<p>As with <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">diff</span></tt>, <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">log</span></tt> supports the <tt class="docutils literal"><span class="pre">-r</span></tt> argument:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr log -r 1000..          # Revision 1000 and everything after it
% bzr log -r ..1000          # Everything up to and including r1000
% bzr log -r 1000..1100      # changes from 1000 to 1100
% bzr log -r 1000            # The changes in only revision 1000
</pre></div>
</div>
</div>
</div>
<div class="section" id="branch-statistics">
<h2>Branch statistics<a class="headerlink" href="#branch-statistics" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">info</span></tt> command shows some summary information about the working
tree and the branch history.</p>
</div>
<div class="section" id="versioning-directories">
<h2>Versioning directories<a class="headerlink" href="#versioning-directories" title="Permalink to this headline">¶</a></h2>
<p>bzr versions files and directories in a way that can keep track of renames
and intelligently merge them:</p>
<div class="highlight-python"><div class="highlight"><pre>% mkdir src
% echo &#39;int main() {}&#39; &gt; src/simple.c
% bzr add src
added src
added src/simple.c
% bzr status
added:
  src/
  src/simple.c
</pre></div>
</div>
</div>
<div class="section" id="deleting-and-removing-files">
<h2>Deleting and removing files<a class="headerlink" href="#deleting-and-removing-files" title="Permalink to this headline">¶</a></h2>
<p>You can delete files or directories by just deleting them from the working
directory.  This is a bit different to CVS, which requires that you also
do <tt class="docutils literal"><span class="pre">cvs</span> <span class="pre">remove</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">remove</span></tt> makes the file un-versioned, but may or may not delete the
working copy <a class="footnote-reference" href="#id4" id="id6">[2]</a>.  This is useful when you add the wrong file, or decide that
a file should actually not be versioned.</p>
<div class="highlight-python"><div class="highlight"><pre>% rm -r src
% bzr remove -v hello.txt
?       hello.txt
% bzr status
removed:
  hello.txt
  src/
  src/simple.c
unknown:
  hello.txt
</pre></div>
</div>
<p>If you remove the wrong file by accident, you can use <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">revert</span></tt> to
restore it.</p>
</div>
<div class="section" id="branching">
<h2>Branching<a class="headerlink" href="#branching" title="Permalink to this headline">¶</a></h2>
<p>Often rather than starting your own project, you will want to submit a
change to an existing project.  To do this, you&#8217;ll need to get a copy of
the existing branch.  Because this new copy is potentially a new branch,
the command is called <strong>branch</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr branch lp:bzr bzr.dev
% cd bzr.dev
</pre></div>
</div>
<p>This copies down the complete history of this branch, so we can do all
operations on it locally: log, annotate, making and merging branches.
There will be an option to get only part of the history if you wish.</p>
<p>You can also get a copy of an existing branch by copying its directory,
expanding a tarball, or by a remote copy using something like rsync.</p>
</div>
<div class="section" id="following-upstream-changes">
<h2>Following upstream changes<a class="headerlink" href="#following-upstream-changes" title="Permalink to this headline">¶</a></h2>
<p>You can stay up-to-date with the parent branch by &#8220;pulling&#8221; in their
changes:</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr pull
</pre></div>
</div>
<p>After this change, the local directory will be a mirror of the source. This
includes the &#8216;&#8217;revision-history&#8217;&#8217; - which is a list of the commits done in
this branch, rather than merged from other branches.</p>
<p>This command only works if your local (destination) branch is either an
older copy of the parent branch with no new commits of its own, or if the
most recent commit in your local branch has been merged into the parent
branch.</p>
</div>
<div class="section" id="merging-from-related-branches">
<h2>Merging from related branches<a class="headerlink" href="#merging-from-related-branches" title="Permalink to this headline">¶</a></h2>
<p>If two branches have diverged (both have unique changes) then <tt class="docutils literal"><span class="pre">bzr</span>
<span class="pre">merge</span></tt> is the appropriate command to use. Merge will automatically
calculate the changes that exist in the branch you&#8217;re merging from that
are not in your branch and attempt to apply them in your branch.</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr merge URL
</pre></div>
</div>
<p>If there is a conflict during a merge, 3 files with the same basename
are created. The filename of the common base is appended with &#8221;.BASE&#8221;,
the filename of the file containing your changes is appended with
&#8221;.THIS&#8221; and the filename with the changes from the other tree is
appended with &#8221;.OTHER&#8221;.  Using a program such as kdiff3, you can now
comfortably merge them into one file.  In order to commit you have to
rename the merged file (&#8221;.THIS&#8221;) to the original file name.  To
complete the conflict resolution you must use the resolve command,
which will remove the &#8221;.OTHER&#8221; and &#8221;.BASE&#8221; files.  As long as there
exist files with .BASE, .THIS or .OTHER the commit command will
report an error.</p>
<div class="highlight-python"><div class="highlight"><pre>% kdiff3 file.BASE file.OTHER file.THIS
% mv file.THIS file
% bzr resolve file
</pre></div>
</div>
<p>[<strong>TODO</strong>: explain conflict markers within files]</p>
</div>
<div class="section" id="publishing-your-branch">
<h2>Publishing your branch<a class="headerlink" href="#publishing-your-branch" title="Permalink to this headline">¶</a></h2>
<p>You don&#8217;t need a special server to publish a bzr branch, just a normal web
server.  Just mirror the files to your server, including the .bzr
directory.  One can push a branch (or the changes for a branch) by one of
the following three methods:</p>
<ul>
<li><p class="first">The best method is to use bzr itself to do it.</p>
<div class="highlight-python"><div class="highlight"><pre>% bzr push bzr+ssh://servername.com/path/to/directory
</pre></div>
</div>
<p>(The destination directory must already exist unless the
<tt class="docutils literal"><span class="pre">--create-prefix</span></tt> option is used.)</p>
</li>
<li><p class="first">Another option is the <tt class="docutils literal"><span class="pre">rspush</span></tt> plugin that comes with BzrTools, which
uses rsync to push the changes to the revision history and the working
tree.</p>
</li>
<li><p class="first">You can also copy the files around manually, by sending a tarball, or using
rsync, or other related file transfer methods.  This is usually less safe
than using <tt class="docutils literal"><span class="pre">push</span></tt>, but may be faster or easier in some situations.</p>
</li>
</ul>
</div>
<div class="section" id="moving-changes-between-trees">
<h2>Moving changes between trees<a class="headerlink" href="#moving-changes-between-trees" title="Permalink to this headline">¶</a></h2>
<p>It happens to the best of us: sometimes you&#8217;ll make changes in the wrong
tree.  Maybe because you&#8217;ve accidentally started work in the wrong directory,
maybe because as you&#8217;re working, the change turns out to be bigger than you
expected, so you start a new branch for it.</p>
<p>To move your changes from one tree to another, use</p>
<div class="highlight-python"><div class="highlight"><pre>% cd NEWDIR
% bzr merge --uncommitted OLDDIR
</pre></div>
</div>
<p>This will apply all of the uncommitted changes you made in OLDDIR to NEWDIR.
It will not apply committed changes, even if they could be applied to NEWDIR
with a regular merge.  The changes will remain in OLDDIR, but you can use <tt class="docutils literal"><span class="pre">bzr</span>
<span class="pre">revert</span> <span class="pre">OLDDIR</span></tt> to remove them, once you&#8217;re satisfied with NEWDIR.</p>
<p>NEWDIR does not have to be a copy of OLDDIR, but they should be related.
The more different they are, the greater the chance of conflicts.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Bazaar Tutorial</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#the-purpose-of-version-control">The purpose of version control</a></li>
<li><a class="reference internal" href="#how-dvcs-is-different">How DVCS is different</a></li>
<li><a class="reference internal" href="#introducing-yourself-to-bazaar">Introducing yourself to Bazaar</a></li>
<li><a class="reference internal" href="#creating-a-branch">Creating a branch</a></li>
<li><a class="reference internal" href="#branch-locations">Branch locations</a></li>
<li><a class="reference internal" href="#reviewing-changes">Reviewing changes</a><ul>
<li><a class="reference internal" href="#bzr-status">bzr status</a></li>
<li><a class="reference internal" href="#bzr-diff">bzr diff</a></li>
</ul>
</li>
<li><a class="reference internal" href="#committing-changes">Committing changes</a><ul>
<li><a class="reference internal" href="#bzr-commit">bzr commit</a></li>
<li><a class="reference internal" href="#message-from-an-editor">Message from an editor</a></li>
<li><a class="reference internal" href="#marking-bugs-as-fixed">Marking bugs as fixed</a></li>
<li><a class="reference internal" href="#selective-commit">Selective commit</a></li>
</ul>
</li>
<li><a class="reference internal" href="#removing-uncommitted-changes">Removing uncommitted changes</a></li>
<li><a class="reference internal" href="#ignoring-files">Ignoring files</a><ul>
<li><a class="reference internal" href="#the-bzrignore-file">The .bzrignore file</a></li>
<li><a class="reference internal" href="#bzr-ignore">bzr ignore</a></li>
<li><a class="reference internal" href="#global-ignores">Global ignores</a></li>
</ul>
</li>
<li><a class="reference internal" href="#examining-history">Examining history</a><ul>
<li><a class="reference internal" href="#bzr-log">bzr log</a></li>
</ul>
</li>
<li><a class="reference internal" href="#branch-statistics">Branch statistics</a></li>
<li><a class="reference internal" href="#versioning-directories">Versioning directories</a></li>
<li><a class="reference internal" href="#deleting-and-removing-files">Deleting and removing files</a></li>
<li><a class="reference internal" href="#branching">Branching</a></li>
<li><a class="reference internal" href="#following-upstream-changes">Following upstream changes</a></li>
<li><a class="reference internal" href="#merging-from-related-branches">Merging from related branches</a></li>
<li><a class="reference internal" href="#publishing-your-branch">Publishing your branch</a></li>
<li><a class="reference internal" href="#moving-changes-between-trees">Moving changes between trees</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="../mini-tutorial/index.html"
                        title="previous chapter">Bazaar in five minutes</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="using_bazaar_with_launchpad.html"
                        title="next chapter">Using Bazaar with Launchpad</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/tutorials/tutorial.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="using_bazaar_with_launchpad.html" title="Using Bazaar with Launchpad"
             >next</a></li>
        <li class="right" >
          <a href="../mini-tutorial/index.html" title="Bazaar in five minutes"
             >previous</a> |</li>
<li><a href="http://bazaar.canonical.com/">
    <img src="../_static/bzr icon 16.png" /> Home</a>&nbsp;|&nbsp;</li>
<a href="http://doc.bazaar.canonical.com/en/">Documentation</a>&nbsp;|&nbsp;</li>

        <li><a href="../index.html">Table of Contents (2.6.0)</a> &raquo;</li>

          <li><a href="index.html" >Tutorials</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2011 Canonical Ltd.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
    </div>
  </body>
</html>