hgbook

view en/tour.tex @ 88:d351032c189c

Progress with log coverage.
author Bryan O'Sullivan <bos@serpentine.com>
date Thu Oct 12 10:33:03 2006 -0700 (2006-10-12)
parents 0995016342f8
children 7524d52d9577
line source
1 \chapter{A lightning tour of Mercurial}
2 \label{chap:tour}
4 \section{Installing Mercurial on your system}
5 \label{sec:tour:install}
7 Prebuilt binary packages of Mercurial are available for every popular
8 operating system. These make it easy to start using Mercurial on your
9 computer immediately.
11 \subsection{Linux}
13 Because each Linux distribution has its own packaging tools, policies,
14 and rate of development, it's difficult to give a comprehensive set of
15 instructions on how to install Mercurial binaries. The version of
16 Mercurial that you will end up with can vary depending on how active
17 the person is who maintains the package for your distribution.
19 To keep things simple, I will focus on installing Mercurial from the
20 command line under the most popular Linux distributions. Most of
21 these distributions provide graphical package managers that will let
22 you install Mercurial with a single click; the package name to look
23 for is \texttt{mercurial}.
25 \begin{itemize}
26 \item[Debian]
27 \begin{codesample4}
28 apt-get install mercurial
29 \end{codesample4}
31 \item[Fedora Core]
32 \begin{codesample4}
33 yum install mercurial
34 \end{codesample4}
36 \item[Gentoo]
37 \begin{codesample4}
38 emerge mercurial
39 \end{codesample4}
41 \item[OpenSUSE]
42 \begin{codesample4}
43 yum install mercurial
44 \end{codesample4}
46 \item[Ubuntu] Ubuntu's Mercurial package is particularly old, and you
47 should not use it. If you know how, you can rebuild and install the
48 Debian package. It's probably easier to build Mercurial from source
49 and simply run that; see section~\ref{sec:srcinstall:unixlike} for
50 details.
51 \end{itemize}
53 \subsection{Mac OS X}
55 Lee Cantey publishes an installer of Mercurial for Mac OS~X at
56 \url{http://mercurial.berkwood.com}. This package works on both
57 Intel-~and Power-based Macs. Before you can use it, you must install
58 a compatible version of Universal MacPython~\cite{web:macpython}. This
59 is easy to do; simply follow the instructions on Lee's site.
61 \subsection{Solaris}
63 XXX.
65 \subsection{Windows}
67 Lee Cantey publishes an installer of Mercurial for Windows at
68 \url{http://mercurial.berkwood.com}. This package has no external
69 dependencies; it ``just works''.
71 \begin{note}
72 The Windows version of Mercurial does not automatically convert line
73 endings between Windows and Unix styles. If you want to share work
74 with Unix users, you must do a little additional configuration
75 work. XXX Flesh this out.
76 \end{note}
78 \section{Getting started}
80 To begin, we'll use the \hgcmd{version} command to find out whether
81 Mercurial is actually installed properly. The actual version
82 information that it prints isn't so important; it's whether it prints
83 anything at all that we care about.
84 \interaction{tour.version}
86 \subsection{Built-in help}
88 Mercurial provides a built-in help system. This invaluable for those
89 times when you find yourself stuck trying to remember how to run a
90 command. If you are completely stuck, simply run \hgcmd{help}; it
91 will print a brief list of commands, along with a description of what
92 each does. If you ask for help on a specific command (as below), it
93 prints more detailed information.
94 \interaction{tour.help}
95 For a more impressive level of detail (which you won't usually need)
96 run \hgcmdargs{help}{\hggopt{-v}}. The \hggopt{-v} option is short
97 for \hggopt{--verbose}, and tells Mercurial to print more information
98 than it usually would.
100 \section{Working with a repository}
102 In Mercurial, everything happens inside a \emph{repository}. The
103 repository for a project contains all of the files that ``belong to''
104 that project, along with a historical record of the project's files.
106 There's nothing particularly magical about a repository; it is simply
107 a directory tree in your filesystem that Mercurial treats as special.
108 You can rename delete a repository any time you like, using either the
109 command line or your file browser.
111 \subsection{Making a local copy of a repository}
113 \emph{Copying} a repository is just a little bit special. While you
114 could use a normal file copying command to make a copy of a
115 repository, it's best to use a built-in command that Mercurial
116 provides. This command is called \hgcmd{clone}, because it creates an
117 identical copy of an existing repository.
118 \interaction{tour.clone}
119 If our clone succeeded, we should now have a local directory called
120 \dirname{hello}. This directory will contain some files.
121 \interaction{tour.ls}
122 These files have the same contents and history in our repository as
123 they do in the repository we cloned.
125 Every Mercurial repository is complete, self-contained, and
126 independent. It contains its own private copy of a project's files
127 and history. A cloned repository remembers the location of the
128 repository it was cloned from, but it does not communicate with that
129 repository, or any other, unless you tell it to.
131 What this means for now is that we're free to experiment with our
132 repository, safe in the knowledge that it's a private ``sandbox'' that
133 won't affect anyone else.
135 \subsection{What's in a repository?}
137 When we take a more detailed look inside a repository, we can see that
138 it contains a directory named \dirname{.hg}. This is where Mercurial
139 keeps all of its metadata for the repository.
140 \interaction{tour.ls-a}
142 The contents of the \dirname{.hg} directory and its subdirectories are
143 private to Mercurial. Every other file and directory in the
144 repository is yours to do with as you please.
146 To introduce a little terminology, the \dirname{.hg} directory is the
147 ``real'' repository, and all of the files and directories that coexist
148 with it are said to live in the ``working directory''. An easy way to
149 remember the distinction is that the \emph{repository} contains the
150 \emph{history} of your project, while the \emph{working directory}
151 contains a \emph{snapshot} of your project at a particular point in
152 history.
154 \section{A tour through history}
156 One of the first things we might want to do with a new, unfamiliar
157 repository is understand its history. The \hgcmd{log} command gives
158 us a view of history.
159 \interaction{tour.log}
160 By default, this command prints a brief paragraph of output for each
161 change to the project that was recorded. In Mercurial terminology, we
162 call each of these recorded events a \emph{changeset}, because it can
163 contain a record of changes to several files.
165 The fields in a record of output from \hgcmd{log} are as follows.
166 \begin{itemize}
167 \item[\texttt{changeset}] This field has the format of a number,
168 followed by a colon, followed by a hexadecimal string. These are
169 \emph{identifiers} for the changeset. There are two identifiers
170 because the number is shorter and easier to type than the hex
171 string.
172 \item[\texttt{user}] The identity of the person who created the
173 changeset. This is a free-form field, but it most often contains a
174 person's name and email address.
175 \item[\texttt{date}] The date and time on which the changeset was
176 created, and the timezone in which it was created. (Thef date and
177 time are local to that timezone; they display what time and date it
178 was for the person who created the changeset.)
179 \item[\texttt{summary}] The first line of the text message that the
180 creator of the changeset entered to describe the changeset.
181 \end{itemize}
182 The default output printed by \hgcmd{log} is purely a summary; it is
183 missing a lot of detail.
185 \subsection{Changesets, revisions, and identification}
187 English being a notoriously sloppy language, we have a variety of
188 terms that have the same meaning. If you are talking about Mercurial
189 history with other people, you will find that the word ``changeset''
190 is often compressed to ``change'' or ``cset'', and sometimes a
191 changeset is referred to as a ``revision'' or a ``rev''.
193 While it doesn't matter what \emph{word} you use to refer to the
194 concept of ``a~changeset'', the \emph{identifier} that you use to
195 refer to ``a~\emph{specific} changeset'' is of great importance.
196 Recall that the \texttt{changeset} field in the output from
197 \hgcmd{log} identifies a changeset using both a number and a
198 hexadecimal string. The number is \emph{only valid in that
199 repository}, while the hex string is the \emph{permanent, unchanging
200 identifier} that will always identify that changeset in every copy
201 of the repository.
203 This distinction is important. If you send someone an email talking
204 about ``revision~33'', there's a high likelihood that their
205 revision~33 will \emph{not be the same} as yours. The reason for this
206 is that a revision number depends on the order in which changes
207 arrived in a repository, and there is no guarantee that the same
208 changes will happen in the same order in different repositories.
209 Three changes $a,b,c$ can easily appear in one repository as $0,1,2$,
210 while in another as $1,0,2$.
212 Mercurial uses revision numbers purely as a convenient shorthand. If
213 you need to discuss a changeset with someone, or make a record of a
214 changeset for some other reason (for example, in a bug report), use
215 the hexadecimal identifier.
217 \subsection{Viewing specific revisions}
219 To narrow the output of \hgcmd{log} down to a single revision, use the
220 \hgopt{log}{-r} option. You can use either a revision number or a
221 long-form changeset identifier, and you can provide as many revisions
222 as you want.
223 \interaction{tour.log-r}
225 If you want to see the history of several revisions without having to
226 list each one, you can use \emph{range notation}; this lets you
227 express the idea ``I want all revisions between $a$ and $b$,
228 inclusive''.
229 \interaction{tour.log.range}
230 Mercurial also honours the order in which you specify revisions, so
231 \hgcmdargs{log}{-r 2:4} prints $2,3,4$ while \hgcmdargs{log}{-r 4:2}
232 prints $4,3,2$.
234 %%% Local Variables:
235 %%% mode: latex
236 %%% TeX-master: "00book"
237 %%% End: