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

Almost always, Mercurial commands use consistent option names to ...

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.