X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=tour.mdwn;h=e6429f24592acec073ac8df11b235f311b307a83;hb=1fea60df5d0d8fe3e67903a8728be7c2fb269e24;hp=641383d903c65e92b6e80c1d261efb33107a91fd;hpb=a98dc5a20c65ce0f6f910aed0f2f6621ed8c88c3;p=hgbook-git
diff --git a/tour.mdwn b/tour.mdwn
index 641383d..e6429f2 100644
--- a/tour.mdwn
+++ b/tour.mdwn
@@ -1,10 +1,12 @@
## 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
+.
Copyright © 2006, 2007 Bryan OâSullivan.
@@ -12,122 +14,116 @@ This material may be distributed only subject to the terms and
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
-To begin, weâll use the âhg versionâ command to find out whether
-Mercurial is actually installed properly. The actual version
-information that it prints isnât so important; itâs whether it prints
-anything at all that we care about.
+To begin, weâll use the âgit versionâ command to find out whether git
+is actually installed properly. Versions 1.5 and newer of git are much
+more friendly to new users than versions 1.4 and older. If you aren't
+yet running version 1.5 or newer, it's highly recommended that you
+upgrade.
-1  $ hg version
-2  Mercurial Distributed SCM (version 2937d0dbfab0)
-3Â Â
-4  Copyright (C) 2005, 2006 Matt MackallÂ
-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.
+ $ git version
+ git version 1.5.3.2
#### 2.2.1 Built-in help
-Mercurial provides a built-in help system. This is invaluable for
-those times when you find yourself stuck trying to remember how to run
-a command. If you are completely stuck, simply run âhg helpâ; it will
-print a brief list of commands, along with a description of what each
-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
-
-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
-Mercurial to print more information than it usually would.
+Git provides a built-in help system. This is invaluable for those
+times when you find yourself stuck trying to remember how to run a
+command. If you are completely stuck, simply run âgit helpâ; it will
+print a brief list of commonly-used commands, along with a description
+of what each does. If you ask for help on a specific command (such as
+"git help init"), it prints more detailed information. [XXX: Does "git
+help " work universally as a built-in or does it expect man to be
+present and just call out to "man git-"?]
+
+ [XXX: The original hgbook includes the complete output of "hg
+ help init" at this point. I'm not including the corresponding
+ "git help init" output as it would be excessively long. The
+ description alone is quite reasonable, (other than a
+ not-too-helpful aside about the obsolete git-init-db command),
+ but it only comes after a full screen's worth of options
+ details. Might it make sense to have a more summarized help
+ output for "git help " than all of the documentation
+ available for git-? And perhaps alos provide a "git -v
+ help" similar to "hg -v help" for more?]
### 2.3 Working with a repository
@@ -148,23 +144,23 @@ best to use a built-in command that Mercurial provides. This command
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.
@@ -185,9 +181,9 @@ When we take a more detailed look inside a repository, we can see that
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
@@ -206,33 +202,33 @@ One of the first things we might want to do with a new, unfamiliar
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Â
-5  date:        Tue Sep 06 15:43:07 2005 -0700
-6  summary:     Trim comments.
-7Â Â
-8Â Â changeset:Â Â Â 3:ff5d7b70a2a9
-9  user:        Bryan O'SullivanÂ
-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Â
-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Â
+ date:        Tue Sep 06 15:43:07 2005 -0700
+ summary:     Trim comments.
+
+ changeset:Â Â Â 3:ff5d7b70a2a9
+ user:        Bryan O'SullivanÂ
+ 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Â
+ 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
@@ -313,52 +309,52 @@ To narrow the output of âhg logâ down to a single revision, use the -r
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Â
-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Â
-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Â
-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Â
+ 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Â
+ 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Â
+ 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Â
-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Â
-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Â
-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Â
+ date:        Tue Sep 06 13:15:43 2005 -0700
+ summary:     Introduce a typo into hello.c.
+
+ changeset:Â Â Â 3:ff5d7b70a2a9
+ user:        Bryan O'SullivanÂ
+ 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Â
+ 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.
@@ -372,42 +368,42 @@ trying to decide whether a changeset is the one youâre looking
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Â
-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Â
+ 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Â
-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Â
+ 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
@@ -451,10 +447,10 @@ locally, we can just clone that instead. This is much faster than
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
@@ -472,15 +468,15 @@ scripted example this way. Since youâre not under the same constraint,
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
@@ -495,17 +491,17 @@ Itâs a little bit helpful to know that weâve modified hello.c, but we
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
@@ -558,9 +554,9 @@ To set a user name, use your favourite editor to create a file called
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Â
+ # This is a Mercurial configuration file.
+ [ui]
+ username = Firstname LastnameÂ
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
@@ -588,13 +584,13 @@ this changeset. This is called the commit message. It will be a record
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
@@ -607,10 +603,10 @@ default, itâs best to write a commit message whose first line stands
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Â
-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Â
+ 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
@@ -640,27 +636,27 @@ display the changeset we just created. This command produces output
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Â
-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Â
+ 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.
@@ -678,9 +674,9 @@ To get started, letâs clone our original hello repository, which does
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
@@ -688,16 +684,16 @@ is a somewhat scary prospect. Mercurial provides the âhg incomingâ
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Â
-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Â
+ 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
@@ -707,28 +703,28 @@ didnât expect.)
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Â
-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Â
-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Â
+ 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Â
+ 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
@@ -743,13 +739,13 @@ check, thereâs no sign of those changes in the working directory. This
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
@@ -764,25 +760,25 @@ However, since pull-then-update is such a common thing to do,
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Â
-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Â
+ 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
@@ -793,16 +789,16 @@ that the working directory currently contains.
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Â
-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Â
+ 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
@@ -814,33 +810,33 @@ Mercurial lets us push changes to another repository, from the
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Â
-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Â
+ 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
@@ -850,10 +846,10 @@ other repositoryâs working directory.)
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
@@ -862,24 +858,24 @@ limited to working with local repositories. Each works in exactly the
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Â
-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Â
+ 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