## Chapter 2
-A tour of Mercurial: the basics
+A tour of git: the basics
### 2.0 Copyright
-Distributed revision control with Mercurial
-Bryan O’Sullivan
+This document is a modified version originally known as "Distributed
+revision control with Mercurial" and originally authored by Bryan
+O’Sullivan. The original document was obtained from
+<http://hgbook.red-bean.com/>.
Copyright © 2006, 2007 Bryan O’Sullivan.
conditions set forth in version 1.0 of the Open Publication
License. Please refer to Appendix D for the license text.
-### 2.1 Installing Mercurial on your system
+As this is a modified version, the name of Bryan O'Sullivan is used
+only to properly credit him with the original text. The appearance of
+his name here explicitly does not assert or imply his endorsement of
+this modified document.
-Prebuilt binary packages of Mercurial are available for every popular
-operating system. These make it easy to start using Mercurial on your
+Portions Copyright © 2007 Carl Worth.
+
+Changes made by Carl include the following:
+
+ * 2007-09-27:
+ * Convert from HTML to markdown source syntax
+ * Eliminate all content except Chapter 2 and Appendix D
+ * Eliminate line numbers from examples
+ * Modified to describe git instead of mercurial
+
+### 2.1 Installing git on your system
+
+Prebuilt binary packages of git are available for many popular
+operating systems. These make it easy to start using git on your
computer immediately.
#### 2.1.1 Linux
Because each Linux distribution has its own packaging tools, policies,
and rate of development, it’s difficult to give a comprehensive set of
-instructions on how to install Mercurial binaries. The version of
-Mercurial that you will end up with can vary depending on how active
+instructions on how to install git binaries. The version of
+git that you will end up with can vary depending on how active
the person is who maintains the package for your distribution.
-To keep things simple, I will focus on installing Mercurial from the
+To keep things simple, I will focus on installing git from the
command line under the most popular Linux distributions. Most of these
distributions provide graphical package managers that will let you
-install Mercurial with a single click; the package name to look for is
-mercurial.
+install git with a single click. The package name to look for is
+often git, but is sometimes git-core, (due to an unfortunate name
+with git, meaning GNU Interactive Tools).
* Debian
-1 apt-get install mercurial
+ apt-get install git-core
* Fedora Core
-1 yum install mercurial
+ yum install git
* Gentoo
-1 emerge mercurial
+ emerge git
* OpenSUSE
-1 yum install mercurial
-
- * Ubuntu Ubuntu’s Mercurial package is based on Debian’s. To install
-it, run the following command.
-
-1 apt-get install mercurial
-
-The Ubuntu package for Mercurial tends to lag behind the Debian
-version by a considerable time margin (at the time of writing, seven
-months), which in some cases will mean that on Ubuntu, you may run
-into problems that have since been fixed in the Debian package.
+ yum install git
-#### 2.1.2 Solaris
+ * Ubuntu
-XXX.
+ apt-get install git
-#### 2.1.3 Mac OS X
+#### 2.1.2 Mac OS X
-Lee Cantey publishes an installer of Mercurial for Mac OS X at
-[http://mercurial.berkwood.com][6]. This package works on both
-Intel- and Power-based Macs. Before you can use it, you must install a
-compatible version of Universal MacPython [[BI][7]]. This is easy to
-do; simply follow the instructions on Lee’s site.
+A git-core package is available through
+[macports](http://macports.org). Once macports is enabled, the command
+to install git is:
-#### 2.1.4 Windows
+ port install git-core
-Lee Cantey also publishes an installer of Mercurial for Windows at
-[http://mercurial.berkwood.com][6]. This package has no external
-dependencies; it “just works”.
+#### 2.1.3 Windows
-Note: The Windows version of Mercurial does not automatically convert
-line endings between Windows and Unix styles. If you want to share
-work with Unix users, you must do a little additional configuration
-work. XXX Flesh this out.
+Git has long been available as part of cygwin, and works reasonably
+well in that environment. Some people find cygwin a particularly
+inelegant approach to running git and would prefer a "native"
+solution. To this end, the [msysgit
+project](http://code.google.com/p/msysgit/) is rapidly putting
+together a solution including various packages with full
+installers. These include GitMe, a package to install the entire
+development environment necessary to work on improving the msysgit
+port of git, and WinGit, a package for installing just git itself
+without the development environment, (still in Alpha as of September
+2008).
### 2.2 Getting started
information that it prints isn’t so important; it’s whether it prints
anything at all that we care about.
-1 $ hg version
-2 Mercurial Distributed SCM (version 2937d0dbfab0)
-3
-4 Copyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>
-5 This is free software; see the source for copying conditions. There is NO
-6 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ $ hg version
+ Mercurial Distributed SCM (version 2937d0dbfab0)
+
+ Copyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>
+ This is free software; see the source for copying conditions. There is NO
+ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#### 2.2.1 Built-in help
does. If you ask for help on a specific command (as below), it prints
more detailed information.
-1 $ hg help init
-2 hg init [-e CMD] [--remotecmd CMD] [DEST]
-3
-4 create a new repository in the given directory
-5
-6 Initialize a new repository in the given directory. If the given
-7 directory does not exist, it is created.
-8
-9 If no directory is given, the current directory is used.
-10
-11 It is possible to specify an ssh:// URL as the destination.
-12 Look at the help text for the pull command for important details
-13 about ssh:// URLs.
-14
-15 options:
-16
-17 -e --ssh specify ssh command to use
-18 --remotecmd specify hg command to run on the remote side
-19
-20 use "hg -v help init" to show global options
+ $ hg help init
+ hg init [-e CMD] [--remotecmd CMD] [DEST]
+
+ create a new repository in the given directory
+
+ Initialize a new repository in the given directory. If the given
+ directory does not exist, it is created.
+
+ If no directory is given, the current directory is used.
+
+ It is possible to specify an ssh:// URL as the destination.
+ Look at the help text for the pull command for important details
+ about ssh:// URLs.
+
+ options:
+
+ -e --ssh specify ssh command to use
+ --remotecmd specify hg command to run on the remote side
+
+ use "hg -v help init" to show global options
For a more impressive level of detail (which you won’t usually need)
run “hg help -v”. The -v option is short for --verbose, and tells
is called “hg clone”, because it creates an identical copy of an
existing repository.
-1 $ hg clone http://hg.serpentine.com/tutorial/hello
-2 destination directory: hello
-3 requesting all changes
-4 adding changesets
-5 adding manifests
-6 adding file changes
-7 added 5 changesets with 5 changes to 2 files
-8 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg clone http://hg.serpentine.com/tutorial/hello
+ destination directory: hello
+ requesting all changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 5 changesets with 5 changes to 2 files
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
If our clone succeeded, we should now have a local directory called
hello. This directory will contain some files.
-1 $ ls -l
-2 total 4
-3 drwxrwxr-x 3 bos bos 4096 Jun 17 18:05 hello
-4 $ ls hello
-5 Makefile hello.c
+ $ ls -l
+ total 4
+ drwxrwxr-x 3 bos bos 4096 Jun 17 18:05 hello
+ $ ls hello
+ Makefile hello.c
These files have the same contents and history in our repository as
they do in the repository we cloned.
it contains a directory named .hg. This is where Mercurial keeps all
of its metadata for the repository.
-1 $ cd hello
-2 $ ls -a
-3 . .. .hg Makefile hello.c
+ $ cd hello
+ $ ls -a
+ . .. .hg Makefile hello.c
The contents of the .hg directory and its subdirectories are private
to Mercurial. Every other file and directory in the repository is
repository is understand its history. The “hg log” command gives us a
view of history.
-1 $ hg log
-2 changeset: 4:b57f9a090b62
-3 tag: tip
-4 user: Bryan O'Sullivan <bos@serpentine.com>
-5 date: Tue Sep 06 15:43:07 2005 -0700
-6 summary: Trim comments.
-7
-8 changeset: 3:ff5d7b70a2a9
-9 user: Bryan O'Sullivan <bos@serpentine.com>
-10 date: Tue Sep 06 13:15:58 2005 -0700
-11 summary: Get make to generate the final binary from a .o file.
-12
-13 changeset: 2:057d3c2d823c
-14 user: Bryan O'Sullivan <bos@serpentine.com>
-15 date: Tue Sep 06 13:15:43 2005 -0700
-16 summary: Introduce a typo into hello.c.
-17
-18 changeset: 1:82e55d328c8c
-19 user: mpm@selenic.com
-20 date: Fri Aug 26 01:21:28 2005 -0700
-21 summary: Create a makefile
-22
-23 changeset: 0:0a04b987be5a
-24 user: mpm@selenic.com
-25 date: Fri Aug 26 01:20:50 2005 -0700
-26 summary: Create a standard "hello, world" program
-27
+ $ hg log
+ changeset: 4:b57f9a090b62
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 15:43:07 2005 -0700
+ summary: Trim comments.
+
+ changeset: 3:ff5d7b70a2a9
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:58 2005 -0700
+ summary: Get make to generate the final binary from a .o file.
+
+ changeset: 2:057d3c2d823c
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:43 2005 -0700
+ summary: Introduce a typo into hello.c.
+
+ changeset: 1:82e55d328c8c
+ user: mpm@selenic.com
+ date: Fri Aug 26 01:21:28 2005 -0700
+ summary: Create a makefile
+
+ changeset: 0:0a04b987be5a
+ user: mpm@selenic.com
+ date: Fri Aug 26 01:20:50 2005 -0700
+ summary: Create a standard "hello, world" program
+
By default, this command prints a brief paragraph of output for each
change to the project that was recorded. In Mercurial terminology, we
changeset identifier, and you can provide as many revisions as you
want.
-1 $ hg log -r 3
-2 changeset: 3:ff5d7b70a2a9
-3 user: Bryan O'Sullivan <bos@serpentine.com>
-4 date: Tue Sep 06 13:15:58 2005 -0700
-5 summary: Get make to generate the final binary from a .o file.
-6
-7 $ hg log -r ff5d7b70a2a9
-8 changeset: 3:ff5d7b70a2a9
-9 user: Bryan O'Sullivan <bos@serpentine.com>
-10 date: Tue Sep 06 13:15:58 2005 -0700
-11 summary: Get make to generate the final binary from a .o file.
-12
-13 $ hg log -r 1 -r 4
-14 changeset: 1:82e55d328c8c
-15 user: mpm@selenic.com
-16 date: Fri Aug 26 01:21:28 2005 -0700
-17 summary: Create a makefile
-18
-19 changeset: 4:b57f9a090b62
-20 tag: tip
-21 user: Bryan O'Sullivan <bos@serpentine.com>
-22 date: Tue Sep 06 15:43:07 2005 -0700
-23 summary: Trim comments.
-24
+ $ hg log -r 3
+ changeset: 3:ff5d7b70a2a9
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:58 2005 -0700
+ summary: Get make to generate the final binary from a .o file.
+
+ $ hg log -r ff5d7b70a2a9
+ changeset: 3:ff5d7b70a2a9
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:58 2005 -0700
+ summary: Get make to generate the final binary from a .o file.
+
+ $ hg log -r 1 -r 4
+ changeset: 1:82e55d328c8c
+ user: mpm@selenic.com
+ date: Fri Aug 26 01:21:28 2005 -0700
+ summary: Create a makefile
+
+ changeset: 4:b57f9a090b62
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 15:43:07 2005 -0700
+ summary: Trim comments.
+
If you want to see the history of several revisions without having to
list each one, you can use range notation; this lets you express the
idea “I want all revisions between a and b, inclusive”.
-1 $ hg log -r 2:4
-2 changeset: 2:057d3c2d823c
-3 user: Bryan O'Sullivan <bos@serpentine.com>
-4 date: Tue Sep 06 13:15:43 2005 -0700
-5 summary: Introduce a typo into hello.c.
-6
-7 changeset: 3:ff5d7b70a2a9
-8 user: Bryan O'Sullivan <bos@serpentine.com>
-9 date: Tue Sep 06 13:15:58 2005 -0700
-10 summary: Get make to generate the final binary from a .o file.
-11
-12 changeset: 4:b57f9a090b62
-13 tag: tip
-14 user: Bryan O'Sullivan <bos@serpentine.com>
-15 date: Tue Sep 06 15:43:07 2005 -0700
-16 summary: Trim comments.
-17
+ $ hg log -r 2:4
+ changeset: 2:057d3c2d823c
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:43 2005 -0700
+ summary: Introduce a typo into hello.c.
+
+ changeset: 3:ff5d7b70a2a9
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:58 2005 -0700
+ summary: Get make to generate the final binary from a .o file.
+
+ changeset: 4:b57f9a090b62
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 15:43:07 2005 -0700
+ summary: Trim comments.
+
Mercurial also honours the order in which you specify revisions, so
“hg log -r 2:4” prints 2,3,4 while “hg log -r 4:2” prints 4,3,2.
for. The “hg log” command’s -v (or --verbose) option gives you this
extra detail.
-1 $ hg log -v -r 3
-2 changeset: 3:ff5d7b70a2a9
-3 user: Bryan O'Sullivan <bos@serpentine.com>
-4 date: Tue Sep 06 13:15:58 2005 -0700
-5 files: Makefile
-6 description:
-7 Get make to generate the final binary from a .o file.
-8
-9
+ $ hg log -v -r 3
+ changeset: 3:ff5d7b70a2a9
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:58 2005 -0700
+ files: Makefile
+ description:
+ Get make to generate the final binary from a .o file.
+
+
If you want to see both the description and content of a change, add
the -p (or --patch) option. This displays the content of a change as a
unified diff (if you’ve never seen a unified diff before, see
section [12.4][10] for an overview).
-1 $ hg log -v -p -r 2
-2 changeset: 2:057d3c2d823c
-3 user: Bryan O'Sullivan <bos@serpentine.com>
-4 date: Tue Sep 06 13:15:43 2005 -0700
-5 files: hello.c
-6 description:
-7 Introduce a typo into hello.c.
-8
-9
-10 diff -r 82e55d328c8c -r 057d3c2d823c hello.c
-11 --- a/hello.c Fri Aug 26 01:21:28 2005 -0700
-12 +++ b/hello.c Tue Sep 06 13:15:43 2005 -0700
-13 @@ -11,6 +11,6 @@
-14
-15 int main(int argc, char ⋆⋆argv)
-16 {
-17 - printf("hello, world!∖n");
-18 + printf("hello, world!∖");
-19 return 0;
-20 }
-21
+ $ hg log -v -p -r 2
+ changeset: 2:057d3c2d823c
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:43 2005 -0700
+ files: hello.c
+ description:
+ Introduce a typo into hello.c.
+
+
+ diff -r 82e55d328c8c -r 057d3c2d823c hello.c
+ --- a/hello.c Fri Aug 26 01:21:28 2005 -0700
+ +++ b/hello.c Tue Sep 06 13:15:43 2005 -0700
+ @@ -11,6 +11,6 @@
+
+ int main(int argc, char ⋆⋆argv)
+ {
+ - printf("hello, world!∖n");
+ + printf("hello, world!∖");
+ return 0;
+ }
+
### 2.5 All about command options
cloning over the network, and cloning a local repository uses less
disk space in most cases, too.
-1 $ cd ..
-2 $ hg clone hello my-hello
-3 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-4 $ cd my-hello
+ $ cd ..
+ $ hg clone hello my-hello
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd my-hello
As an aside, it’s often good practice to keep a “pristine” copy of a
remote repository around, which you can then make temporary clones of
you probably won’t want to use sed; simply use your preferred text
editor to do the same thing.)
-1 $ sed -i '/printf/a∖∖tprintf("hello again!∖∖n");' hello.c
+ $ sed -i '/printf/a∖∖tprintf("hello again!∖∖n");' hello.c
Mercurial’s “hg status” command will tell us what Mercurial knows
about the files in the repository.
-1 $ ls
-2 Makefile hello.c
-3 $ hg status
-4 M hello.c
+ $ ls
+ Makefile hello.c
+ $ hg status
+ M hello.c
The “hg status” command prints no output for some files, but a line
starting with “M” for hello.c. Unless you tell it to, “hg status” will
might prefer to know exactly what changes we’ve made to it. To do
this, we use the “hg diff” command.
-1 $ hg diff
-2 diff -r b57f9a090b62 hello.c
-3 --- a/hello.c Tue Sep 06 15:43:07 2005 -0700
-4 +++ b/hello.c Sun Jun 17 18:05:50 2007 +0000
-5 @@ -8,5 +8,6 @@ int main(int argc, char ⋆⋆argv)
-6 int main(int argc, char ⋆⋆argv)
-7 {
-8 printf("hello, world!∖");
-9 + printf("hello again!∖n");
-10 return 0;
-11 }
+ $ hg diff
+ diff -r b57f9a090b62 hello.c
+ --- a/hello.c Tue Sep 06 15:43:07 2005 -0700
+ +++ b/hello.c Sun Jun 17 18:05:50 2007 +0000
+ @@ -8,5 +8,6 @@ int main(int argc, char ⋆⋆argv)
+ int main(int argc, char ⋆⋆argv)
+ {
+ printf("hello, world!∖");
+ + printf("hello again!∖n");
+ return 0;
+ }
### 2.7 Recording changes in a new changeset
your personalised configuration settings. The initial contents of your
.hgrc should look like this.
-1 # This is a Mercurial configuration file.
-2 [ui]
-3 username = Firstname Lastname <email.address@domain.net>
+ # This is a Mercurial configuration file.
+ [ui]
+ username = Firstname Lastname <email.address@domain.net>
The “[ui]” line begins a section of the config file, so you can read
the “username = ...” line as meaning “set the value of the username
for readers of what we did and why, and it will be printed by “hg log”
after we’ve finished committing.
-1 $ hg commit
+ $ hg commit
The editor that the “hg commit” command drops us into will contain an
empty line, followed by a number of lines starting with “HG:”.
-1 empty line
-2 HG: changed hello.c
+ empty line
+ HG: changed hello.c
Mercurial ignores the lines that start with “HG:”; it uses them only
to tell us which files it’s recording changes to. Modifying or
alone. Here’s a real example of a commit message that doesn’t follow
this guideline, and hence has a summary that is not readable.
-1 changeset: 73:584af0e231be
-2 user: Censored Person <censored.person@example.org>
-3 date: Tue Sep 26 21:37:07 2006 -0700
-4 summary: include buildmeister/commondefs. Add an exports and install
+ changeset: 73:584af0e231be
+ user: Censored Person <censored.person@example.org>
+ date: Tue Sep 26 21:37:07 2006 -0700
+ summary: include buildmeister/commondefs. Add an exports and install
As far as the remainder of the contents of the commit message are
concerned, there are no hard-and-fast rules. Mercurial itself doesn’t
that is identical to “hg log”, but it only displays the newest
revision in the repository.
-1 $ hg tip -vp
-2 changeset: 5:fa1321bf0c80
-3 tag: tip
-4 user: Bryan O'Sullivan <bos@serpentine.com>
-5 date: Sun Jun 17 18:05:50 2007 +0000
-6 files: hello.c
-7 description:
-8 Added an extra line of output
-9
-10
-11 diff -r b57f9a090b62 -r fa1321bf0c80 hello.c
-12 --- a/hello.c Tue Sep 06 15:43:07 2005 -0700
-13 +++ b/hello.c Sun Jun 17 18:05:50 2007 +0000
-14 @@ -8,5 +8,6 @@ int main(int argc, char ⋆⋆argv)
-15 int main(int argc, char ⋆⋆argv)
-16 {
-17 printf("hello, world!∖");
-18 + printf("hello again!∖n");
-19 return 0;
-20 }
-21
+ $ hg tip -vp
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ files: hello.c
+ description:
+ Added an extra line of output
+
+
+ diff -r b57f9a090b62 -r fa1321bf0c80 hello.c
+ --- a/hello.c Tue Sep 06 15:43:07 2005 -0700
+ +++ b/hello.c Sun Jun 17 18:05:50 2007 +0000
+ @@ -8,5 +8,6 @@ int main(int argc, char ⋆⋆argv)
+ int main(int argc, char ⋆⋆argv)
+ {
+ printf("hello, world!∖");
+ + printf("hello again!∖n");
+ return 0;
+ }
+
We refer to the newest revision in the repository as the tip revision,
or simply the tip.
not contain the change we just committed. We’ll call our temporary
repository hello-pull.
-1 $ cd ..
-2 $ hg clone hello hello-pull
-3 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd ..
+ $ hg clone hello hello-pull
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
We’ll use the “hg pull” command to bring changes from my-hello into
hello-pull. However, blindly pulling unknown changes into a repository
command to tell us what changes the “hg pull” command would pull into
the repository, without actually pulling the changes in.
-1 $ cd hello-pull
-2 $ hg incoming ../my-hello
-3 comparing with ../my-hello
-4 searching for changes
-5 changeset: 5:fa1321bf0c80
-6 tag: tip
-7 user: Bryan O'Sullivan <bos@serpentine.com>
-8 date: Sun Jun 17 18:05:50 2007 +0000
-9 summary: Added an extra line of output
-10
+ $ cd hello-pull
+ $ hg incoming ../my-hello
+ comparing with ../my-hello
+ searching for changes
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ summary: Added an extra line of output
+
(Of course, someone could cause more changesets to appear in the
repository that we ran “hg incoming” in, before we get a chance to “hg
Bringing changes into a repository is a simple matter of running the
“hg pull” command, and telling it which repository to pull from.
-1 $ hg tip
-2 changeset: 4:b57f9a090b62
-3 tag: tip
-4 user: Bryan O'Sullivan <bos@serpentine.com>
-5 date: Tue Sep 06 15:43:07 2005 -0700
-6 summary: Trim comments.
-7
-8 $ hg pull ../my-hello
-9 pulling from ../my-hello
-10 searching for changes
-11 adding changesets
-12 adding manifests
-13 adding file changes
-14 added 1 changesets with 1 changes to 1 files
-15 (run 'hg update' to get a working copy)
-16 $ hg tip
-17 changeset: 5:fa1321bf0c80
-18 tag: tip
-19 user: Bryan O'Sullivan <bos@serpentine.com>
-20 date: Sun Jun 17 18:05:50 2007 +0000
-21 summary: Added an extra line of output
-22
+ $ hg tip
+ changeset: 4:b57f9a090b62
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 15:43:07 2005 -0700
+ summary: Trim comments.
+
+ $ hg pull ../my-hello
+ pulling from ../my-hello
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+ (run 'hg update' to get a working copy)
+ $ hg tip
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ summary: Added an extra line of output
+
As you can see from the before-and-after output of “hg tip”, we have
successfully pulled changes into our repository. There remains one
is because “hg pull” does not (by default) touch the working
directory. Instead, we use the “hg update” command to do this.
-1 $ grep printf hello.c
-2 printf("hello, world!∖");
-3 $ hg update tip
-4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-5 $ grep printf hello.c
-6 printf("hello, world!∖");
-7 printf("hello again!∖n");
+ $ grep printf hello.c
+ printf("hello, world!∖");
+ $ hg update tip
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ grep printf hello.c
+ printf("hello, world!∖");
+ printf("hello again!∖n");
It might seem a bit strange that “hg pull” doesn’t update the working
directory automatically. There’s actually a good reason for this: you
Mercurial lets you combine the two by passing the -u option to “hg
pull”.
-1 hg pull -u
+ hg pull -u
If you look back at the output of “hg pull” in section [2.8.1][12]
when we ran it without -u, you can see that it printed a helpful
reminder that we’d have to take an explicit step to update the working
directory:
-1 (run 'hg update' to get a working copy)
+ (run 'hg update' to get a working copy)
To find out what revision the working directory is at, use the “hg
parents” command.
-1 $ hg parents
-2 changeset: 5:fa1321bf0c80
-3 tag: tip
-4 user: Bryan O'Sullivan <bos@serpentine.com>
-5 date: Sun Jun 17 18:05:50 2007 +0000
-6 summary: Added an extra line of output
-7
+ $ hg parents
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ summary: Added an extra line of output
+
If you look back at figure [2.1][8], you’ll see arrows connecting each
changeset. The node that the arrow leads from in each case is a
To update the working directory to a particular revision, give a
revision number or changeset ID to the “hg update” command.
-1 $ hg update 2
-2 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-3 $ hg parents
-4 changeset: 2:057d3c2d823c
-5 user: Bryan O'Sullivan <bos@serpentine.com>
-6 date: Tue Sep 06 13:15:43 2005 -0700
-7 summary: Introduce a typo into hello.c.
-8
-9 $ hg update
-10 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg update 2
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg parents
+ changeset: 2:057d3c2d823c
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Tue Sep 06 13:15:43 2005 -0700
+ summary: Introduce a typo into hello.c.
+
+ $ hg update
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
If you omit an explicit revision, “hg update” will update to the tip
revision, as shown by the second call to “hg update” in the example
repository we’re currently visiting. As with the example of “hg pull”
above, we’ll create a temporary repository to push our changes into.
-1 $ cd ..
-2 $ hg clone hello hello-push
-3 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd ..
+ $ hg clone hello hello-push
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
The “hg outgoing” command tells us what changes would be pushed into
another repository.
-1 $ cd my-hello
-2 $ hg outgoing ../hello-push
-3 comparing with ../hello-push
-4 searching for changes
-5 changeset: 5:fa1321bf0c80
-6 tag: tip
-7 user: Bryan O'Sullivan <bos@serpentine.com>
-8 date: Sun Jun 17 18:05:50 2007 +0000
-9 summary: Added an extra line of output
-10
+ $ cd my-hello
+ $ hg outgoing ../hello-push
+ comparing with ../hello-push
+ searching for changes
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ summary: Added an extra line of output
+
And the “hg push” command does the actual push.
-1 $ hg push ../hello-push
-2 pushing to ../hello-push
-3 searching for changes
-4 adding changesets
-5 adding manifests
-6 adding file changes
-7 added 1 changesets with 1 changes to 1 files
+ $ hg push ../hello-push
+ pushing to ../hello-push
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
As with “hg pull”, the “hg push” command does not update the working
directory in the repository that it’s pushing changes into. (Unlike
What happens if we try to pull or push changes and the receiving
repository already has those changes? Nothing too exciting.
-1 $ hg push ../hello-push
-2 pushing to ../hello-push
-3 searching for changes
-4 no changes found
+ $ hg push ../hello-push
+ pushing to ../hello-push
+ searching for changes
+ no changes found
#### 2.8.4 Sharing changes over a network
same fashion over a network connection; simply pass in a URL instead
of a local path.
-1 $ hg outgoing http://hg.serpentine.com/tutorial/hello
-2 comparing with http://hg.serpentine.com/tutorial/hello
-3 searching for changes
-4 changeset: 5:fa1321bf0c80
-5 tag: tip
-6 user: Bryan O'Sullivan <bos@serpentine.com>
-7 date: Sun Jun 17 18:05:50 2007 +0000
-8 summary: Added an extra line of output
-9
+ $ hg outgoing http://hg.serpentine.com/tutorial/hello
+ comparing with http://hg.serpentine.com/tutorial/hello
+ searching for changes
+ changeset: 5:fa1321bf0c80
+ tag: tip
+ user: Bryan O'Sullivan <bos@serpentine.com>
+ date: Sun Jun 17 18:05:50 2007 +0000
+ summary: Added an extra line of output
+
In this example, we can see what changes we could push to the remote
repository, but the repository is understandably not set up to let
anonymous users push to it.
-1 $ hg push http://hg.serpentine.com/tutorial/hello
-2 pushing to http://hg.serpentine.com/tutorial/hello
-3 searching for changes
-4 ssl required
+ $ hg push http://hg.serpentine.com/tutorial/hello
+ pushing to http://hg.serpentine.com/tutorial/hello
+ searching for changes
+ ssl required
[1]: http://hgbook.red-bean.com/hgbookch3.html
[2]: http://hgbook.red-bean.com/hgbookch1.html