- $ 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.
+ $ 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: 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: 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: 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
+ changeset: 0:0a04b987be5a
+ user: mpm@selenic.com
+ date: Fri Aug 26 01:20:50 2005 -0700
+ summary: Create a standard "hello, world" program
the hello repository, to make it a little easier to see which
direction history is “flowing” in. We’ll be returning to this figure
several times in this chapter and the chapter that follows.
the hello repository, to make it a little easier to see which
direction history is “flowing” in. We’ll be returning to this figure
several times in this chapter and the chapter that follows.
changeset is referred to as a “revision” or a “rev”.
While it doesn’t matter what word you use to refer to the concept of
changeset is referred to as a “revision” or a “rev”.
While it doesn’t matter what word you use to refer to the concept of
changeset” is of great importance. Recall that the changeset field in
the output from “hg log” identifies a changeset using both a number
and a hexadecimal string.
changeset” is of great importance. Recall that the changeset field in
the output from “hg log” identifies a changeset using both a number
and a hexadecimal string.
will not be the same as yours. The reason for this is that a revision
number depends on the order in which changes arrived in a repository,
and there is no guarantee that the same changes will happen in the
will not be the same as yours. The reason for this is that a revision
number depends on the order in which changes arrived in a repository,
and there is no guarantee that the same changes will happen in the
- $ 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 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 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
+ $ 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.
+ 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”.
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”.
- $ 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.
+ $ 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: 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.
+ 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 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
+ $ 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
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
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
- $ 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
+ $ 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
- 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 @@
+ 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 @@
- - printf("hello, world!∖n");
- + printf("hello, world!∖");
- return 0;
+ - printf("hello, world!∖n");
+ + printf("hello, world!∖");
+ return 0;
* Most options have short names, too. Instead of --rev, we can use
-r. (The reason that some options don’t have short names is that
the options in question are rarely used.)
* Most options have short names, too. Instead of --rev, we can use
-r. (The reason that some options don’t have short names is that
the options in question are rarely used.)
- * Long options start with two dashes (e.g. --rev), while short
- options start with one (e.g. -r).
+ * Long options start with two dashes (e.g. --rev), while short
+ options start with one (e.g. -r).
revision number accepts both -r and --rev arguments.
In the examples throughout this book, I use short options instead of
revision number accepts both -r and --rev arguments.
In the examples throughout this book, I use short options instead of
cloning over the network, and cloning a local repository uses less
disk space in most cases, too.
cloning over the network, and cloning a local repository uses less
disk space in most cases, too.
- $ cd ..
- $ hg clone hello my-hello
- 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
- $ 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
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
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
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.
might prefer to know exactly what changes we’ve made to it. To do
this, we use the “hg diff” command.
- $ 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)
+ $ 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;
+ printf("hello, world!∖");
+ + printf("hello again!∖n");
+ return 0;
2. If you have set the HGUSER environment variable, this is checked next.
3. If you create a file in your home directory called .hgrc, with a
username entry, that will be used next. To see what the contents
2. If you have set the HGUSER environment variable, this is checked next.
3. If you create a file in your home directory called .hgrc, with a
username entry, that will be used next. To see what the contents
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
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.
for readers of what we did and why, and it will be printed by “hg log”
after we’ve finished committing.
The editor that the “hg commit” command drops us into will contain an
empty line, followed by a number of lines starting with “HG:”.
The editor that the “hg commit” command drops us into will contain an
empty line, followed by a number of lines starting with “HG:”.
Mercurial ignores the lines that start with “HG:”; it uses them only
to tell us which files it’s recording changes to. Modifying or
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.
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.
- 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
+ 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
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.
that is identical to “hg log”, but it only displays the newest
revision in the repository.
- $ 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
+ $ 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
- 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)
+ 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;
+ printf("hello, world!∖");
+ + printf("hello again!∖n");
+ return 0;
- $ cd ..
- $ hg clone hello hello-pull
- 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
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.
command to tell us what changes the “hg pull” command would pull into
the repository, without actually pulling the changes in.
- $ 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
+ $ 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
Bringing changes into a repository is a simple matter of running the
“hg pull” command, and telling it which repository to pull from.
Bringing changes into a repository is a simple matter of running the
“hg pull” command, and telling it which repository to pull from.
- $ 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 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
+ $ 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
We have so far glossed over the relationship between a repository and
its working directory. The “hg pull” command that we ran in
We have so far glossed over the relationship between a repository and
its working directory. The “hg pull” command that we ran in
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.
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.
- $ 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");
+ $ 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
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
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:
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:
- $ 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
+ $ 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
changeset. The node that the arrow leads from in each case is a
parent, and the node that the arrow leads to is its child. The working
directory has a parent in just the same way; this is the changeset
that the working directory currently contains.
To update the working directory to a particular revision, give a
changeset. The node that the arrow leads from in each case is a
parent, and the node that the arrow leads to is its child. The working
directory has a parent in just the same way; this is the changeset
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.
-
- $ 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.
+revision number or changeset ID to the “hg update” command.
+
+ $ 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
+ $ 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
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.
repository we’re currently visiting. As with the example of “hg pull”
above, we’ll create a temporary repository to push our changes into.
- $ cd ..
- $ hg clone hello hello-push
- 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
- $ 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
+ $ 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
- $ 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
+ $ 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
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.
What happens if we try to pull or push changes and the receiving
repository already has those changes? Nothing too exciting.
- $ 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
+ $ 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.
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.
- $ hg push http://hg.serpentine.com/tutorial/hello
- pushing to http://hg.serpentine.com/tutorial/hello
- searching for changes
- ssl required
+ $ hg push http://hg.serpentine.com/tutorial/hello
+ pushing to http://hg.serpentine.com/tutorial/hello
+ searching for changes
+ ssl required
[http://www.opencontent.org/openpub/][http://www.opencontent.org/openpub/]).
The reference must be immediately followed with any options elected by
[http://www.opencontent.org/openpub/][http://www.opencontent.org/openpub/]).
The reference must be immediately followed with any options elected by