bos@553: bos@553: bos@559: bos@572: bos@553: A tour of Mercurial: the basics bos@559: bos@559: bos@553: Installing Mercurial on your system bos@553: bos@584: Prebuilt binary packages of Mercurial are available for bos@553: every popular operating system. These make it easy to start bos@553: using Mercurial on your computer immediately. bos@553: bos@553: bos@609: Windows bos@609: bos@609: The best version of Mercurial for Windows is bos@609: TortoiseHg, which can be found at http://bitbucket.org/tortoisehg/stable/wiki/Home. bos@609: This package has no external dependencies; it just bos@609: works. It provides both command line and graphical bos@609: user interfaces. bos@609: bos@609: bos@609: bos@609: bos@609: Mac OS X bos@609: bos@609: Lee Cantey publishes an installer of Mercurial bos@609: for Mac OS X at http://mercurial.berkwood.com. bos@609: bos@609: bos@609: bos@553: Linux bos@553: bos@584: Because each Linux distribution has its own packaging bos@553: tools, policies, and rate of development, it's difficult to bos@553: give a comprehensive set of instructions on how to install bos@553: Mercurial binaries. The version of Mercurial that you will bos@553: end up with can vary depending on how active the person is who bos@553: maintains the package for your distribution. bos@553: bos@584: To keep things simple, I will focus on installing bos@553: Mercurial from the command line under the most popular Linux bos@553: distributions. Most of these distributions provide graphical bos@553: package managers that will let you install Mercurial with a bos@553: single click; the package name to look for is bos@553: mercurial. bos@553: bos@553: bos@609: Ubuntu and Debian: bos@579: apt-get install mercurial bos@609: Fedora and OpenSUSE: bos@579: yum install mercurial bos@584: Gentoo: bos@553: emerge mercurial bos@553: bos@553: bos@553: bos@553: bos@553: Solaris bos@553: bos@584: SunFreeWare, at http://www.sunfreeware.com, bos@609: provides prebuilt packages of Mercurial. bos@609: bos@609: bos@609: bos@553: bos@609: bos@553: bos@553: Getting started bos@553: bos@584: To begin, we'll use the hg bos@553: version command to find out whether Mercurial is bos@553: actually installed properly. The actual version information bos@553: that it prints isn't so important; it's whether it prints bos@559: anything at all that we care about. bos@559: bos@566: &interaction.tour.version; bos@553: bos@553: bos@553: Built-in help bos@553: bos@584: Mercurial provides a built-in help system. This is bos@559: invaluable for those times when you find yourself stuck bos@559: trying to remember how to run a command. If you are bos@559: completely stuck, simply run hg bos@559: help; it will print a brief list of commands, bos@559: along with a description of what each does. If you ask for bos@559: help on a specific command (as below), it prints more bos@559: detailed information. bos@559: bos@566: &interaction.tour.help; bos@559: bos@584: For a more impressive level of detail (which you won't bos@559: usually need) run hg help . The option is short for bos@559: , and tells bos@559: Mercurial to print more information than it usually bos@559: would. bos@553: bos@553: bos@553: bos@553: bos@553: Working with a repository bos@553: bos@584: In Mercurial, everything happens inside a bos@553: repository. The repository for a project bos@553: contains all of the files that belong to that bos@553: project, along with a historical record of the project's bos@553: files. bos@553: bos@584: There's nothing particularly magical about a repository; it bos@553: is simply a directory tree in your filesystem that Mercurial bos@553: treats as special. You can rename or delete a repository any bos@553: time you like, using either the command line or your file bos@553: browser. bos@553: bos@553: bos@553: Making a local copy of a repository bos@553: bos@584: Copying a repository is just a little bos@553: bit special. While you could use a normal file copying bos@553: command to make a copy of a repository, it's best to use a bos@553: built-in command that Mercurial provides. This command is bos@553: called hg clone, because it bos@609: makes an identical copy of an existing repository. bos@559: bos@566: &interaction.tour.clone; bos@559: bos@609: One advantage of using hg bos@609: clone is that, as we can see above, it lets us clone bos@609: repositories over the network. Another is that it remembers bos@609: where we cloned from, which we'll find useful soon when we bos@609: want to fetch new changes from another repository. bos@609: bos@584: If our clone succeeded, we should now have a local bos@559: directory called hello. bos@559: This directory will contain some files. bos@559: bos@566: &interaction.tour.ls; bos@559: bos@584: These files have the same contents and history in our bos@559: repository as they do in the repository we cloned. bos@553: bos@609: Every Mercurial repository is complete, bos@609: self-contained, and independent. It contains its own private bos@609: copy of a project's files and history. As we just mentioned, bos@609: a cloned repository remembers the location of the repository bos@609: it was cloned from, but Mercurial will not communicate with bos@609: that repository, or any other, unless you tell it to. bos@553: bos@584: What this means for now is that we're free to experiment bos@553: with our repository, safe in the knowledge that it's a private bos@553: sandbox that won't affect anyone else. bos@553: bos@553: bos@553: bos@553: What's in a repository? bos@553: bos@584: When we take a more detailed look inside a repository, we bos@553: can see that it contains a directory named .hg. This is where Mercurial bos@559: keeps all of its metadata for the repository. bos@559: bos@566: &interaction.tour.ls-a; bos@553: bos@584: The contents of the .hg directory and its bos@553: subdirectories are private to Mercurial. Every other file and bos@553: directory in the repository is yours to do with as you bos@553: please. bos@553: bos@584: To introduce a little terminology, the .hg directory is the bos@553: real repository, and all of the files and bos@553: directories that coexist with it are said to live in the bos@553: working directory. An easy way to bos@553: remember the distinction is that the bos@553: repository contains the bos@553: history of your project, while the bos@553: working directory contains a bos@553: snapshot of your project at a particular bos@553: point in history. bos@553: bos@553: bos@553: bos@553: bos@553: A tour through history bos@553: bos@584: One of the first things we might want to do with a new, bos@553: unfamiliar repository is understand its history. The hg log command gives us a view of bos@609: the history of changes in the repository. bos@559: bos@566: &interaction.tour.log; bos@559: bos@584: By default, this command prints a brief paragraph of output bos@559: for each change to the project that was recorded. In Mercurial bos@559: terminology, we call each of these recorded events a bos@553: changeset, because it can contain a record bos@553: of changes to several files. bos@553: bos@584: The fields in a record of output from hg log are as follows. bos@609: bos@553: bos@609: changeset: This bos@609: field has the format of a number, followed by a colon, bos@609: followed by a hexadecimal (or hex) bos@609: string. These are identifiers for the bos@609: changeset. The hex string is a unique identifier: the same bos@609: hex string will always refer to the same changeset. The bos@609: number is shorter and easier to type than the hex string, bos@609: but it isn't unique: the same number in two different clones bos@609: of a repository may identify different changesets. Why bos@609: provide the number at all, then? For local bos@609: convenience. bos@609: bos@584: user: The identity of the bos@553: person who created the changeset. This is a free-form bos@553: field, but it most often contains a person's name and email bos@553: address. bos@584: date: The date and time on bos@553: which the changeset was created, and the timezone in which bos@553: it was created. (The date and time are local to that bos@553: timezone; they display what time and date it was for the bos@553: person who created the changeset.) bos@584: summary: The first line of bos@553: the text message that the creator of the changeset entered bos@609: to describe the changeset. bos@609: bos@609: Some changesets, such as the first in the list above, bos@609: have a tag field. A tag is another way bos@609: to identify a changeset, by giving it an easy-to-remember bos@609: name. (The tag named tip is special: it bos@609: always refers to the newest change in a repository.) bos@609: bos@609: bos@609: bos@609: The default output printed by hg log is purely a summary; it is bos@609: missing a lot of detail. bos@553: bos@592: provides bos@592: a graphical representation of the history of the hello repository, to make it a bos@553: little easier to see which direction history is bos@553: flowing in. We'll be returning to this figure bos@553: several times in this chapter and the chapter that bos@553: follows. bos@553: bos@591:
bos@591: Graphical history of the <filename bos@591: class="directory">hello</filename> repository bos@558: bos@594: bos@558: XXX add text bos@558: bos@591:
bos@553: bos@553: bos@553: Changesets, revisions, and talking to other bos@553: people bos@553: bos@584: As English is a notoriously sloppy language, and computer bos@553: science has a hallowed history of terminological confusion bos@553: (why use one term when four will do?), revision control has a bos@553: variety of words and phrases that mean the same thing. If you bos@553: are talking about Mercurial history with other people, you bos@553: will find that the word changeset is often bos@553: compressed to change or (when written) bos@553: cset, and sometimes a changeset is referred to bos@553: as a revision or a rev. bos@553: bos@584: While it doesn't matter what word you bos@553: use to refer to the concept of a changeset, the bos@553: identifier that you use to refer to bos@553: a specific changeset is of bos@553: great importance. Recall that the changeset bos@553: field in the output from hg bos@553: log identifies a changeset using both a number and bos@553: a hexadecimal string. bos@553: bos@609: The revision number is a handy bos@609: notation that is only valid in that bos@609: repository. bos@609: The hexadecimal string is the bos@553: permanent, unchanging identifier that bos@553: will always identify that exact changeset in bos@553: every copy of the bos@553: repository. bos@609: bos@609: This distinction is important. If you send bos@609: someone an email talking about revision 33, bos@609: there's a high likelihood that their revision 33 will bos@609: not be the same as yours. The reason for bos@609: this is that a revision number depends on the order in which bos@609: changes arrived in a repository, and there is no guarantee bos@609: that the same changes will happen in the same order in bos@609: different repositories. Three changes a,b,c bos@609: can easily appear in one repository as bos@609: 0,1,2, while in another as bos@609: 0,2,1. bos@553: bos@584: Mercurial uses revision numbers purely as a convenient bos@553: shorthand. If you need to discuss a changeset with someone, bos@553: or make a record of a changeset for some other reason (for bos@553: example, in a bug report), use the hexadecimal bos@553: identifier. bos@553: bos@553: bos@553: bos@553: Viewing specific revisions bos@553: bos@584: To narrow the output of hg bos@553: log down to a single revision, use the (or ) option. You can use bos@609: either a revision number or a hexadecimal identifier, bos@559: and you can provide as many revisions as you want. bos@559: bos@566: &interaction.tour.log-r; bos@553: bos@584: If you want to see the history of several revisions bos@553: without having to list each one, you can use range bos@553: notation; this lets you express the idea I bos@559: want all revisions between abc and bos@559: def, inclusive. bos@559: bos@566: &interaction.tour.log.range; bos@559: bos@584: Mercurial also honours the order in which you specify bos@559: revisions, so hg log -r 2:4 bos@559: prints 2, 3, and 4. while hg log -r bos@559: 4:2 prints 4, 3, and 2. bos@553: bos@553: bos@553: bos@553: More detailed information bos@553: bos@584: While the summary information printed by hg log is useful if you already know bos@553: what you're looking for, you may need to see a complete bos@553: description of the change, or a list of the files changed, if bos@553: you're trying to decide whether a changeset is the one you're bos@553: looking for. The hg log bos@553: command's (or ) option gives you bos@559: this extra detail. bos@559: bos@566: &interaction.tour.log-v; bos@553: bos@592: If you want to see both the description and bos@592: content of a change, add the (or ) option. This displays bos@592: the content of a change as a unified diff bos@592: (if you've never seen a unified diff before, see for an overview). bos@559: bos@566: &interaction.tour.log-vp; bos@553: bos@609: The option is bos@609: tremendously useful, so it's well worth remembering. bos@609: bos@553: bos@553:
bos@609: bos@553: bos@553: All about command options bos@553: bos@584: Let's take a brief break from exploring Mercurial commands bos@553: to discuss a pattern in the way that they work; you may find bos@553: this useful to keep in mind as we continue our tour. bos@553: bos@584: Mercurial has a consistent and straightforward approach to bos@553: dealing with the options that you can pass to commands. It bos@553: follows the conventions for options that are common to modern bos@553: Linux and Unix systems. bos@609: bos@553: bos@609: bos@609: Every option has a long name. For example, as bos@553: we've already seen, the hg bos@553: log command accepts a option. bos@609: bos@609: bos@609: Most options have short names, too. Instead bos@609: of , we can use bos@609: . (The reason that bos@609: some options don't have short names is that the options in bos@609: question are rarely used.) bos@609: bos@609: bos@609: Long options start with two dashes (e.g. bos@609: ), while short bos@609: options start with one (e.g. ). bos@609: bos@609: bos@609: Option naming and usage is consistent across bos@553: commands. For example, every command that lets you specify bos@553: a changeset ID or revision number accepts both and arguments. bos@609: bos@609: bos@609: If you are using short options, you can save typing by bos@609: running them together. For example, the command hg log -v -p -r 2 can be written bos@609: as hg log -vpr2. bos@609: bos@609: bos@609: bos@584: In the examples throughout this book, I use short options bos@553: instead of long. This just reflects my own preference, so don't bos@553: read anything significant into it. bos@553: bos@584: Most commands that print output of some kind will print more bos@553: output when passed a bos@553: (or ) option, and bos@553: less when passed (or bos@553: ). bos@553: bos@609: bos@609: Option naming consistency bos@609: bos@609: Almost always, Mercurial commands use consistent option bos@609: names to refer to the same concepts. For instance, if a bos@609: command deals with changesets, you'll always identify them bos@609: with or . This consistent use of bos@609: option names makes it easier to remember what options a bos@609: particular command takes. bos@609: bos@609: bos@553: bos@553: bos@553: Making and reviewing changes bos@553: bos@584: Now that we have a grasp of viewing history in Mercurial, bos@553: let's take a look at making some changes and examining bos@553: them. bos@553: bos@584: The first thing we'll do is isolate our experiment in a bos@553: repository of its own. We use the hg bos@553: clone command, but we don't need to clone a copy of bos@553: the remote repository. Since we already have a copy of it bos@553: locally, we can just clone that instead. This is much faster bos@553: than cloning over the network, and cloning a local repository bos@609: uses less disk space in most cases, too bos@609: The saving of space arises when source and destination bos@609: repositories are on the same filesystem, in which case bos@609: Mercurial will use hardlinks to do copy-on-write sharing of bos@609: its internal metadata. If that explanation meant nothing to bos@609: you, don't worry: everything happens transparently and bos@609: automatically, and you don't need to understand it. bos@609: . bos@559: bos@566: &interaction.tour.reclone; bos@559: bos@584: As an aside, it's often good practice to keep a bos@559: pristine copy of a remote repository around, bos@559: which you can then make temporary clones of to create sandboxes bos@559: for each task you want to work on. This lets you work on bos@559: multiple tasks in parallel, each isolated from the others until bos@559: it's complete and you're ready to integrate it back. Because bos@559: local clones are so cheap, there's almost no overhead to cloning bos@559: and destroying repositories whenever you want. bos@553: bos@584: In our my-hello bos@553: repository, we have a file hello.c that bos@609: contains the classic hello, world program. bos@609: bos@609: &interaction.tour.cat1; bos@609: bos@609: Let's edit this file so that it prints a second line of bos@609: output. bos@609: bos@609: &interaction.tour.cat2; bos@553: bos@584: Mercurial's hg status bos@553: command will tell us what Mercurial knows about the files in the bos@559: repository. bos@559: bos@566: &interaction.tour.status; bos@559: bos@584: The hg status command bos@559: prints no output for some files, but a line starting with bos@553: M for bos@553: hello.c. Unless you tell it to, hg status will not print any output bos@553: for files that have not been modified. bos@553: bos@584: The M indicates that bos@553: Mercurial has noticed that we modified bos@553: hello.c. We didn't need to bos@553: inform Mercurial that we were going to bos@553: modify the file before we started, or that we had modified the bos@553: file after we were done; it was able to figure this out bos@553: itself. bos@553: bos@609: It's somewhat helpful to know that we've modified bos@553: hello.c, but we might prefer to know bos@553: exactly what changes we've made to it. To bos@553: do this, we use the hg diff bos@559: command. bos@559: bos@566: &interaction.tour.diff; bos@553: bos@609: bos@609: Understanding patches bos@609: bos@609: Remember to take a look at if you don't know how to read bos@609: output above. bos@609: bos@553: bos@553: bos@553: Recording changes in a new changeset bos@553: bos@584: We can modify files, build and test our changes, and use bos@553: hg status and hg diff to review our changes, until bos@553: we're satisfied with what we've done and arrive at a natural bos@553: stopping point where we want to record our work in a new bos@553: changeset. bos@553: bos@584: The hg commit command lets bos@553: us create a new changeset; we'll usually refer to this as bos@553: making a commit or bos@553: committing. bos@553: bos@553: bos@553: Setting up a username bos@553: bos@584: When you try to run hg bos@553: commit for the first time, it is not guaranteed to bos@553: succeed. Mercurial records your name and address with each bos@553: change that you commit, so that you and others will later be bos@553: able to tell who made each change. Mercurial tries to bos@553: automatically figure out a sensible username to commit the bos@553: change with. It will attempt each of the following methods, bos@553: in order: bos@553: bos@584: If you specify a option to the hg commit command on the command bos@553: line, followed by a username, this is always given the bos@553: highest precedence. bos@584: If you have set the HGUSER bos@553: environment variable, this is checked bos@553: next. bos@592: If you create a file in your home bos@592: directory called .hgrc, with a username entry, that will be bos@592: used next. To see what the contents of this file should bos@592: look like, refer to bos@553: below. bos@584: If you have set the EMAIL bos@553: environment variable, this will be used bos@553: next. bos@584: Mercurial will query your system to find out bos@553: your local user name and host name, and construct a bos@553: username from these components. Since this often results bos@553: in a username that is not very useful, it will print a bos@553: warning if it has to do bos@558: this. bos@558: bos@584: If all of these mechanisms fail, Mercurial will bos@553: fail, printing an error message. In this case, it will not bos@553: let you commit until you set up a bos@558: username. bos@584: You should think of the HGUSER environment bos@558: variable and the bos@558: option to the hg commit bos@558: command as ways to override Mercurial's bos@558: default selection of username. For normal use, the simplest bos@558: and most robust way to set a username for yourself is by bos@558: creating a .hgrc file; see bos@558: below for details. bos@558: bos@553: Creating a Mercurial configuration file bos@558: bos@584: To set a user name, use your favourite editor bos@553: to create a file called .hgrc in your home directory. bos@553: Mercurial will use this file to look up your personalised bos@553: configuration settings. The initial contents of your bos@553: .hgrc should look like bos@558: this. bos@609: bos@609: Figure out what the appropriate directory is on bos@609: Windows. bos@609: bos@558: # This is a Mercurial configuration file. bos@579: [ui] bos@609: username = Firstname Lastname <email.address@domain.net> bos@558: bos@584: The [ui] line begins a bos@558: section of the config file, so you can bos@558: read the username = ... bos@558: line as meaning set the value of the bos@558: username item in the bos@558: ui section. A section continues bos@558: until a new section begins, or the end of the file. bos@558: Mercurial ignores empty lines and treats any text from bos@558: # to the end of a line as bos@558: a comment. bos@553: bos@558: bos@553: bos@553: Choosing a user name bos@553: bos@584: You can use any text you like as the value of bos@553: the username config item, since this bos@609: information is for reading by other people, but will not be bos@609: interpreted by Mercurial. The convention that most bos@553: people follow is to use their name and email address, as bos@558: in the example above. bos@553: bos@584: Mercurial's built-in web server obfuscates bos@553: email addresses, to make it more difficult for the email bos@553: harvesting tools that spammers use. This reduces the bos@553: likelihood that you'll start receiving more junk email bos@553: if you publish a Mercurial repository on the bos@558: web. bos@553: bos@553: bos@553: bos@553: bos@553: Writing a commit message bos@553: bos@584: When we commit a change, Mercurial drops us into bos@553: a text editor, to enter a message that will describe the bos@553: modifications we've made in this changeset. This is called bos@553: the commit message. It will be a bos@553: record for readers of what we did and why, and it will be bos@553: printed by hg log after bos@558: we've finished committing. bos@558: bos@566: &interaction.tour.commit; bos@558: bos@584: The editor that the hg bos@553: commit command drops us into will contain an bos@609: empty line or two, followed by a number of lines starting with bos@558: HG:. bos@558: bos@609: bos@609: This is where I type my commit comment. bos@609: bos@609: HG: Enter commit message. Lines beginning with 'HG:' are removed. bos@609: HG: -- bos@609: HG: user: Bryan O'Sullivan <bos@serpentine.com> bos@609: HG: branch 'default' bos@609: HG: changed hello.c bos@558: bos@584: Mercurial ignores the lines that start with bos@553: HG:; it uses them only to bos@553: tell us which files it's recording changes to. Modifying or bos@558: deleting these lines has no effect. bos@553: bos@553: bos@553: Writing a good commit message bos@553: bos@584: Since hg log bos@553: only prints the first line of a commit message by default, bos@553: it's best to write a commit message whose first line stands bos@553: alone. Here's a real example of a commit message that bos@553: doesn't follow this guideline, and bos@553: hence has a summary that is not bos@558: readable. bos@558: bos@558: bos@558: changeset: 73:584af0e231be bos@579: user: Censored Person <censored.person@example.org> bos@579: date: Tue Sep 26 21:37:07 2006 -0700 bos@558: summary: include buildmeister/commondefs. Add exports. bos@558: bos@584: As far as the remainder of the contents of the bos@553: commit message are concerned, there are no hard-and-fast bos@553: rules. Mercurial itself doesn't interpret or care about the bos@553: contents of the commit message, though your project may have bos@553: policies that dictate a certain kind of bos@558: formatting. bos@584: My personal preference is for short, but bos@553: informative, commit messages that tell me something that I bos@553: can't figure out with a quick glance at the output of bos@553: hg log bos@558: --patch. bos@553: bos@553: bos@553: Aborting a commit bos@553: bos@584: If you decide that you don't want to commit bos@553: while in the middle of editing a commit message, simply exit bos@553: from your editor without saving the file that it's editing. bos@553: This will cause nothing to happen to either the repository bos@558: or the working directory. bos@584: If we run the hg bos@553: commit command without any arguments, it records bos@553: all of the changes we've made, as reported by hg status and hg diff. bos@553: bos@553: bos@553: Admiring our new handiwork bos@553: bos@584: Once we've finished the commit, we can use the bos@553: hg tip command to display bos@553: the changeset we just created. This command produces output bos@553: that is identical to hg bos@553: log, but it only displays the newest revision in bos@558: the repository. bos@558: bos@566: &interaction.tour.tip; bos@558: bos@609: We refer to the newest revision in the bos@609: repository as the tip revision, or simply bos@609: the tip. bos@609: bos@609: By the way, the hg tip bos@609: command accepts many of the same options as hg log, so above indicates be bos@609: verbose, bos@609: specifies print a patch. The use of to print patches is another bos@609: example of the consistent naming we mentioned earlier. bos@553: bos@553: bos@558: bos@553: bos@553: Sharing changes bos@553: bos@584: We mentioned earlier that repositories in bos@553: Mercurial are self-contained. This means that the changeset bos@553: we just created exists only in our my-hello repository. Let's bos@553: look at a few ways that we can propagate this change into bos@558: other repositories. bos@558: bos@558: bos@553: Pulling changes from another repository bos@584: To get started, let's clone our original bos@553: hello repository, bos@553: which does not contain the change we just committed. We'll bos@553: call our temporary repository hello-pull. bos@558: bos@566: &interaction.tour.clone-pull; bos@558: bos@584: We'll use the hg bos@553: pull command to bring changes from my-hello into hello-pull. However, blindly bos@553: pulling unknown changes into a repository is a somewhat bos@553: scary prospect. Mercurial provides the hg incoming command to tell us bos@553: what changes the hg pull bos@553: command would pull into the repository, bos@558: without actually pulling the changes in. bos@558: bos@566: &interaction.tour.incoming; bos@558: bos@609: Suppose you're pulling changes from a repository bos@609: on the network somewhere. While you are looking at the hg incoming output, and before you bos@609: pull those changes, someone might have committed something in bos@609: the remote repository. This means that it's possible to pull bos@609: more changes than you saw when using hg incoming. bos@558: bos@584: Bringing changes into a repository is a simple bos@553: matter of running the hg bos@553: pull command, and telling it which repository to bos@558: pull from. bos@558: bos@566: &interaction.tour.pull; bos@558: bos@584: As you can see bos@553: from the before-and-after output of hg tip, we have successfully bos@553: pulled changes into our repository. There remains one step bos@553: before we can see these changes in the working bos@558: directory. bos@553: bos@553: bos@553: Updating the working directory bos@553: bos@592: We have so far glossed over the relationship bos@592: between a repository and its working directory. The hg pull command that we ran in bos@592: brought changes into the bos@592: repository, but if we check, there's no sign of those changes bos@592: in the working directory. This is because hg pull does not (by default) touch bos@559: the working directory. Instead, we use the hg update command to do this. bos@559: bos@566: &interaction.tour.update; bos@559: bos@584: It might seem a bit strange that hg bos@559: pull doesn't update the working directory bos@559: automatically. There's actually a good reason for this: you bos@559: can use hg update to update bos@559: the working directory to the state it was in at any bos@559: revision in the history of the repository. If bos@609: you had the working directory updated to an old revision&emdash;to bos@609: hunt down the origin of a bug, say&emdash;and ran a hg pull which automatically updated bos@559: the working directory to a new revision, you might not be bos@559: terribly happy. bos@584: However, since pull-then-update is such a common thing to bos@559: do, Mercurial lets you combine the two by passing the option to hg pull. bos@558: bos@584: If you look back at the output of hg pull in when we ran it without , you can see that it printed bos@559: a helpful reminder that we'd have to take an explicit step to bos@559: update the working directory: bos@558: bos@558: bos@558: bos@584: To find out what revision the working directory is at, use bos@559: the hg parents bos@559: command. bos@558: bos@566: &interaction.tour.parents; bos@558: bos@592: If you look back at , bos@559: you'll see arrows connecting each changeset. The node that bos@559: the arrow leads from in each case is a bos@559: parent, and the node that the arrow leads bos@559: to is its child. The working directory bos@559: has a parent in just the same way; this is the changeset that bos@559: the working directory currently contains. bos@559: bos@584: To update the working directory to a particular revision, bos@559: bos@559: give a revision number or changeset ID to the hg update command. bos@559: bos@566: &interaction.tour.older; bos@559: bos@584: If you omit an explicit revision, hg update will update to the tip bos@559: revision, as shown by the second call to hg update in the example bos@559: above. bos@558: bos@558: bos@553: bos@553: Pushing changes to another repository bos@553: bos@584: Mercurial lets us push changes to another bos@553: repository, from the repository we're currently visiting. bos@553: As with the example of hg bos@553: pull above, we'll create a temporary repository bos@558: to push our changes into. bos@558: bos@566: &interaction.tour.clone-push; bos@558: bos@584: The hg outgoing command bos@553: tells us what changes would be pushed into another bos@558: repository. bos@558: bos@566: &interaction.tour.outgoing; bos@558: bos@584: And the bos@553: hg push command does the bos@558: actual push. bos@558: bos@566: &interaction.tour.push; bos@558: bos@609: As with hg bos@609: pull, the hg push bos@609: command does not update the working directory in the bos@609: repository that it's pushing changes into. Unlike hg pull, hg bos@609: push does not provide a -u bos@609: option that updates the other repository's working directory. bos@609: This asymmetry is deliberate: the repository we're pushing to bos@609: might be on a remote server and shared between several people. bos@609: If we were to update its working directory while someone was bos@609: working in it, their work would be disrupted. bos@558: bos@584: What happens if we try to pull or push changes bos@553: and the receiving repository already has those changes? bos@558: Nothing too exciting. bos@558: bos@566: &interaction.tour.push.nothing; bos@553: bos@553: bos@553: Sharing changes over a network bos@553: bos@584: The commands we have covered in the previous few bos@553: sections are not limited to working with local repositories. bos@553: Each works in exactly the same fashion over a network bos@558: connection; simply pass in a URL instead of a local bos@558: path. bos@558: bos@566: &interaction.tour.outgoing.net; bos@558: bos@584: In this example, we bos@553: can see what changes we could push to the remote repository, bos@553: but the repository is understandably not set up to let bos@558: anonymous users push to it. bos@558: bos@566: &interaction.tour.push.net; bos@553: bos@553: bos@553:
bos@553: bos@553: