Mercurial_ The Definitive Guide - Bryan O'Sullivan [15]
date: Sat Aug 16 22:16:53 2008 +0200
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 abc and def, inclusive.”
$ hg log -r 2:4
changeset: 2:fef857204a0c
user: Bryan O'Sullivan date: Sat Aug 16 22:05:04 2008 +0200 summary: Introduce a typo into hello.c. changeset: 3:0272e0d5a517 user: Bryan O'Sullivan date: Sat Aug 16 22:08:02 2008 +0200 summary: Get make to generate the final binary from a .o file. changeset: 4:2278160e78d4 tag: tip user: Bryan O'Sullivan date: Sat Aug 16 22:16:53 2008 +0200 summary: Trim comments. Mercurial also honors the order in which you specify revisions, so hg log -r 2:4 prints 2, 3, and 4 while hg log -r 4:2 prints 4, 3, and 2. More Detailed Information While the summary information printed by hg log is useful if you already know what you’re looking for, you may need to see a complete description of the change, or a list of the files changed, if you’re 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. $ hg log -v -r 3 changeset: 3:0272e0d5a517 user: Bryan O'Sullivan date: Sat Aug 16 22:08:02 2008 +0200 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 Understanding Patches for an overview). $ hg log -v -p -r 2 changeset: 2:fef857204a0c user: Bryan O'Sullivan date: Sat Aug 16 22:05:04 2008 +0200 files: hello.c description: Introduce a typo into hello.c. diff -r 82e55d328c8c -r fef857204a0c hello.c --- a/hello.c Fri Aug 26 01:21:28 2005 -0700 +++ b/hello.c Sat Aug 16 22:05:04 2008 +0200 @@ -11,6 +11,6 @@ int main(int argc, char **argv) { - printf("hello, world!\n"); + printf("hello, world!\"); return 0; } The -p option is tremendously useful, so it’s well worth remembering. All About Command Options Let’s take a brief break from exploring Mercurial commands to discuss a pattern in the way that they work; you may find this useful to keep in mind as we continue our tour. Mercurial has a consistent and straightforward approach to dealing with the options that you can pass to commands. It follows the conventions for options that are common to modern Linux and Unix systems: Every option has a long name. For example, as we’ve already seen, the hg log command accepts a --rev option. 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). Option naming and usage is consistent across commands. For example, every command that lets you specify a changeset ID or revision number accepts both -r and --rev arguments. If you are using short options, you can save typing by running them together. For example, the command hg log -v -p -r 2 can be written as hg log -vpr2. In the examples throughout this book, I usually use short options instead of long. This simply reflects my own preference, so don’t read anything significant into it. Most commands that print output of some kind will print more output when passed a -v (or --verbose) option, and less when passed -q (or --quiet). * * * Option naming consistency * * * Making and Reviewing Changes
Almost always, Mercurial commands use consistent option names to refer to the same concepts. For instance, if a command deals with changesets, you’ll always identify them with --rev or -r. This consistent use of option names makes it easier to remember what options a particular command takes.