hgbook

view fr/tour-basic.tex @ 938:651aa8fd9882

Work in progress in tour-basic
author Romain PELISSE <belaran@gmail.com>
date Mon Feb 16 10:42:23 2009 +0100 (2009-02-16)
parents 9968b0ed4a38
children 99b93caf2db2
line source
1 \chapter{Un rapide tour de Mercurial}
2 \label{chap:tour-basic}
4 \section{Installer Mercurial sur votre système}
5 \label{sec:tour:install}
7 Des paquetages binaires de Mercurial sont disponible pour tous les plupart
8 des systèmes d'exploitation, ce qui rend facile de commencer de suite
9 à utiliser Mercurial sur votre ordinateur.
11 \subsection{Linux}
13 Parce que chaque distribution de Linux a ses propres outils de gestion
14 de paquets, politique et rythme de développements, il est difficile de
15 donner un ensemble instructions fixes pour installer les binaires de
16 Mercurial. La version de Mercurial avec laquelle vous vous retrouverez
17 dépendera grandement selon l'activité de la personne en charge du paquetage
18 pour la distribution.
20 Pour rester simple, je me concentrerais sur l'installation de Mercurial
21 en ligne de commande, sous les plus courantes des distributions. La
22 plupart des distributions fournissent des gestionnaires graphiques de
23 paquetage qui vous permettront d'installer Mercurial en quelques clicks.
24 Le paquetage devrait se nommer \textit{mercurial}.
26 \begin{itemize}
27 \item[Debian]
28 \begin{codesample4}
29 apt-get install mercurial
30 \end{codesample4}
32 \item[Fedora Core]
33 \begin{codesample4}
34 yum install mercurial
35 \end{codesample4}
37 \item[Gentoo]
38 \begin{codesample4}
39 emerge mercurial
40 \end{codesample4}
42 \item[OpenSUSE]
43 \begin{codesample4}
44 yum install mercurial
45 \end{codesample4}
47 \item[Ubuntu] Le paquetage de Mercurial d'Ubuntu est construit sur celui de Debian. Pour
48 l'installer, exécute simplement les commandes suivantes:
49 \begin{codesample4}
50 apt-get install mercurial
51 \end{codesample4}
52 Les paquetages Ubuntu pour Mercurial ont tendance à être un peu en retard
53 par rapport au paquetage Debian (au moment de l'écriture de ce livre, un
54 peu près 7 mois), ce qui signifie que parfois sur Ubuntu, vous risquez
55 de rencontrer des problèmes qui ont été corrigés depuis longtemps dans
56 les paquetages Debian.
57 \end{itemize}
59 \subsection{Solaris}
61 SunFreeWare, à \url{http://www.saufreeware.com}, est une bonne source
62 pour trouver un vaste nombre de paquet précompiler pour 32 ou 64 bits
63 Intel et les architecture Sparc, dont les versions courantes de Mercurial.
65 \subsection{Mac OS X}
67 Lee Cantey publie un installeur de Mercurial pour Mac OS~X sur le site
68 \url{http://mercurial.berkwood.com}. Ce paquetage fonctionne sur les
69 architecture Intel-~et PowerPCC. Avant de vous en servir, vous devez
70 installer une version Universel MacPython~\cite{web:macpython}. C'est
71 assez facile à faire : suivez simplement les instructions sur le site
72 de Lee.
74 Il est aussi possible d'installer Mercurial en utilisant Fink ou MacPorts,
75 deux outils de gestion de paquetage libre pour Mac OS X. Si vous avez
76 Fink, utiliser \command{sudo fink install mercurial-py25}. Si vous avez
77 acPorts, \command{sudo port install mercurial}.
79 \subsection{Windows}
81 Lee Cantey publie aussi un installeur de Mercurial pour Windows sur le site
82 \url{http://mercurial.berkwood.com}. Ce paquetage n'a aucune dépendance
83 externe, il fonctionne ``tout court''.
85 \begin{note}
86 Le version de Windows de Mercurial ne convertie pas automatiquement
87 les retour chariot Windows et Unix. Si vous désirez partager votre
88 travail avec des utilisateurs Unix, vous devez faire un peu de configuration
89 supllémentaire. XXX En dire plus.
90 \end{note}
92 \section{Commencer à utiliser Mercurial}
94 Pour commencer, nous utiliserons la commande \hgcmd{version} pour vérifier
95 si Mercurial est installé proprement. Les informations affichées sur la
96 version ne sont pas réellement importante en soit, c'est surtout de savoir
97 si elles s'affichent qui nous intéresse.
98 \interaction{tour.version}
100 \subsection{L'aide intégrée}
102 Mercurial fournit un système d'aide intégré, ce qui est inestimable quand
103 vous vous retrouvez coincé à essayer de vous rappeler comment lancer telle
104 ou telle commande.
105 Si c'est le cas, exécuter simplement \hgcmd{help}; il vous aidera à imprimer
106 une brève liste de commandes, avec une description de ce qu'elle fait. Si vous
107 demandez de l'aide sur une commande spécifique (voir ci dessous), il affichera
108 des informations plus détaillés.
109 \interaction{tour.help}
110 Pour un niveau d'informations encore plus détaillé (ce dont vous aurez rarement
111 besoins), exécuter \hgcmdargs{help}{\hggopt{-v}}. L'option \hggopt{-v} est
112 l'abréviation de \hggopt{--verbose}, et indique à Mercurial d'afficher plus
113 d'information que d'habitude.
115 \section{Travailler avec un dépot}
117 Avec Mercurial, tout se déroule au sein du \emph{dépot}\footnote{NdT: Dépôt est
118 la traduction que j'ai retenu pour tout l'ouvrage du terme anglais \textit{repository}}.
119 Le dépôt d'une projet contient tout les fichiers qui ``appartiennent''
120 au projet, avec l'historique des fichiers du projet.
122 Il n'y a rien de particulièrement magique au sujet de ce dépot, c'est
123 simplement une arboresence sur votre système de fichiers que Mercurial
124 traite de manière spéciale. Si vous pouvez renommer ou effacer ce répertoire
125 à n'importe quel moment, en utilisant la ligne de commande ou votre
126 explorateur de fichiers.
128 \subsection{Faire une copie locale de votre dépot}
130 \emph{Copier} un dépôt est just un peu spécial. Bien que vous
131 puissiez utiliser une commande habituelle de copie pour copier
132 votre dépôt, il vaut mieux utiliser une commande fournie par
133 Mercurial. Cette commande est appelée \hgcmd{clone}, car elle
134 crée une copie identique d'un dépôt existant.
135 \interaction{tour.clone}
136 Si votre opération de clonage réussit, vous devriez maintenant
137 avoir un répertoire local appelé \dirname{hello}. Ce répertoire
138 contiendra quelques fichiers.
139 \interaction{tour.ls}
140 Ces fichiers ont le même contenu et historique dans votre dépôt
141 qu'ils ont dans le dépôt que vous avez cloné.
143 Chaque dépôt Mercurial est complet, autonome et indépendant. Il
144 contient sa propre copie privé des fichiers du projet et de leurs
145 historiques. Le clone d'un dépôt se souvient de la localisation du
146 dépôt à partir duquel il a été clôné, mais il ne communique pas avec
147 ce dernier, ou un autre, à moins que vous ne lui demandiez.
149 Ce que tout ceci signifie pour le moment est que nous sommes libre
150 d'expérimenter avec ce dépôt, confiant dans le fait qu'il s'agit d'un
151 ``bac à sable'' qui n'affectera personne d'autres.
153 \subsection{Quel est le contenu d'un dépôt ?}
155 Prêtons plus attention un instant au contenu d'un dépôt. Nous voyons
156 qu'il contient un répertoire nommée \dirname{.hg}. C'est ici que Mercurial
157 conserve toutes ses métadonnées.
158 \interaction{tour.ls-a}
160 Le contenu du répertoire \dirname{.hg} et ses sous répertoires sont les
161 seules propre à Mercurial. Tout les autres fichiers et répertoire dans
162 le répertoire sont à vous, et vous pouvez faire ce que vous en voulez.
164 Pour introduire un peu de terminologie, le répertoire \dirname{.hg} est
165 un ``vrai'' dépôt, et tout les fichiers et les répertoires qui coexistent
166 avec lui, sont désigné sous le nom de \emph{espace de travail}\footnote{NdT:
167 \textit{working directory}}. Une manière facile de se rappeler cette
168 distinction est de retenir que le \emph{dépôt} contient l'\emph{historique}
169 de votre projet, alors que l'\emph{espace de travail} contient une \emph{copie
170 précise}\footnote{NdT: Ce terme est une traduction du terme anglais
171 \textit{snapshot}. Il est traduit ici pour faciliter la lecture, mais ne sera
172 plus traduit par la suite.} de votre projet à un certain point de son
173 historique.
175 \section{Une ballade dans l'historique}
177 Une des premières choses que vous aurez envie de faire avec un nouveau
178 dépôt, sera de comprendre son historique. La commande \hgcmd{log} vous
179 donne une vue de l'historique.
180 \interaction{tour.log}
181 Par défaut, cette commande affiche à l'écran un bref paragraphe pour chaque
182 révision enregistrée pour ce projet. Dans la terminologie de Mercurial, nous
183 appelons chacun de ces évènements enregistrés un \emph{changeset}, parce
184 qu'il contient un ensemble de mofications sur plusieurs fichiers.
186 La commande \hgcmd{log} affiche ainsi ces informations:
187 \begin{itemize}
188 \item[\texttt{changeset}] Ce champ contient un nombre, séparé par une
189 virgule, d'une chaine hexadécimal. Il s'agit en effet d'\emph{identifiants}
190 pour un \textit{changeset}. Il y a deux identifiants car le numéro de
191 la révision est plus court et plus à facile à saisir qu'une séquence
192 hexadécimale.
193 \item[\texttt{utilisateur}] L'identité de la personne qui a crée ce
194 \textit{changeset}. C'est un champ libre de forme, mais la plupart du
195 temps il contient le nom et l'email de la personne.
196 \item[\texttt{date}] La date et l'heure à laquelle le \textit{changeset}
197 a été crée, ainsi que le \textit{timezone} dans laquelle il a été crée. %%%TODO: Translate 'timezone' properly
198 (La date et l'heure sont locals à cette \textit{timezone}, ils indiquent
199 donc quelle date et quelle il était pour la personne qui a crée ce
200 \textit{changeset}.)
201 \item[\texttt{résumé}] La première du message que le créateur a associée à
202 son \textit{changeset} pour le décrire.
203 \end{itemize}
205 Par défaut, la commande \hgcmd{log} n'affiche qu'un résumé, il manque
206 beaucoup de détails.
209 La figure~\ref{fig:tour-basic:history} fournit un représentation graphique
210 de l'historique du dépôt \dirname{hello}, pour rendre plus facile de voir
211 dans quelle direction l'historique se ``déroule''\footnote{NdT: \textit{flowing in}.}.
212 Nous reviendrons régulièrement à cette représentation dans ce chapitre et
213 ceux qui suivent.
215 \begin{figure}[ht]
216 \centering
217 \grafix{tour-history}
218 \caption{Représentation graphique du dépôt \dirname{hello} }
219 \label{fig:tour-basic:history}
220 \end{figure}
222 \subsection{Changesets, révisions, et discuter avec les autres}
224 As English is a notoriously sloppy language, and computer science has
225 a hallowed history of terminological confusion (why use one term when
226 four will do?), revision control has a variety of words and phrases
227 that mean the same thing. If you are talking about Mercurial history
228 with other people, you will find that the word ``changeset'' is often
229 compressed to ``change'' or (when written) ``cset'', and sometimes a
230 changeset is referred to as a ``revision'' or a ``rev''.
232 While it doesn't matter what \emph{word} you use to refer to the
233 concept of ``a~changeset'', the \emph{identifier} that you use to
234 refer to ``a~\emph{specific} changeset'' is of great importance.
235 Recall that the \texttt{changeset} field in the output from
236 \hgcmd{log} identifies a changeset using both a number and a
237 hexadecimal string.
238 \begin{itemize}
239 \item The revision number is \emph{only valid in that repository},
240 \item while the hex string is the \emph{permanent, unchanging
241 identifier} that will always identify that exact changeset in
242 \emph{every} copy of the repository.
243 \end{itemize}
244 This distinction is important. If you send someone an email talking
245 about ``revision~33'', there's a high likelihood that their
246 revision~33 will \emph{not be the same} as yours. The reason for this
247 is that a revision number depends on the order in which changes
248 arrived in a repository, and there is no guarantee that the same
249 changes will happen in the same order in different repositories.
250 Three changes $a,b,c$ can easily appear in one repository as $0,1,2$,
251 while in another as $1,0,2$.
253 Mercurial uses revision numbers purely as a convenient shorthand. If
254 you need to discuss a changeset with someone, or make a record of a
255 changeset for some other reason (for example, in a bug report), use
256 the hexadecimal identifier.
258 \subsection{Viewing specific revisions}
260 To narrow the output of \hgcmd{log} down to a single revision, use the
261 \hgopt{log}{-r} (or \hgopt{log}{--rev}) option. You can use either a
262 revision number or a long-form changeset identifier, and you can
263 provide as many revisions as you want. \interaction{tour.log-r}
265 If you want to see the history of several revisions without having to
266 list each one, you can use \emph{range notation}; this lets you
267 express the idea ``I want all revisions between $a$ and $b$,
268 inclusive''.
269 \interaction{tour.log.range}
270 Mercurial also honours the order in which you specify revisions, so
271 \hgcmdargs{log}{-r 2:4} prints $2,3,4$ while \hgcmdargs{log}{-r 4:2}
272 prints $4,3,2$.
274 \subsection{More detailed information}
276 While the summary information printed by \hgcmd{log} is useful if you
277 already know what you're looking for, you may need to see a complete
278 description of the change, or a list of the files changed, if you're
279 trying to decide whether a changeset is the one you're looking for.
280 The \hgcmd{log} command's \hggopt{-v} (or \hggopt{--verbose})
281 option gives you this extra detail.
282 \interaction{tour.log-v}
284 If you want to see both the description and content of a change, add
285 the \hgopt{log}{-p} (or \hgopt{log}{--patch}) option. This displays
286 the content of a change as a \emph{unified diff} (if you've never seen
287 a unified diff before, see section~\ref{sec:mq:patch} for an overview).
288 \interaction{tour.log-vp}
290 \section{All about command options}
292 Let's take a brief break from exploring Mercurial commands to discuss
293 a pattern in the way that they work; you may find this useful to keep
294 in mind as we continue our tour.
296 Mercurial has a consistent and straightforward approach to dealing
297 with the options that you can pass to commands. It follows the
298 conventions for options that are common to modern Linux and Unix
299 systems.
300 \begin{itemize}
301 \item Every option has a long name. For example, as we've already
302 seen, the \hgcmd{log} command accepts a \hgopt{log}{--rev} option.
303 \item Most options have short names, too. Instead of
304 \hgopt{log}{--rev}, we can use \hgopt{log}{-r}. (The reason that
305 some options don't have short names is that the options in question
306 are rarely used.)
307 \item Long options start with two dashes (e.g.~\hgopt{log}{--rev}),
308 while short options start with one (e.g.~\hgopt{log}{-r}).
309 \item Option naming and usage is consistent across commands. For
310 example, every command that lets you specify a changeset~ID or
311 revision number accepts both \hgopt{log}{-r} and \hgopt{log}{--rev}
312 arguments.
313 \end{itemize}
314 In the examples throughout this book, I use short options instead of
315 long. This just reflects my own preference, so don't read anything
316 significant into it.
318 Most commands that print output of some kind will print more output
319 when passed a \hggopt{-v} (or \hggopt{--verbose}) option, and less
320 when passed \hggopt{-q} (or \hggopt{--quiet}).
322 \section{Making and reviewing changes}
324 Now that we have a grasp of viewing history in Mercurial, let's take a
325 look at making some changes and examining them.
327 The first thing we'll do is isolate our experiment in a repository of
328 its own. We use the \hgcmd{clone} command, but we don't need to
329 clone a copy of the remote repository. Since we already have a copy
330 of it locally, we can just clone that instead. This is much faster
331 than cloning over the network, and cloning a local repository uses
332 less disk space in most cases, too.
333 \interaction{tour.reclone}
334 As an aside, it's often good practice to keep a ``pristine'' copy of a
335 remote repository around, which you can then make temporary clones of
336 to create sandboxes for each task you want to work on. This lets you
337 work on multiple tasks in parallel, each isolated from the others
338 until it's complete and you're ready to integrate it back. Because
339 local clones are so cheap, there's almost no overhead to cloning and
340 destroying repositories whenever you want.
342 In our \dirname{my-hello} repository, we have a file
343 \filename{hello.c} that contains the classic ``hello, world'' program.
344 Let's use the ancient and venerable \command{sed} command to edit this
345 file so that it prints a second line of output. (I'm only using
346 \command{sed} to do this because it's easy to write a scripted example
347 this way. Since you're not under the same constraint, you probably
348 won't want to use \command{sed}; simply use your preferred text editor to
349 do the same thing.)
350 \interaction{tour.sed}
352 Mercurial's \hgcmd{status} command will tell us what Mercurial knows
353 about the files in the repository.
354 \interaction{tour.status}
355 The \hgcmd{status} command prints no output for some files, but a line
356 starting with ``\texttt{M}'' for \filename{hello.c}. Unless you tell
357 it to, \hgcmd{status} will not print any output for files that have
358 not been modified.
360 The ``\texttt{M}'' indicates that Mercurial has noticed that we
361 modified \filename{hello.c}. We didn't need to \emph{inform}
362 Mercurial that we were going to modify the file before we started, or
363 that we had modified the file after we were done; it was able to
364 figure this out itself.
366 It's a little bit helpful to know that we've modified
367 \filename{hello.c}, but we might prefer to know exactly \emph{what}
368 changes we've made to it. To do this, we use the \hgcmd{diff}
369 command.
370 \interaction{tour.diff}
372 \section{Recording changes in a new changeset}
374 We can modify files, build and test our changes, and use
375 \hgcmd{status} and \hgcmd{diff} to review our changes, until we're
376 satisfied with what we've done and arrive at a natural stopping point
377 where we want to record our work in a new changeset.
379 The \hgcmd{commit} command lets us create a new changeset; we'll
380 usually refer to this as ``making a commit'' or ``committing''.
382 \subsection{Setting up a username}
384 When you try to run \hgcmd{commit} for the first time, it is not
385 guaranteed to succeed. Mercurial records your name and address with
386 each change that you commit, so that you and others will later be able
387 to tell who made each change. Mercurial tries to automatically figure
388 out a sensible username to commit the change with. It will attempt
389 each of the following methods, in order:
390 \begin{enumerate}
391 \item If you specify a \hgopt{commit}{-u} option to the \hgcmd{commit}
392 command on the command line, followed by a username, this is always
393 given the highest precedence.
394 \item If you have set the \envar{HGUSER} environment variable, this is
395 checked next.
396 \item If you create a file in your home directory called
397 \sfilename{.hgrc}, with a \rcitem{ui}{username} entry, that will be
398 used next. To see what the contents of this file should look like,
399 refer to section~\ref{sec:tour-basic:username} below.
400 \item If you have set the \envar{EMAIL} environment variable, this
401 will be used next.
402 \item Mercurial will query your system to find out your local user
403 name and host name, and construct a username from these components.
404 Since this often results in a username that is not very useful, it
405 will print a warning if it has to do this.
406 \end{enumerate}
407 If all of these mechanisms fail, Mercurial will fail, printing an
408 error message. In this case, it will not let you commit until you set
409 up a username.
411 You should think of the \envar{HGUSER} environment variable and the
412 \hgopt{commit}{-u} option to the \hgcmd{commit} command as ways to
413 \emph{override} Mercurial's default selection of username. For normal
414 use, the simplest and most robust way to set a username for yourself
415 is by creating a \sfilename{.hgrc} file; see below for details.
417 \subsubsection{Creating a Mercurial configuration file}
418 \label{sec:tour-basic:username}
420 To set a user name, use your favourite editor to create a file called
421 \sfilename{.hgrc} in your home directory. Mercurial will use this
422 file to look up your personalised configuration settings. The initial
423 contents of your \sfilename{.hgrc} should look like this.
424 \begin{codesample2}
425 # This is a Mercurial configuration file.
426 [ui]
427 username = Firstname Lastname <email.address@domain.net>
428 \end{codesample2}
429 The ``\texttt{[ui]}'' line begins a \emph{section} of the config file,
430 so you can read the ``\texttt{username = ...}'' line as meaning ``set
431 the value of the \texttt{username} item in the \texttt{ui} section''.
432 A section continues until a new section begins, or the end of the
433 file. Mercurial ignores empty lines and treats any text from
434 ``\texttt{\#}'' to the end of a line as a comment.
436 \subsubsection{Choosing a user name}
438 You can use any text you like as the value of the \texttt{username}
439 config item, since this information is for reading by other people,
440 but for interpreting by Mercurial. The convention that most people
441 follow is to use their name and email address, as in the example
442 above.
444 \begin{note}
445 Mercurial's built-in web server obfuscates email addresses, to make
446 it more difficult for the email harvesting tools that spammers use.
447 This reduces the likelihood that you'll start receiving more junk
448 email if you publish a Mercurial repository on the web.
449 \end{note}
451 \subsection{Writing a commit message}
453 When we commit a change, Mercurial drops us into a text editor, to
454 enter a message that will describe the modifications we've made in
455 this changeset. This is called the \emph{commit message}. It will be
456 a record for readers of what we did and why, and it will be printed by
457 \hgcmd{log} after we've finished committing.
458 \interaction{tour.commit}
460 The editor that the \hgcmd{commit} command drops us into will contain
461 an empty line, followed by a number of lines starting with
462 ``\texttt{HG:}''.
463 \begin{codesample2}
464 \emph{empty line}
465 HG: changed hello.c
466 \end{codesample2}
467 Mercurial ignores the lines that start with ``\texttt{HG:}''; it uses
468 them only to tell us which files it's recording changes to. Modifying
469 or deleting these lines has no effect.
471 \subsection{Writing a good commit message}
473 Since \hgcmd{log} only prints the first line of a commit message by
474 default, it's best to write a commit message whose first line stands
475 alone. Here's a real example of a commit message that \emph{doesn't}
476 follow this guideline, and hence has a summary that is not readable.
477 \begin{codesample2}
478 changeset: 73:584af0e231be
479 user: Censored Person <censored.person@example.org>
480 date: Tue Sep 26 21:37:07 2006 -0700
481 summary: include buildmeister/commondefs. Add an exports and install
482 \end{codesample2}
484 As far as the remainder of the contents of the commit message are
485 concerned, there are no hard-and-fast rules. Mercurial itself doesn't
486 interpret or care about the contents of the commit message, though
487 your project may have policies that dictate a certain kind of
488 formatting.
490 My personal preference is for short, but informative, commit messages
491 that tell me something that I can't figure out with a quick glance at
492 the output of \hgcmdargs{log}{--patch}.
494 \subsection{Aborting a commit}
496 If you decide that you don't want to commit while in the middle of
497 editing a commit message, simply exit from your editor without saving
498 the file that it's editing. This will cause nothing to happen to
499 either the repository or the working directory.
501 If we run the \hgcmd{commit} command without any arguments, it records
502 all of the changes we've made, as reported by \hgcmd{status} and
503 \hgcmd{diff}.
505 \subsection{Admiring our new handiwork}
507 Once we've finished the commit, we can use the \hgcmd{tip} command to
508 display the changeset we just created. This command produces output
509 that is identical to \hgcmd{log}, but it only displays the newest
510 revision in the repository.
511 \interaction{tour.tip}
512 We refer to the newest revision in the repository as the tip revision,
513 or simply the tip.
515 \section{Sharing changes}
517 We mentioned earlier that repositories in Mercurial are
518 self-contained. This means that the changeset we just created exists
519 only in our \dirname{my-hello} repository. Let's look at a few ways
520 that we can propagate this change into other repositories.
522 \subsection{Pulling changes from another repository}
523 \label{sec:tour:pull}
525 To get started, let's clone our original \dirname{hello} repository,
526 which does not contain the change we just committed. We'll call our
527 temporary repository \dirname{hello-pull}.
528 \interaction{tour.clone-pull}
530 We'll use the \hgcmd{pull} command to bring changes from
531 \dirname{my-hello} into \dirname{hello-pull}. However, blindly
532 pulling unknown changes into a repository is a somewhat scary
533 prospect. Mercurial provides the \hgcmd{incoming} command to tell us
534 what changes the \hgcmd{pull} command \emph{would} pull into the
535 repository, without actually pulling the changes in.
536 \interaction{tour.incoming}
537 (Of course, someone could cause more changesets to appear in the
538 repository that we ran \hgcmd{incoming} in, before we get a chance to
539 \hgcmd{pull} the changes, so that we could end up pulling changes that we
540 didn't expect.)
542 Bringing changes into a repository is a simple matter of running the
543 \hgcmd{pull} command, and telling it which repository to pull from.
544 \interaction{tour.pull}
545 As you can see from the before-and-after output of \hgcmd{tip}, we
546 have successfully pulled changes into our repository. There remains
547 one step before we can see these changes in the working directory.
549 \subsection{Updating the working directory}
551 We have so far glossed over the relationship between a repository and
552 its working directory. The \hgcmd{pull} command that we ran in
553 section~\ref{sec:tour:pull} brought changes into the repository, but
554 if we check, there's no sign of those changes in the working
555 directory. This is because \hgcmd{pull} does not (by default) touch
556 the working directory. Instead, we use the \hgcmd{update} command to
557 do this.
558 \interaction{tour.update}
560 It might seem a bit strange that \hgcmd{pull} doesn't update the
561 working directory automatically. There's actually a good reason for
562 this: you can use \hgcmd{update} to update the working directory to
563 the state it was in at \emph{any revision} in the history of the
564 repository. If you had the working directory updated to an old
565 revision---to hunt down the origin of a bug, say---and ran a
566 \hgcmd{pull} which automatically updated the working directory to a
567 new revision, you might not be terribly happy.
569 However, since pull-then-update is such a common thing to do,
570 Mercurial lets you combine the two by passing the \hgopt{pull}{-u}
571 option to \hgcmd{pull}.
572 \begin{codesample2}
573 hg pull -u
574 \end{codesample2}
575 If you look back at the output of \hgcmd{pull} in
576 section~\ref{sec:tour:pull} when we ran it without \hgopt{pull}{-u},
577 you can see that it printed a helpful reminder that we'd have to take
578 an explicit step to update the working directory:
579 \begin{codesample2}
580 (run 'hg update' to get a working copy)
581 \end{codesample2}
583 To find out what revision the working directory is at, use the
584 \hgcmd{parents} command.
585 \interaction{tour.parents}
586 If you look back at figure~\ref{fig:tour-basic:history}, you'll see
587 arrows connecting each changeset. The node that the arrow leads
588 \emph{from} in each case is a parent, and the node that the arrow
589 leads \emph{to} is its child. The working directory has a parent in
590 just the same way; this is the changeset that the working directory
591 currently contains.
593 To update the working directory to a particular revision, give a
594 revision number or changeset~ID to the \hgcmd{update} command.
595 \interaction{tour.older}
596 If you omit an explicit revision, \hgcmd{update} will update to the
597 tip revision, as shown by the second call to \hgcmd{update} in the
598 example above.
600 \subsection{Pushing changes to another repository}
602 Mercurial lets us push changes to another repository, from the
603 repository we're currently visiting. As with the example of
604 \hgcmd{pull} above, we'll create a temporary repository to push our
605 changes into.
606 \interaction{tour.clone-push}
607 The \hgcmd{outgoing} command tells us what changes would be pushed
608 into another repository.
609 \interaction{tour.outgoing}
610 And the \hgcmd{push} command does the actual push.
611 \interaction{tour.push}
612 As with \hgcmd{pull}, the \hgcmd{push} command does not update the
613 working directory in the repository that it's pushing changes into.
614 (Unlike \hgcmd{pull}, \hgcmd{push} does not provide a \texttt{-u}
615 option that updates the other repository's working directory.)
617 What happens if we try to pull or push changes and the receiving
618 repository already has those changes? Nothing too exciting.
619 \interaction{tour.push.nothing}
621 \subsection{Sharing changes over a network}
623 The commands we have covered in the previous few sections are not
624 limited to working with local repositories. Each works in exactly the
625 same fashion over a network connection; simply pass in a URL instead
626 of a local path.
627 \interaction{tour.outgoing.net}
628 In this example, we can see what changes we could push to the remote
629 repository, but the repository is understandably not set up to let
630 anonymous users push to it.
631 \interaction{tour.push.net}
633 %%% Local Variables:
634 %%% mode: latex
635 %%% TeX-master: "00book"
636 %%% End: