hg

Mercurial source code management system

Author: Matt Mackall <mpm@selenic.com>
Organization: Mercurial
Manual section:1
Manual group:Mercurial Manual

Contents

Synopsis

hg command [option]... [argument]...

Description

The hg command provides a command line interface to the Mercurial system.

Command Elements

files...
indicates one or more filename or relative path filenames; see File Name Patterns for information on pattern matching
path
indicates a path on the local machine
revision
indicates a changeset which can be specified as a changeset revision number, a tag, or a unique substring of the changeset hash value
repository path
either the pathname of a local repository or the URI of a remote repository.

Options

-R, --repository
 repository root directory or name of overlay bundle file
--cwd change working directory
-y, --noninteractive
 do not prompt, assume 'yes' for any required answers
-q, --quiet suppress output
-v, --verbose enable additional output
--config set/override config option (use 'section.name=value')
--debug enable debugging output
--debugger start debugger
--encoding set the charset encoding (default: ascii)
--encodingmode set the charset encoding mode (default: strict)
--traceback always print a traceback on exception
--time time how long the command takes
--profile print command execution profile
--version output version information and exit
-h, --help display help and exit

Commands

add [OPTION]... [FILE]...

Schedule files to be version controlled and added to the repository.

The files will be added to the repository at the next commit. To undo an add before that, see hg forget.

If no names are given, add all files to the repository.

An example showing how new (unknown) files are added automatically by hg add:

$ ls
foo.c
$ hg status
? foo.c
$ hg add
adding foo.c
$ hg status
A foo.c

Returns 0 if all files are successfully added.

options:

-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-n, --dry-run do not perform actions, just print output
addremove [OPTION]... [FILE]...

Add all new files and remove all missing files from the repository.

New files are ignored if they match any of the patterns in .hgignore. As with add, these changes take effect at the next commit.

Use the -s/--similarity option to detect renamed files. With a parameter greater than 0, this compares every removed file with every added file and records those similar enough as renames. This option takes a percentage between 0 (disabled) and 100 (files must be identical) as its parameter. Detecting renamed files this way can be expensive. After using this option, hg status -C can be used to check which files were identified as moved or renamed.

Returns 0 if all files are successfully added.

options:

-s, --similarity
 guess renamed files by similarity (0<=s<=100)
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-n, --dry-run do not perform actions, just print output
annotate [-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...

List changes in files, showing the revision id responsible for each line

This command is useful for discovering when a change was made and by whom.

Without the -a/--text option, annotate will avoid processing files it detects as binary. With -a, annotate will annotate the file anyway, although the results will probably be neither useful nor desirable.

Returns 0 on success.

options:

-r, --rev annotate the specified revision
--follow follow copies/renames and list the filename (DEPRECATED)
--no-follow don't follow copies and renames
-a, --text treat all files as text
-u, --user list the author (long with -v)
-f, --file list the filename
-d, --date list the date (short with -q)
-n, --number list the revision number (default)
-c, --changeset
 list the changeset
-l, --line-number
 show line number at the first appearance
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns

aliases: blame

archive [OPTION]... DEST

By default, the revision used is the parent of the working directory; use -r/--rev to specify a different revision.

The archive type is automatically detected based on file extension (or override using -t/--type).

Valid types are:

files:a directory full of files (default)
tar:tar archive, uncompressed
tbz2:tar archive, compressed using bzip2
tgz:tar archive, compressed using gzip
uzip:zip archive, uncompressed
zip:zip archive, compressed using deflate

The exact name of the destination archive or directory is given using a format string; see hg help export for details.

Each member added to an archive file has a directory prefix prepended. Use -p/--prefix to specify a format string for the prefix. The default is the basename of the archive, with suffixes removed.

Returns 0 on success.

options:

--no-decode do not pass files through decoders
-p, --prefix directory prefix for files in archive
-r, --rev revision to distribute
-t, --type type of distribution to create
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
backout [OPTION]... [-r] REV

Commit the backed out changes as a new changeset. The new changeset is a child of the backed out changeset.

If you backout a changeset other than the tip, a new head is created. This head will be the new tip and you should merge this backout changeset with another head.

The --merge option remembers the parent of the working directory before starting the backout, then merges the new head with that changeset afterwards. This saves you from doing the merge by hand. The result of this merge is not committed, as with a normal merge.

See hg help dates for a list of formats valid for -d/--date.

Returns 0 on success.

options:

--merge merge with old dirstate parent after backout
--parent parent to choose when backing out merge
-r, --rev revision to backout
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-m, --message use text as commit message
-l, --logfile read commit message from file
-d, --date record datecode as commit date
-u, --user record the specified user as committer
bisect [-gbsr] [-U] [-c CMD] [REV]

This command helps to find changesets which introduce problems. To use, mark the earliest changeset you know exhibits the problem as bad, then mark the latest changeset which is free from the problem as good. Bisect will update your working directory to a revision for testing (unless the -U/--noupdate option is specified). Once you have performed tests, mark the working directory as good or bad, and bisect will either update to another candidate changeset or announce that it has found the bad revision.

As a shortcut, you can also use the revision argument to mark a revision as good or bad without checking it out first.

If you supply a command, it will be used for automatic bisection. Its exit status will be used to mark revisions as good or bad: status 0 means good, 125 means to skip the revision, 127 (command not found) will abort the bisection, and any other non-zero exit status means the revision is bad.

Returns 0 on success.

options:

-r, --reset reset bisect state
-g, --good mark changeset good
-b, --bad mark changeset bad
-s, --skip skip testing changeset
-c, --command use command to check changeset state
-U, --noupdate do not update to target
branch [-fC] [NAME]

With no argument, show the current branch name. With one argument, set the working directory branch name (the branch will not exist in the repository until the next commit). Standard practice recommends that primary development take place on the 'default' branch.

Unless -f/--force is specified, branch will not let you set a branch name that already exists, even if it's inactive.

Use -C/--clean to reset the working directory branch to that of the parent of the working directory, negating a previous branch change.

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch as closed.

Returns 0 on success.

options:

-f, --force set branch name even if it shadows an existing branch
-C, --clean reset branch name to parent branch name
branches [-ac]

List the repository's named branches, indicating which ones are inactive. If -c/--closed is specified, also list branches which have been marked closed (see hg commit --close-branch).

If -a/--active is specified, only show active branches. A branch is considered active if it contains repository heads.

Use the command hg update to switch to an existing branch.

Returns 0.

options:

-a, --active show only branches that have unmerged heads
-c, --closed show normal and closed branches
bundle [-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]

Generate a compressed changegroup file collecting changesets not known to be in another repository.

If you omit the destination repository, then hg assumes the destination will have all the nodes you specify with --base parameters. To create a bundle containing all changesets, use -a/--all (or --base null).

You can change compression method with the -t/--type option. The available compression methods are: none, bzip2, and gzip (by default, bundles are compressed using bzip2).

The bundle file can then be transferred using conventional means and applied to another repository with the unbundle or pull command. This is useful when direct push and pull are not available or when exporting an entire repository is undesirable.

Applying bundles preserves all changeset contents including permissions, copy/rename information, and revision history.

Returns 0 on success, 1 if no changes found.

options:

-f, --force run even when the destination is unrelated
-r, --rev a changeset intended to be added to the destination
-b, --branch a specific branch you would like to bundle
--base a base changeset assumed to be available at the destination
-a, --all bundle all changesets in the repository
-t, --type bundle compression type to use (default: bzip2)
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side
cat [OPTION]... FILE...

Print the specified files as they were at the given revision. If no revision is given, the parent of the working directory is used, or tip if no revision is checked out.

Output may be to a file, in which case the name of the file is given using a format string. The formatting rules are the same as for the export command, with the following additions:

%s:basename of file being printed
%d:dirname of file being printed, or '.' if in repository root
%p:root-relative path name of file being printed

Returns 0 on success.

options:

-o, --output print output to file with formatted name
-r, --rev print the given revision
--decode apply any matching decode filter
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
clone [OPTION]... SOURCE [DEST]

Create a copy of an existing repository in a new directory.

If no destination directory name is specified, it defaults to the basename of the source.

The location of the source is added to the new repository's .hg/hgrc file, as the default to be used for future pulls.

See hg help urls for valid source format details.

It is possible to specify an ssh:// URL as the destination, but no .hg/hgrc and working directory will be created on the remote side. Please see hg help urls for important details about ssh:// URLs.

A set of changesets (tags, or branch names) to pull may be specified by listing each changeset (tag, or branch name) with -r/--rev. If -r/--rev is used, the cloned repository will contain only a subset of the changesets of the source repository. Only the set of changesets defined by all -r/--rev options (including all their ancestors) will be pulled into the destination repository. No subsequent changesets (including subsequent tags) will be present in the destination.

Using -r/--rev (or 'clone src#rev dest') implies --pull, even for local source repositories.

For efficiency, hardlinks are used for cloning whenever the source and destination are on the same filesystem (note this applies only to the repository data, not to the working directory). Some filesystems, such as AFS, implement hardlinking incorrectly, but do not report errors. In these cases, use the --pull option to avoid hardlinking.

In some cases, you can clone repositories and the working directory using full hardlinks with

$ cp -al REPO REPOCLONE

This is the fastest way to clone, but it is not always safe. The operation is not atomic (making sure REPO is not modified during the operation is up to you) and you have to make sure your editor breaks hardlinks (Emacs and most Linux Kernel tools do so). Also, this is not compatible with certain extensions that place their metadata under the .hg directory, such as mq.

Mercurial will update the working directory to the first applicable revision from this list:

  1. null if -U or the source repository has no changesets
  2. if -u . and the source repository is local, the first parent of the source repository's working directory
  3. the changeset specified with -u (if a branch name, this means the latest head of that branch)
  4. the changeset specified with -r
  5. the tipmost head specified with -b
  6. the tipmost head specified with the url#branch source syntax
  7. the tipmost head of the default branch
  8. tip

Returns 0 on success.

options:

-U, --noupdate the clone will include an empty working copy (only a repository)
-u, --updaterev
 revision, tag or branch to check out
-r, --rev include the specified changeset
-b, --branch clone only the specified branch
--pull use pull protocol to copy metadata
--uncompressed use uncompressed transfer (fast over LAN)
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side
commit [OPTION]... [FILE]...

Commit changes to the given files into the repository. Unlike a centralized RCS, this operation is a local operation. See hg push for a way to actively distribute your changes.

If a list of files is omitted, all changes reported by hg status will be committed.

If you are committing the result of a merge, do not provide any filenames or -I/-X filters.

If no commit message is specified, Mercurial starts your configured editor where you can enter a message. In case your commit fails, you will find a backup of your message in .hg/last-message.txt.

See hg help dates for a list of formats valid for -d/--date.

Returns 0 on success, 1 if nothing changed.

options:

-A, --addremove
 mark new/missing files as added/removed before committing
--close-branch mark a branch as closed, hiding it from the branch list
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-m, --message use text as commit message
-l, --logfile read commit message from file
-d, --date record datecode as commit date
-u, --user record the specified user as committer

aliases: ci

copy [OPTION]... [SOURCE]... DEST

Mark dest as having copies of source files. If dest is a directory, copies are put in that directory. If dest is a file, the source must be a single file.

By default, this command copies the contents of files as they exist in the working directory. If invoked with -A/--after, the operation is recorded, but no copying is performed.

This command takes effect with the next commit. To undo a copy before that, see hg revert.

Returns 0 on success, 1 if errors are encountered.

options:

-A, --after record a copy that has already occurred
-f, --force forcibly copy over an existing managed file
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-n, --dry-run do not perform actions, just print output

aliases: cp

diff [OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...

Show differences between revisions for the specified files.

Differences between files are shown using the unified diff format.

NOTE: diff may generate unexpected results for merges, as it will default to comparing against the working directory's first parent changeset if no revisions are specified.

When two revision arguments are given, then changes are shown between those revisions. If only one revision is specified then that revision is compared to the working directory, and, when no revisions are specified, the working directory files are compared to its parent.

Alternatively you can specify -c/--change with a revision to see the changes in that changeset relative to its first parent.

Without the -a/--text option, diff will avoid generating diffs of files it detects as binary. With -a, diff will generate a diff anyway, probably with undesirable results.

Use the -g/--git option to generate diffs in the git extended diff format. For more information, read hg help diffs.

Returns 0 on success.

options:

-r, --rev revision
-c, --change change made by revision
-a, --text treat all files as text
-g, --git use git extended diff format
--nodates omit dates from diff headers
-p, --show-function
 show which function each change is in
--reverse produce a diff that undoes the changes
-w, --ignore-all-space
 ignore white space when comparing lines
-b, --ignore-space-change
 ignore changes in the amount of white space
-B, --ignore-blank-lines
 ignore changes whose lines are all blank
-U, --unified number of lines of context to show
--stat output diffstat-style summary of changes
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
export [OPTION]... [-o OUTFILESPEC] REV...

Print the changeset header and diffs for one or more revisions.

The information shown in the changeset header is: author, date, branch name (if non-default), changeset hash, parent(s) and commit comment.

NOTE: export may generate unexpected diff output for merge changesets, as it will compare the merge changeset against its first parent only.

Output may be to a file, in which case the name of the file is given using a format string. The formatting rules are as follows:

%%:literal "%" character
%H:changeset hash (40 bytes of hexadecimal)
%N:number of patches being generated
%R:changeset revision number
%b:basename of the exporting repository
%h:short-form changeset hash (12 bytes of hexadecimal)
%n:zero-padded sequence number, starting at 1
%r:zero-padded changeset revision number

Without the -a/--text option, export will avoid generating diffs of files it detects as binary. With -a, export will generate a diff anyway, probably with undesirable results.

Use the -g/--git option to generate diffs in the git extended diff format. See hg help diffs for more information.

With the --switch-parent option, the diff will be against the second parent. It can be useful to review a merge.

Returns 0 on success.

options:

-o, --output print output to file with formatted name
--switch-parent
 diff against the second parent
-r, --rev revisions to export
-a, --text treat all files as text
-g, --git use git extended diff format
--nodates omit dates from diff headers
forget [OPTION]... FILE...

Mark the specified files so they will no longer be tracked after the next commit.

This only removes files from the current branch, not from the entire project history, and it does not delete them from the working directory.

To undo a forget before the next commit, see hg add.

Returns 0 on success.

options:

-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
grep [OPTION]... PATTERN [FILE]...

Search revisions of files for a regular expression.

This command behaves differently than Unix grep. It only accepts Python/Perl regexps. It searches repository history, not the working directory. It always prints the revision number in which a match appears.

By default, grep only prints output for the first revision of a file in which it finds a match. To get it to print every revision that contains a change in match status ("-" for a match that becomes a non-match, or "+" for a non-match that becomes a match), use the --all flag.

Returns 0 if a match is found, 1 otherwise.

options:

-0, --print0 end fields with NUL
--all print all revisions that match
-f, --follow follow changeset history, or file history across copies and renames
-i, --ignore-case
 ignore case when matching
-l, --files-with-matches
 print only filenames and revisions that match
-n, --line-number
 print matching line numbers
-r, --rev only search files changed within revision range
-u, --user list the author (long with -v)
-d, --date list the date (short with -q)
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
heads [-ac] [-r REV] [REV]...

With no arguments, show all repository branch heads.

Repository "heads" are changesets with no child changesets. They are where development generally takes place and are the usual targets for update and merge operations. Branch heads are changesets that have no child changeset on the same branch.

If one or more REVs are given, only branch heads on the branches associated with the specified changesets are shown.

If -c/--closed is specified, also show branch heads marked closed (see hg commit --close-branch).

If STARTREV is specified, only those heads that are descendants of STARTREV will be displayed.

If -t/--topo is specified, named branch mechanics will be ignored and only changesets without children will be shown.

Returns 0 if matching heads are found, 1 if not.

options:

-r, --rev show only heads which are descendants of REV
-t, --topo show topological heads only
-a, --active show active branchheads only (DEPRECATED)
-c, --closed show normal and closed branch heads
--style display using template map file
--template display with template
help [TOPIC]

With no arguments, print a list of commands with short help messages.

Given a topic, extension, or command name, print help for that topic.

Returns 0 if successful.

identify [-nibt] [-r REV] [SOURCE]

With no revision, print a summary of the current state of the repository.

Specifying a path to a repository root or Mercurial bundle will cause lookup to operate on that repository/bundle.

This summary identifies the repository state using one or two parent hash identifiers, followed by a "+" if there are uncommitted changes in the working directory, a list of tags for this revision and a branch name for non-default branches.

Returns 0 if successful.

options:

-r, --rev identify the specified revision
-n, --num show local revision number
-i, --id show global revision id
-b, --branch show branch
-t, --tags show tags

aliases: id

import [OPTION]... PATCH...

Import a list of patches and commit them individually (unless --no-commit is specified).

If there are outstanding changes in the working directory, import will abort unless given the -f/--force flag.

You can import a patch straight from a mail message. Even patches as attachments work (to use the body part, it must have type text/plain or text/x-patch). From and Subject headers of email message are used as default committer and commit message. All text/plain body parts before first diff are added to commit message.

If the imported patch was generated by hg export, user and description from patch override values from message headers and body. Values given on command line with -m/--message and -u/--user override these.

If --exact is specified, import will set the working directory to the parent of each patch before applying it, and will abort if the resulting changeset has a different ID than the one recorded in the patch. This may happen due to character set problems or other deficiencies in the text patch format.

With -s/--similarity, hg will attempt to discover renames and copies in the patch in the same way as 'addremove'.

To read a patch from standard input, use "-" as the patch name. If a URL is specified, the patch will be downloaded from it. See hg help dates for a list of formats valid for -d/--date.

Returns 0 on success.

options:

-p, --strip directory strip option for patch. This has the same meaning as the corresponding patch option (default: 1)
-b, --base base path
-f, --force skip check for outstanding uncommitted changes
--no-commit don't commit, just update the working directory
--exact apply patch to the nodes from which it was generated
--import-branch
 use any branch information in patch (implied by --exact)
-m, --message use text as commit message
-l, --logfile read commit message from file
-d, --date record datecode as commit date
-u, --user record the specified user as committer
-s, --similarity
 guess renamed files by similarity (0<=s<=100)

aliases: patch

incoming [-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]

Show new changesets found in the specified path/URL or the default pull location. These are the changesets that would have been pulled if a pull at the time you issued this command.

For remote repository, using --bundle avoids downloading the changesets twice if the incoming is followed by a pull.

See pull for valid source format details.

Returns 0 if there are incoming changes, 1 otherwise.

options:

-f, --force run even if remote repository is unrelated
-n, --newest-first
 show newest record first
--bundle file to store the bundles into
-r, --rev a remote changeset intended to be added
-b, --branch a specific branch you would like to pull
-p, --patch show patch
-g, --git use git extended diff format
-l, --limit limit number of changes displayed
-M, --no-merges
 do not show merges
--stat output diffstat-style summary of changes
--style display using template map file
--template display with template
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side

aliases: in

init [-e CMD] [--remotecmd CMD] [DEST]

Initialize a new repository in the given directory. If the given directory does not exist, it will be created.

If no directory is given, the current directory is used.

It is possible to specify an ssh:// URL as the destination. See hg help urls for more information.

Returns 0 on success.

options:

-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side
locate [OPTION]... [PATTERN]...

Print files under Mercurial control in the working directory whose names match the given patterns.

By default, this command searches all directories in the working directory. To search just the current directory and its subdirectories, use "--include .".

If no patterns are given to match, this command prints the names of all files under Mercurial control in the working directory.

If you want to feed the output of this command into the "xargs" command, use the -0 option to both this command and "xargs". This will avoid the problem of "xargs" treating single filenames that contain whitespace as multiple filenames.

Returns 0 if a match is found, 1 otherwise.

options:

-r, --rev search the repository as it is in REV
-0, --print0 end filenames with NUL, for use with xargs
-f, --fullpath print complete paths from the filesystem root
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
log [OPTION]... [FILE]

Print the revision history of the specified files or the entire project.

File history is shown without following rename or copy history of files. Use -f/--follow with a filename to follow history across renames and copies. --follow without a filename will only show ancestors or descendants of the starting revision. --follow-first only follows the first parent of merge revisions.

If no revision range is specified, the default is tip:0 unless --follow is set, in which case the working directory parent is used as the starting revision. You can specify a revision set for log, see hg help revsets for more information.

See hg help dates for a list of formats valid for -d/--date.

By default this command prints revision number and changeset id, tags, non-trivial parents, user, date and time, and a summary for each commit. When the -v/--verbose switch is used, the list of changed files and full commit message are shown.

NOTE: log -p/--patch may generate unexpected diff output for merge changesets, as it will only compare the merge changeset against its first parent. Also, only files different from BOTH parents will appear in files:.

Returns 0 on success.

options:

-f, --follow follow changeset history, or file history across copies and renames
--follow-first only follow the first parent of merge changesets
-d, --date show revisions matching date spec
-C, --copies show copied files
-k, --keyword do case-insensitive search for a given text
-r, --rev show the specified revision or range
--removed include revisions where files were removed
-m, --only-merges
 show only merges
-u, --user revisions committed by user
--only-branch show only changesets within the given named branch (DEPRECATED)
-b, --branch show changesets within the given named branch
-P, --prune do not display revision or any of its ancestors
-p, --patch show patch
-g, --git use git extended diff format
-l, --limit limit number of changes displayed
-M, --no-merges
 do not show merges
--stat output diffstat-style summary of changes
--style display using template map file
--template display with template
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns

aliases: history

manifest [-r REV]

Print a list of version controlled files for the given revision. If no revision is given, the first parent of the working directory is used, or the null revision if no revision is checked out.

With -v, print file permissions, symlink and executable bits. With --debug, print file revision hashes.

Returns 0 on success.

options:

-r, --rev revision to display
merge [-P] [-f] [[-r] REV]

The current working directory is updated with all changes made in the requested revision since the last common predecessor revision.

Files that changed between either parent are marked as changed for the next commit and a commit must be performed before any further updates to the repository are allowed. The next commit will have two parents.

If no revision is specified, the working directory's parent is a head revision, and the current branch contains exactly one other head, the other head is merged with by default. Otherwise, an explicit revision with which to merge with must be provided.

To undo an uncommitted merge, use hg update --clean . which will check out a clean copy of the original merge parent, losing all changes.

Returns 0 on success, 1 if there are unresolved files.

options:

-f, --force force a merge with outstanding changes
-r, --rev revision to merge
-P, --preview review revisions to merge (no merge is performed)
outgoing [-M] [-p] [-n] [-f] [-r REV]... [DEST]

Show changesets not found in the specified destination repository or the default push location. These are the changesets that would be pushed if a push was requested.

See pull for details of valid destination formats.

Returns 0 if there are outgoing changes, 1 otherwise.

options:

-f, --force run even when the destination is unrelated
-r, --rev a changeset intended to be included in the destination
-n, --newest-first
 show newest record first
-b, --branch a specific branch you would like to push
-p, --patch show patch
-g, --git use git extended diff format
-l, --limit limit number of changes displayed
-M, --no-merges
 do not show merges
--stat output diffstat-style summary of changes
--style display using template map file
--template display with template
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side

aliases: out

parents [-r REV] [FILE]

Print the working directory's parent revisions. If a revision is given via -r/--rev, the parent of that revision will be printed. If a file argument is given, the revision in which the file was last changed (before the working directory revision or the argument to --rev if given) is printed.

Returns 0 on success.

options:

-r, --rev show parents of the specified revision
--style display using template map file
--template display with template
paths [NAME]

Show definition of symbolic path name NAME. If no name is given, show definition of all available names.

Path names are defined in the [paths] section of /etc/mercurial/hgrc and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.

The path names default and default-push have a special meaning. When performing a push or pull operation, they are used as fallbacks if no location is specified on the command-line. When default-push is set, it will be used for push and default will be used for pull; otherwise default is used as the fallback for both. When cloning a repository, the clone source is written as default in .hg/hgrc. Note that default and default-push apply to all inbound (e.g. hg incoming) and outbound (e.g. hg outgoing, hg email and hg bundle) operations.

See hg help urls for more information.

Returns 0 on success.

pull [-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]

Pull changes from a remote repository to a local one.

This finds all changes from the repository at the specified path or URL and adds them to a local repository (the current one unless -R is specified). By default, this does not update the copy of the project in the working directory.

Use hg incoming if you want to see what would have been added by a pull at the time you issued this command. If you then decide to add those changes to the repository, you should use hg pull -r X where X is the last changeset listed by hg incoming.

If SOURCE is omitted, the 'default' path will be used. See hg help urls for more information.

Returns 0 on success, 1 if an update had unresolved files.

options:

-u, --update update to new branch head if changesets were pulled
-f, --force run even when remote repository is unrelated
-r, --rev a remote changeset intended to be added
-b, --branch a specific branch you would like to pull
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side
push [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]

Push changesets from the local repository to the specified destination.

This operation is symmetrical to pull: it is identical to a pull in the destination repository from the current one.

By default, push will not allow creation of new heads at the destination, since multiple heads would make it unclear which head to use. In this situation, it is recommended to pull and merge before pushing.

Use --new-branch if you want to allow push to create a new named branch that is not present at the destination. This allows you to only create a new branch without forcing other changes.

Use -f/--force to override the default behavior and push all changesets on all branches.

If -r/--rev is used, the specified revision and all its ancestors will be pushed to the remote repository.

Please see hg help urls for important details about ssh:// URLs. If DESTINATION is omitted, a default path will be used.

Returns 0 if push was successful, 1 if nothing to push.

options:

-f, --force force push
-r, --rev a changeset intended to be included in the destination
-b, --branch a specific branch you would like to push
--new-branch allow pushing a new branch
-e, --ssh specify ssh command to use
--remotecmd specify hg command to run on the remote side
recover

Recover from an interrupted commit or pull.

This command tries to fix the repository status after an interrupted operation. It should only be necessary when Mercurial suggests it.

Returns 0 if successful, 1 if nothing to recover or verify fails.

remove [OPTION]... FILE...

Schedule the indicated files for removal from the repository.

This only removes files from the current branch, not from the entire project history. -A/--after can be used to remove only files that have already been deleted, -f/--force can be used to force deletion, and -Af can be used to remove files from the next revision without deleting them from the working directory.

The following table details the behavior of remove for different file states (columns) and option combinations (rows). The file states are Added [A], Clean [C], Modified [M] and Missing [!] (as reported by hg status). The actions are Warn, Remove (from branch) and Delete (from disk):

       A  C  M  !
none   W  RD W  R
-f     R  RD RD R
-A     W  W  W  R
-Af    R  R  R  R

This command schedules the files to be removed at the next commit. To undo a remove before that, see hg revert.

Returns 0 on success, 1 if any warnings encountered.

options:

-A, --after record delete for missing files
-f, --force remove (and delete) file even if added or modified
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns

aliases: rm

rename [OPTION]... SOURCE... DEST

Mark dest as copies of sources; mark sources for deletion. If dest is a directory, copies are put in that directory. If dest is a file, there can only be one source.

By default, this command copies the contents of files as they exist in the working directory. If invoked with -A/--after, the operation is recorded, but no copying is performed.

This command takes effect at the next commit. To undo a rename before that, see hg revert.

Returns 0 on success, 1 if errors are encountered.

options:

-A, --after record a rename that has already occurred
-f, --force forcibly copy over an existing managed file
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-n, --dry-run do not perform actions, just print output

aliases: mv

resolve [OPTION]... [FILE]...

Merges with unresolved conflicts are often the result of non-interactive merging using the internal:merge hgrc setting, or a command-line merge tool like diff3. The resolve command is used to manage the files involved in a merge, after hg merge has been run, and before hg commit is run (i.e. the working directory must have two parents).

The resolve command can be used in the following ways:

  • hg resolve FILE...: attempt to re-merge the specified files, discarding any previous merge attempts. Re-merging is not performed for files already marked as resolved. Use --all/-a to selects all unresolved files.
  • hg resolve -m [FILE]: mark a file as having been resolved (e.g. after having manually fixed-up the files). The default is to mark all unresolved files.
  • hg resolve -u [FILE]...: mark a file as unresolved. The default is to mark all resolved files.
  • hg resolve -l: list files which had or still have conflicts. In the printed list, U = unresolved and R = resolved.

Note that Mercurial will not let you commit files with unresolved merge conflicts. You must use hg resolve -m ... before you can commit after a conflicting merge.

Returns 0 on success, 1 if any files fail a resolve attempt.

options:

-a, --all select all unresolved files
-l, --list list state of files needing merge
-m, --mark mark files as resolved
-u, --unmark mark files as unresolved
-n, --no-status
 hide status prefix
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
revert [OPTION]... [-r REV] [NAME]...

NOTE: This command is most likely not what you are looking for. revert will partially overwrite content in the working directory without changing the working directory parents. Use hg update -r rev to check out earlier revisions, or hg update --clean . to undo a merge which has added another parent.

With no revision specified, revert the named files or directories to the contents they had in the parent of the working directory. This restores the contents of the affected files to an unmodified state and unschedules adds, removes, copies, and renames. If the working directory has two parents, you must explicitly specify a revision.

Using the -r/--rev option, revert the given files or directories to their contents as of a specific revision. This can be helpful to "roll back" some or all of an earlier change. See hg help dates for a list of formats valid for -d/--date.

Revert modifies the working directory. It does not commit any changes, or change the parent of the working directory. If you revert to a revision other than the parent of the working directory, the reverted files will thus appear modified afterwards.

If a file has been deleted, it is restored. If the executable mode of a file was changed, it is reset.

If names are given, all files matching the names are reverted. If no arguments are given, no files are reverted.

Modified files are saved with a .orig suffix before reverting. To disable these backups, use --no-backup.

Returns 0 on success.

options:

-a, --all revert all changes when no arguments given
-d, --date tipmost revision matching date
-r, --rev revert to the specified revision
--no-backup do not save backup copies of files
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns
-n, --dry-run do not perform actions, just print output
rollback

This command should be used with care. There is only one level of rollback, and there is no way to undo a rollback. It will also restore the dirstate at the time of the last transaction, losing any dirstate changes since that time. This command does not alter the working directory.

Transactions are used to encapsulate the effects of all commands that create new changesets or propagate existing changesets into a repository. For example, the following commands are transactional, and their effects can be rolled back:

  • commit
  • import
  • pull
  • push (with this repository as the destination)
  • unbundle

This command is not intended for use on public repositories. Once changes are visible for pull by other users, rolling a transaction back locally is ineffective (someone else may already have pulled the changes). Furthermore, a race is possible with readers of the repository; for example an in-progress pull from the repository may fail if a rollback is performed.

Returns 0 on success, 1 if no rollback data is available.

options:

-n, --dry-run do not perform actions, just print output
root

Print the root directory of the current repository.

Returns 0 on success.

serve [OPTION]...

Start a local HTTP repository browser and pull server. You can use this for ad-hoc sharing and browing of repositories. It is recommended to use a real web server to serve a repository for longer periods of time.

Please note that the server does not implement access control. This means that, by default, anybody can read from the server and nobody can write to it by default. Set the web.allow_push option to * to allow everybody to push to the server. You should use a real web server if you need to authenticate users.

By default, the server logs accesses to stdout and errors to stderr. Use the -A/--accesslog and -E/--errorlog options to log to files.

To have the server choose a free port number to listen on, specify a port number of 0; in this case, the server will print the port number it uses.

Returns 0 on success.

options:

-A, --accesslog
 name of access log file to write to
-d, --daemon run server in background
--daemon-pipefds
 used internally by daemon mode
-E, --errorlog name of error log file to write to
-p, --port port to listen on (default: 8000)
-a, --address address to listen on (default: all interfaces)
--prefix prefix path to serve from (default: server root)
-n, --name name to show in web pages (default: working directory)
--web-conf name of the hgweb config file (serve more than one repository)
--webdir-conf name of the hgweb config file (DEPRECATED)
--pid-file name of file to write process ID to
--stdio for remote clients
-t, --templates
 web templates to use
--style template style to use
-6, --ipv6 use IPv6 in addition to IPv4
--certificate SSL certificate file
showconfig [-u] [NAME]...

With no arguments, print names and values of all config items.

With one argument of the form section.name, print just the value of that config item.

With multiple arguments, print names and values of all config items with matching section names.

With --debug, the source (filename and line number) is printed for each config item.

Returns 0 on success.

options:

-u, --untrusted
 show untrusted configuration options

aliases: debugconfig

status [OPTION]... [FILE]...

Show status of files in the repository. If names are given, only files that match are shown. Files that are clean or ignored or the source of a copy/move operation, are not listed unless -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. Unless options described with "show only ..." are given, the options -mardu are used.

Option -q/--quiet hides untracked (unknown and ignored) files unless explicitly requested with -u/--unknown or -i/--ignored.

NOTE: status may appear to disagree with diff if permissions have changed or a merge has occurred. The standard diff format does not report permission changes and diff only reports changes relative to one merge parent.

If one revision is given, it is used as the base revision. If two revisions are given, the differences between them are shown. The --change option can also be used as a shortcut to list the changed files of a revision from its first parent.

The codes used to show the status of files are:

M = modified
A = added
R = removed
C = clean
! = missing (deleted by non-hg command, but still tracked)
? = not tracked
I = ignored
  = origin of the previous file listed as A (added)

Returns 0 on success.

options:

-A, --all show status of all files
-m, --modified show only modified files
-a, --added show only added files
-r, --removed show only removed files
-d, --deleted show only deleted (but tracked) files
-c, --clean show only files without changes
-u, --unknown show only unknown (not tracked) files
-i, --ignored show only ignored files
-n, --no-status
 hide status prefix
-C, --copies show source of copied files
-0, --print0 end filenames with NUL, for use with xargs
--rev show difference from revision
--change list the changed files of a revision
-I, --include include names matching the given patterns
-X, --exclude exclude names matching the given patterns

aliases: st

summary [--remote]

This generates a brief summary of the working directory state, including parents, branch, commit status, and available updates.

With the --remote option, this will check the default paths for incoming and outgoing changes. This can be time-consuming.

Returns 0 on success.

options:

--remote check for push and pull

aliases: sum

tag [-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...

Name a particular revision using <name>.

Tags are used to name particular revisions of the repository and are very useful to compare different revisions, to go back to significant earlier versions or to mark branch points as releases, etc.

If no revision is given, the parent of the working directory is used, or tip if no revision is checked out.

To facilitate version control, distribution, and merging of tags, they are stored as a file named ".hgtags" which is managed similarly to other project files and can be hand-edited if necessary. The file '.hg/localtags' is used for local tags (not shared among repositories).

See hg help dates for a list of formats valid for -d/--date.

Since tag names have priority over branch names during revision lookup, using an existing branch name as a tag name is discouraged.

Returns 0 on success.

options:

-f, --force replace existing tag
-l, --local make the tag local
-r, --rev revision to tag
--remove remove a tag
-e, --edit edit commit message
-m, --message use <text> as commit message
-d, --date record datecode as commit date
-u, --user record the specified user as committer
tags

This lists both regular and local tags. When the -v/--verbose switch is used, a third column "local" is printed for local tags.

Returns 0 on success.

tip [-p] [-g]

The tip revision (usually just called the tip) is the changeset most recently added to the repository (and therefore the most recently changed head).

If you have just made a commit, that commit will be the tip. If you have just pulled changes from another repository, the tip of that repository becomes the current tip. The "tip" tag is special and cannot be renamed or assigned to a different changeset.

Returns 0 on success.

options:

-p, --patch show patch
-g, --git use git extended diff format
--style display using template map file
--template display with template
unbundle [-u] FILE...

Apply one or more compressed changegroup files generated by the bundle command.

Returns 0 on success, 1 if an update has unresolved files.

options:

-u, --update update to new branch head if changesets were unbundled
update [-c] [-C] [-d DATE] [[-r] REV]

Update the repository's working directory to the specified changeset.

If no changeset is specified, attempt to update to the tip of the current branch. If this changeset is a descendant of the working directory's parent, update to it, otherwise abort.

The following rules apply when the working directory contains uncommitted changes:

  1. If neither -c/--check nor -C/--clean is specified, and if the requested changeset is an ancestor or descendant of the working directory's parent, the uncommitted changes are merged into the requested changeset and the merged result is left uncommitted. If the requested changeset is not an ancestor or descendant (that is, it is on another branch), the update is aborted and the uncommitted changes are preserved.
  2. With the -c/--check option, the update is aborted and the uncommitted changes are preserved.
  3. With the -C/--clean option, uncommitted changes are discarded and the working directory is updated to the requested changeset.

Use null as the changeset to remove the working directory (like hg clone -U).

If you want to update just one file to an older changeset, use hg revert.

See hg help dates for a list of formats valid for -d/--date.

Returns 0 on success, 1 if there are unresolved files.

options:

-C, --clean discard uncommitted changes (no backup)
-c, --check check for uncommitted changes
-d, --date tipmost revision matching date
-r, --rev revision

aliases: up checkout co

verify

Verify the integrity of the current repository.

This will perform an extensive check of the repository's integrity, validating the hashes and checksums of each entry in the changelog, manifest, and tracked files, as well as the integrity of their crosslinks and indices.

Returns 0 on success, 1 if errors are encountered.

version
output version and copyright information

Configuration Files

Mercurial reads configuration data from several files, if they exist. Below we list the most specific file first.

On Windows, these configuration files are read:

On Unix, these files are read:

If there is a per-repository configuration file which is not owned by the active user, Mercurial will warn you that the file is skipped:

not trusting file <repo>/.hg/hgrc from untrusted user USER, group GROUP

If this bothers you, the warning can be silenced (the file would still be ignored) or trust can be established. Use one of the following settings, the syntax is explained below:

The configuration files for Mercurial use a simple ini-file format. A configuration file consists of sections, led by a [section] header and followed by name = value entries:

[ui]
username = Firstname Lastname <firstname.lastname@example.net>
verbose = True

The above entries will be referred to as ui.username and ui.verbose, respectively. Please see the hgrc man page for a full description of the possible configuration values:

Date Formats

Some commands allow the user to specify a date, e.g.:

Many date formats are valid. Here are some examples:

Lastly, there is Mercurial's internal format:

This is the internal representation format for dates. unixtime is the number of seconds since the epoch (1970-01-01 00:00 UTC). offset is the offset of the local timezone, in seconds west of UTC (negative if the timezone is east of UTC).

The log command also accepts date ranges:

File Name Patterns

Mercurial accepts several notations for identifying one or more files at a time.

By default, Mercurial treats filenames as shell-style extended glob patterns.

Alternate pattern notations must be specified explicitly.

To use a plain path name without any pattern matching, start it with path:. These path names must completely match starting at the current repository root.

To use an extended glob, start a name with glob:. Globs are rooted at the current directory; a glob such as *.c will only match files in the current directory ending with .c.

The supported glob syntax extensions are ** to match any string across path separators and {a,b} to mean "a or b".

To use a Perl/Python regular expression, start a name with re:. Regexp pattern matching is anchored at the root of the repository.

Plain examples:

path:foo/bar   a name bar in a directory named foo in the root
               of the repository
path:path:name a file or directory named "path:name"

Glob examples:

glob:*.c       any name ending in ".c" in the current directory
*.c            any name ending in ".c" in the current directory
**.c           any name ending in ".c" in any subdirectory of the
               current directory including itself.
foo/*.c        any name ending in ".c" in the directory foo
foo/**.c       any name ending in ".c" in any subdirectory of foo
               including itself.

Regexp examples:

re:.*\.c$      any name ending in ".c", anywhere in the repository

Environment Variables

HG
Path to the 'hg' executable, automatically passed when running hooks, extensions or external tools. If unset or empty, this is the hg executable's name if it's frozen, or an executable named 'hg' (with %PATHEXT% [defaulting to COM/EXE/BAT/CMD] extensions on Windows) is searched.
HGEDITOR

This is the name of the editor to run when committing. See EDITOR.

(deprecated, use .hgrc)

HGENCODING
This overrides the default locale setting detected by Mercurial. This setting is used to convert data including usernames, changeset descriptions, tag names, and branches. This setting can be overridden with the --encoding command-line option.
HGENCODINGMODE
This sets Mercurial's behavior for handling unknown characters while transcoding user input. The default is "strict", which causes Mercurial to abort if it can't map a character. Other settings include "replace", which replaces unknown characters, and "ignore", which drops them. This setting can be overridden with the --encodingmode command-line option.
HGMERGE

An executable to use for resolving merge conflicts. The program will be executed with three arguments: local file, remote file, ancestor file.

(deprecated, use .hgrc)

HGRCPATH

A list of files or directories to search for hgrc files. Item separator is ":" on Unix, ";" on Windows. If HGRCPATH is not set, platform default search path is used. If empty, only the .hg/hgrc from the current repository is read.

For each element in HGRCPATH:

  • if it's a directory, all files ending with .rc are added
  • otherwise, the file itself will be added
HGPLAIN

When set, this disables any options in .hgrc that might change Mercurial's default output. This includes encoding, defaults, verbose mode, debug mode, quiet mode, tracebacks, and localization. This can be useful when scripting against Mercurial in the face of existing user configuration.

Equivalent options set via command line flags or environment variables are not overridden.

HGUSER

This is the string used as the author of a commit. If not set, available values will be considered in this order:

  • HGUSER (deprecated)
  • hgrc files from the HGRCPATH
  • EMAIL
  • interactive prompt
  • LOGNAME (with @hostname appended)

(deprecated, use .hgrc)

EMAIL
May be used as the author of a commit; see HGUSER.
LOGNAME
May be used as the author of a commit; see HGUSER.
VISUAL
This is the name of the editor to use when committing. See EDITOR.
EDITOR
Sometimes Mercurial needs to open a text file in an editor for a user to modify, for example when writing commit messages. The editor it uses is determined by looking at the environment variables HGEDITOR, VISUAL and EDITOR, in that order. The first non-empty one is chosen. If all of them are empty, the editor defaults to 'vi'.
PYTHONPATH
This is used by Python to find imported modules and may need to be set appropriately if this Mercurial is not installed system-wide.

Specifying Single Revisions

Mercurial supports several ways to specify individual revisions.

A plain integer is treated as a revision number. Negative integers are treated as sequential offsets from the tip, with -1 denoting the tip, -2 denoting the revision prior to the tip, and so forth.

A 40-digit hexadecimal string is treated as a unique revision identifier.

A hexadecimal string less than 40 characters long is treated as a unique revision identifier and is referred to as a short-form identifier. A short-form identifier is only valid if it is the prefix of exactly one full-length identifier.

Any other string is treated as a tag or branch name. A tag name is a symbolic name associated with a revision identifier. A branch name denotes the tipmost revision of that branch. Tag and branch names must not contain the ":" character.

The reserved name "tip" is a special tag that always identifies the most recent revision.

The reserved name "null" indicates the null revision. This is the revision of an empty repository, and the parent of revision 0.

The reserved name "." indicates the working directory parent. If no working directory is checked out, it is equivalent to null. If an uncommitted merge is in progress, "." is the revision of the first parent.

Specifying Multiple Revisions

When Mercurial accepts more than one revision, they may be specified individually, or provided as a topologically continuous range, separated by the ":" character.

The syntax of range notation is [BEGIN]:[END], where BEGIN and END are revision identifiers. Both BEGIN and END are optional. If BEGIN is not specified, it defaults to revision number 0. If END is not specified, it defaults to the tip. The range ":" thus means "all revisions".

If BEGIN is greater than END, revisions are treated in reverse order.

A range acts as a closed interval. This means that a range of 3:5 gives 3, 4 and 5. Similarly, a range of 9:6 gives 9, 8, 7, and 6.

Specifying Revision Sets

Mercurial supports a functional language for selecting a set of revisions.

The language supports a number of predicates which are joined by infix operators. Parenthesis can be used for grouping.

Identifiers such as branch names must be quoted with single or double quotes if they contain characters outside of [._a-zA-Z0-9\x80-\xff] or if they match one of the predefined predicates. Special characters can be used in quoted identifiers by escaping them, e.g., \n is interpreted as a newline.

There is a single prefix operator:

not x
Changesets not in x. Short form is ! x.

These are the supported infix operators:

x::y

A DAG range, meaning all changesets that are descendants of x and ancestors of y, including x and y themselves. If the first endpoint is left out, this is equivalent to ancestors(y), if the second is left out it is equivalent to descendants(x).

An alternative syntax is x..y.

x:y
All changesets with revision numbers between x and y, both inclusive. Either endpoint can be left out, they default to 0 and tip.
x and y
The intersection of changesets in x and y. Short form is x & y.
x or y
The union of changesets in x and y. There are two alternative short forms: x | y and x + y.
x - y
Changesets in x but not in y.

The following predicates are supported:

adds(pattern)
Changesets that add a file matching pattern.
all()
All changesets, the same as 0:tip.
ancestor(single, single)
Greatest common ancestor of the two changesets.
ancestors(set)
Changesets that are ancestors of a changeset in set.
author(string)
Alias for user(string).
branch(set)
The branch names are found for changesets in set, and the result is all changesets belonging to one those branches.
children(set)
Child changesets of changesets in set.
closed()
Changeset is closed.
contains(pattern)
Revision contains pattern.
date(interval)
Changesets within the interval, see hg help dates.
descendants(set)
Changesets which are decendants of changesets in set.
file(pattern)
Changesets which manually affected files matching pattern.
follow()
An alias for ::. (ancestors of the working copy's first parent).
grep(regex)
Like keyword(string) but accepts a regex.
head()
Changeset is a head.
heads(set)
Members of set with no children in set.
keyword(string)
Search commit message, user name, and names of changed files for string.
limit(set, n)
First n members of set.
max(set)
Changeset with highest revision number in set.
merge()
Changeset is a merge changeset.
modifies(pattern)
Changesets which modify files matching pattern.
outgoing([path])
Changesets missing in path.
p1(set)
First parent of changesets in set.
p2(set)
Second parent of changesets in set.
parents(set)
The set of all parents for all changesets in set.
removes(pattern)
Changesets which remove files matching pattern.
reverse(set)
Reverse order of set.
roots(set)
Changesets with no parent changeset in set.
sort(set[, [-]key...])

Sort set by keys. The default sort order is ascending, specify a key as -key to sort in descending order.

The keys can be:

  • rev for the revision number,
  • branch for the branch name,
  • desc for the commit message (description),
  • user for user name (author can be used as an alias),
  • date for the commit date
tagged()
Changeset is tagged.
user(string)
User name is string.

Command line equivalents for hg log:

-f    ->  ::.
-d x  ->  date(x)
-k x  ->  keyword(x)
-m    ->  merge()
-u x  ->  user(x)
-b x  ->  branch(x)
-P x  ->  !::x
-l x  ->  limit(expr, x)

Some sample queries:

hg log -r 'branch(default)'
hg log -r 'branch(default) and 1.5:: and not merge()'
hg log -r '1.3::1.5 and keyword(bug) and file("hgext/*")'
hg log -r 'sort(date("May 2008"), user)'
hg log -r '(keyword(bug) or keyword(issue)) and not ancestors(tagged())'

Diff Formats

Mercurial's default format for showing changes between two versions of a file is compatible with the unified format of GNU diff, which can be used by GNU patch and many other standard tools.

While this standard format is often enough, it does not encode the following information:

Mercurial also supports the extended diff format from the git VCS which addresses these limitations. The git diff format is not produced by default because a few widespread tools still do not understand this format.

This means that when generating diffs from a Mercurial repository (e.g. with hg export), you should be careful about things like file copies and renames or other things mentioned above, because when applying a standard diff to a different repository, this extra information is lost. Mercurial's internal operations (like push and pull) are not affected by this, because they use an internal binary format for communicating changes.

To make Mercurial produce the git extended diff format, use the --git option available for many commands, or set 'git = True' in the [diff] section of your hgrc. You do not need to set this option when importing diffs in this format or using them in the mq extension.

Template Usage

Mercurial allows you to customize output of commands through templates. You can either pass in a template from the command line, via the --template option, or select an existing template-style (--style).

You can customize output for any "log-like" command: log, outgoing, incoming, tip, parents, heads and glog.

Four styles are packaged with Mercurial: default (the style used when no explicit preference is passed), compact, changelog, and xml. Usage:

$ hg log -r1 --style changelog

A template is a piece of text, with markup to invoke variable expansion:

$ hg log -r1 --template "{node}\n"
b56ce7b07c52de7d5fd79fb89701ea538af65746

Strings in curly braces are called keywords. The availability of keywords depends on the exact context of the templater. These keywords are usually available for templating a log-like command:

author:String. The unmodified author of the changeset.
branches:String. The name of the branch on which the changeset was committed. Will be empty if the branch name was default.
date:Date information. The date when the changeset was committed.
desc:String. The text of the changeset description.
diffstat:String. Statistics of changes with the following format: "modified files: +added/-removed lines"
files:List of strings. All files modified, added, or removed by this changeset.
file_adds:List of strings. Files added by this changeset.
file_copies:List of strings. Files copied in this changeset with their sources.
file_copies_switch:
 List of strings. Like "file_copies" but displayed only if the --copied switch is set.
file_mods:List of strings. Files modified by this changeset.
file_dels:List of strings. Files removed by this changeset.
node:String. The changeset identification hash, as a 40-character hexadecimal string.
parents:List of strings. The parents of the changeset.
rev:Integer. The repository-local changeset revision number.
tags:List of strings. Any tags associated with the changeset.
latesttag:String. Most recent global tag in the ancestors of this changeset.
latesttagdistance:
 Integer. Longest path to the latest tag.

The "date" keyword does not produce human-readable output. If you want to use a date in your output, you can use a filter to process it. Filters are functions which return a string based on the input variable. Be sure to use the stringify filter first when you're applying a string-input filter to a list-like input variable. You can also use a chain of filters to get the desired output:

$ hg tip --template "{date|isodate}\n"
2008-08-21 18:22 +0000

List of filters:

addbreaks:Any text. Add an XHTML "<br />" tag before the end of every line except the last.
age:Date. Returns a human-readable date/time difference between the given date/time and the current date/time.
basename:Any text. Treats the text as a path, and returns the last component of the path after splitting by the path separator (ignoring trailing separators). For example, "foo/bar/baz" becomes "baz" and "foo/bar//" becomes "bar".
stripdir:Treat the text as path and strip a directory level, if possible. For example, "foo" and "foo/bar" becomes "foo".
date:Date. Returns a date in a Unix date format, including the timezone: "Mon Sep 04 15:13:13 2006 0700".
domain:Any text. Finds the first string that looks like an email address, and extracts just the domain component. Example: User <user@example.com> becomes example.com.
email:Any text. Extracts the first string that looks like an email address. Example: User <user@example.com> becomes user@example.com.
escape:Any text. Replaces the special XML/XHTML characters "&", "<" and ">" with XML entities.
fill68:Any text. Wraps the text to fit in 68 columns.
fill76:Any text. Wraps the text to fit in 76 columns.
firstline:Any text. Returns the first line of text.
nonempty:Any text. Returns '(none)' if the string is empty.
hgdate:Date. Returns the date as a pair of numbers: "1157407993 25200" (Unix timestamp, timezone offset).
isodate:Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 +0200".
isodatesec:Date. Returns the date in ISO 8601 format, including seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date filter.
localdate:Date. Converts a date to local date.
obfuscate:Any text. Returns the input text rendered as a sequence of XML entities.
person:Any text. Returns the text before an email address.
rfc822date:Date. Returns a date using the same format used in email headers: "Tue, 18 Aug 2009 13:00:13 +0200".
rfc3339date:Date. Returns a date using the Internet date format specified in RFC 3339: "2009-08-18T13:00:13+02:00".
short:Changeset hash. Returns the short form of a changeset hash, i.e. a 12-byte hexadecimal string.
shortdate:Date. Returns a date like "2006-09-18".
stringify:Any type. Turns the value into text by converting values into text and concatenating them.
strip:Any text. Strips all leading and trailing whitespace.
tabindent:Any text. Returns the text, with every line except the first starting with a tab character.
urlescape:Any text. Escapes all "special" characters. For example, "foo bar" becomes "foo%20bar".
user:Any text. Returns the user portion of an email address.

URL Paths

Valid URLs are of the form:

local/filesystem/path[#revision]
file://local/filesystem/path[#revision]
http://[user[:pass]@]host[:port]/[path][#revision]
https://[user[:pass]@]host[:port]/[path][#revision]
ssh://[user[:pass]@]host[:port]/[path][#revision]

Paths in the local filesystem can either point to Mercurial repositories or to bundle files (as created by hg bundle or :hg:` incoming --bundle`).

An optional identifier after # indicates a particular branch, tag, or changeset to use from the remote repository. See also hg help revisions.

Some features, such as pushing to http:// and https:// URLs are only possible if the feature is explicitly enabled on the remote Mercurial server.

Some notes about using SSH with Mercurial:

These URLs can all be stored in your hgrc with path aliases under the [paths] section like so:

[paths]
alias1 = URL1
alias2 = URL2
...

You can then use the alias for any command that uses a URL (for example hg pull alias1 will be treated as hg pull URL1).

Two path aliases are special because they are used as defaults when you do not provide the URL to a command:

default:
When you create a repository with hg clone, the clone command saves the location of the source repository as the new repository's 'default' path. This is then used when you omit path from push- and pull-like commands (including incoming and outgoing).
default-push:
The push command will look for a path named 'default-push', and prefer it over 'default' if both are defined.

Using additional features

Mercurial has the ability to add new features through the use of extensions. Extensions may add new commands, add options to existing commands, change the default behavior of commands, or implement hooks.

Extensions are not loaded by default for a variety of reasons: they can increase startup overhead; they may be meant for advanced usage only; they may provide potentially dangerous abilities (such as letting you destroy or modify history); they might not be ready for prime time; or they may alter some usual behaviors of stock Mercurial. It is thus up to the user to activate extensions as needed.

To enable the "foo" extension, either shipped with Mercurial or in the Python search path, create an entry for it in your hgrc, like this:

[extensions]
foo =

You may also specify the full path to an extension:

[extensions]
myfeature = ~/.hgext/myfeature.py

To explicitly disable an extension enabled in an hgrc of broader scope, prepend its path with !:

[extensions]
# disabling extension bar residing in /path/to/extension/bar.py
bar = !/path/to/extension/bar.py
# ditto, but no path was supplied for extension baz
baz = !

disabled extensions:

acl:hooks for controlling repository access
bookmarks:track a line of development with movable markers
bugzilla:hooks for integrating with the Bugzilla bug tracker
children:command to display child changesets
churn:command to display statistics about repository history
color:colorize output from some commands
convert:import revisions from foreign VCS repositories into Mercurial
eol:automatically manage newlines in repository files
extdiff:command to allow external programs to compare revisions
fetch:pull, update and merge in one command
gpg:commands to sign and verify changesets
graphlog:command to view revision graphs from a shell
hgcia:hooks for integrating with the CIA.vc notification service
hgk:browse the repository in a graphical way
highlight:syntax highlighting for hgweb (requires Pygments)
inotify:accelerate status report using Linux's inotify service
interhg:expand expressions into changelog and summaries
keyword:expand keywords in tracked files
mq:manage a stack of patches
notify:hooks for sending email notifications at commit/push time
pager:browse command output with an external pager
parentrevspec:interpret suffixes to refer to ancestor revisions
patchbomb:command to send changesets as (a series of) patch emails
progress:show progress bars for some actions
purge:command to delete untracked files from the working directory
rebase:command to move sets of revisions to a different ancestor
record:commands to interactively select changes for commit/qrefresh
relink:recreates hardlinks between repository clones
schemes:extend schemes with shortcuts to repository swarms
share:share a common history between several working directories
transplant:command to transplant changesets from another branch
win32mbcs:allow the use of MBCS paths with problematic encodings
win32text:perform automatic newline conversion
zeroconf:discover and advertise repositories on the local network

Configuring hgweb

Mercurial's internal web server, hgweb, can serve either a single repository, or a collection of them. In the latter case, a special configuration file can be used to specify the repository paths to use and global web configuration options.

This file uses the same syntax as hgrc configuration files, but only the following sections are recognized:

  • web
  • paths
  • collections

The web section can specify all the settings described in the web section of the hgrc documentation.

The paths section provides mappings of physical repository paths to virtual ones. For instance:

[paths]
projects/a = /foo/bar
projects/b = /baz/quux
web/root = /real/root/*
/ = /real/root2/*
virtual/root2 = /real/root2/**

The collections section provides mappings of trees of physical repositories paths to virtual ones, though the paths syntax is generally preferred. For instance:

[collections]
/foo = /foo

Here, the left side will be stripped off all repositories found in the right side. Thus /foo/bar and foo/quux/baz will be listed as bar and quux/baz respectively.

Glossary

Ancestor
Any changeset that can be reached by an unbroken chain of parent changesets from a given changeset. More precisely, the ancestors of a changeset can be defined by two properties: a parent of a changeset is an ancestor, and a parent of an ancestor is an ancestor. See also: 'Descendant'.
Branch

(Noun) A child changeset that has been created from a parent that is not a head. These are known as topological branches, see 'Branch, topological'. If a topological branch is named, it becomes a named branch. If a topological branch is not named, it becomes an anonymous branch. See 'Branch, anonymous' and 'Branch, named'.

Branches may be created when changes are pulled from or pushed to a remote repository, since new heads may be created by these operations. Note that the term branch can also be used informally to describe a development process in which certain development is done independently of other development.This is sometimes done explicitly with a named branch, but it can also be done locally, using bookmarks or clones and anonymous branches.

Example: "The experimental branch".

(Verb) The action of creating a child changeset which results in its parent having more than one child.

Example: "I'm going to branch at X".

Branch, anonymous
Every time a new child changeset is created from a parent that is not a head and the name of the branch is not changed, a new anonymous branch is created.
Branch, closed
A named branch whose branch heads have all been closed.
Branch, default
The branch assigned to a changeset when no name has previously been assigned.
Branch head
See 'Head, branch'.
Branch, inactive

If a named branch has no topological heads, it is considered to be inactive. As an example, a feature branch becomes inactive when it is merged into the default branch. The hg branches command shows inactive branches by default, though they can be hidden with hg branches --active.

NOTE: this concept is deprecated because it is too implicit. Branches should now be explicitly closed using hg commit --close-branch when they are no longer needed.

Branch, named

A collection of changesets which have the same branch name. By default, children of a changeset in a named branch belong to the same named branch. A child can be explicitly assigned to a different branch. See hg help branch, hg help branches and hg commit --close-branch for more information on managing branches.

Named branches can be thought of as a kind of namespace, dividing the collection of changesets that comprise the repository into a collection of disjoint subsets. A named branch is not necessarily a topological branch. If a new named branch is created from the head of another named branch, or the default branch, but no further changesets are added to that previous branch, then that previous branch will be a branch in name only.

Branch tip
See 'Tip, branch'.
Branch, topological
Every time a new child changeset is created from a parent that is not a head, a new topological branch is created. If a topological branch is named, it becomes a named branch. If a topological branch is not named, it becomes an anonymous branch of the current, possibly default, branch.
Changelog
A record of the changesets in the order in which they were added to the repository. This includes details such as changeset id, author, commit message, date, and list of changed files.
Changeset
A snapshot of the state of the repository used to record a change.
Changeset, child
The converse of parent changeset: if P is a parent of C, then C is a child of P. There is no limit to the number of children that a changeset may have.
Changeset id
A SHA-1 hash that uniquely identifies a changeset. It may be represented as either a "long" 40-byte hexadecimal string, or a "short" 12-byte hexadecimal string.
Changeset, merge
A changeset with two parents. This occurs when a merge is committed.
Changeset, parent
A revision upon which a child changeset is based. Specifically, a parent changeset of a changeset C is a changeset whose node immediately precedes C in the DAG. Changesets have at most two parents.
Checkout

(Noun) The working directory being updated to a specific revision. This use should probably be avoided where possible, as changeset is much more appropriate than checkout in this context.

Example: "I'm using checkout X."

(Verb) Updating the working directory to a specific changeset. See hg help update.

Example: "I'm going to check out changeset X."

Child changeset
See 'Changeset, child'.
Close changeset
See 'Changeset, close'.
Closed branch
See 'Branch, closed'.
Clone

(Noun) An entire or partial copy of a repository. The partial clone must be in the form of a revision and its ancestors.

Example: "Is your clone up to date?".

(Verb) The process of creating a clone, using hg clone.

Example: "I'm going to clone the repository".

Closed branch head
See 'Head, closed branch'.
Commit

(Noun) A synonym for changeset.

Example: "Is the bug fixed in your recent commit?"

(Verb) The act of recording changes to a repository. When files are committed in a working directory, Mercurial finds the differences between the committed files and their parent changeset, creating a new changeset in the repository.

Example: "You should commit those changes now."

Cset
A common abbreviation of the term changeset.
DAG
The repository of changesets of a distributed version control system (DVCS) can be described as a directed acyclic graph (DAG), consisting of nodes and edges, where nodes correspond to changesets and edges imply a parent -> child relation. This graph can be visualized by graphical tools such as hg glog (graphlog). In Mercurial, the DAG is limited by the requirement for children to have at most two parents.
Default branch
See 'Branch, default'.
Descendant
Any changeset that can be reached by a chain of child changesets from a given changeset. More precisely, the descendants of a changeset can be defined by two properties: the child of a changeset is a descendant, and the child of a descendant is a descendant. See also: 'Ancestor'.
Diff

(Noun) The difference between the contents and attributes of files in two changesets or a changeset and the current working directory. The difference is usually represented in a standard form called a "diff" or "patch". The "git diff" format is used when the changes include copies, renames, or changes to file attributes, none of which can be represented/handled by classic "diff" and "patch".

Example: "Did you see my correction in the diff?"

(Verb) Diffing two changesets is the action of creating a diff or patch.

Example: "If you diff with changeset X, you will see what I mean."

Directory, working
The working directory represents the state of the files tracked by Mercurial, that will be recorded in the next commit. The working directory initially corresponds to the snapshot at an existing changeset, known as the parent of the working directory. See 'Parent, working directory'. The state may be modified by changes to the files introduced manually or by a merge. The repository metadata exists in the .hg directory inside the working directory.
Graph
See DAG and hg help graphlog.
Head

The term 'head' may be used to refer to both a branch head or a repository head, depending on the context. See 'Head, branch' and 'Head, repository' for specific definitions.

Heads are where development generally takes place and are the usual targets for update and merge operations.

Head, branch
A changeset with no descendants on the same named branch.
Head, closed branch
A changeset that marks a head as no longer interesting. The closed head is no longer listed by hg heads. A branch is considered closed when all its heads are closed and consequently is not listed by hg branches.
Head, repository
A topological head which has not been closed.
Head, topological
A changeset with no children in the repository.
History, immutable
Once committed, changesets cannot be altered. Extensions which appear to change history actually create new changesets that replace existing ones, and then destroy the old changesets. Doing so in public repositories can result in old changesets being reintroduced to the repository.
History, rewriting
The changesets in a repository are immutable. However, extensions to Mercurial can be used to alter the repository, usually in such a way as to preserve changeset contents.
Immutable history
See 'History, immutable'.
Merge changeset
See 'Changeset, merge'.
Manifest
Each changeset has a manifest, which is the list of files that are tracked by the changeset.
Merge
Used to bring together divergent branches of work. When you update to a changeset and then merge another changeset, you bring the history of the latter changeset into your working directory. Once conflicts are resolved (and marked), this merge may be committed as a merge changeset, bringing two branches together in the DAG.
Named branch
See 'Branch, named'.
Null changeset
The empty changeset. It is the parent state of newly-initialized repositories and repositories with no checked out revision. It is thus the parent of root changesets and the effective ancestor when merging unrelated changesets. Can be specified by the alias 'null' or by the changeset ID '000000000000'.
Parent
See 'Changeset, parent'.
Parent changeset
See 'Changeset, parent'.
Parent, working directory
The working directory parent reflects a virtual revision which is the child of the changeset (or two changesets with an uncommitted merge) shown by hg parents. This is changed with hg update. Other commands to see the working directory parent are hg summary and hg id. Can be specified by the alias ".".
Patch

(Noun) The product of a diff operation.

Example: "I've sent you my patch."

(Verb) The process of using a patch file to transform one changeset into another.

Example: "You will need to patch that revision."

Pull
An operation in which changesets in a remote repository which are not in the local repository are brought into the local repository. Note that this operation without special arguments only updates the repository, it does not update the files in the working directory. See hg help pull.
Push
An operation in which changesets in a local repository which are not in a remote repository are sent to the remote repository. Note that this operation only adds changesets which have been committed locally to the remote repository. Uncommitted changes are not sent. See hg help push.
Repository
The metadata describing all recorded states of a collection of files. Each recorded state is represented by a changeset. A repository is usually (but not always) found in the .hg subdirectory of a working directory. Any recorded state can be recreated by "updating" a working directory to a specific changeset.
Repository head
See 'Head, repository'.
Revision
A state of the repository at some point in time. Earlier revisions can be updated to by using hg update. See also 'Revision number'; See also 'Changeset'.
Revision number
This integer uniquely identifies a changeset in a specific repository. It represents the order in which changesets were added to a repository, starting with revision number 0. Note that the revision number may be different in each clone of a repository. To identify changesets uniquely between different clones, see 'Changeset id'.
Revlog
History storage mechanism used by Mercurial. It is a form of delta encoding, with occasional full revision of data followed by delta of each successive revision. It includes data and an index pointing to the data.
Rewriting history
See 'History, rewriting'.
Root
A changeset that has only the null changeset as its parent. Most repositories have only a single root changeset.
Tip
The changeset with the highest revision number. It is the changeset most recently added in a repository.
Tip, branch
The head of a given branch with the highest revision number. When a branch name is used as a revision identifier, it refers to the branch tip. See also 'Branch, head'. Note that because revision numbers may be different in different repository clones, the branch tip may be different in different cloned repositories.
Update

(Noun) Another synonym of changeset.

Example: "I've pushed an update".

(Verb) This term is usually used to describe updating the state of the working directory to that of a specific changeset. See hg help update.

Example: "You should update".

Working directory
See 'Directory, working'.
Working directory parent
See 'Parent, working directory'.

Files

.hgignore
This file contains regular expressions (one per line) that describe file names that should be ignored by hg. For details, see hgignore(5).
.hgtags
This file contains changeset hash values and text tag names (one of each separated by spaces) that correspond to tagged versions of the repository contents.
/etc/mercurial/hgrc, $HOME/.hgrc, .hg/hgrc
This file contains defaults and configuration. Values in .hg/hgrc override those in $HOME/.hgrc, and these override settings made in the global /etc/mercurial/hgrc configuration. See hgrc(5) for details of the contents and format of these files.

Some commands (e.g. revert) produce backup files ending in .orig, if the .orig file already exists and is not tracked by Mercurial, it will be overwritten.

Bugs

Probably lots, please post them to the mailing list (see Resources below) when you find them.

See Also

hgignore(5), hgrc(5)

Author

Written by Matt Mackall <mpm@selenic.com>

Resources

Main Web Site: http://mercurial.selenic.com/

Source code repository: http://selenic.com/hg

Mailing list: http://selenic.com/mailman/listinfo/mercurial

Copying

Copyright (C) 2005-2010 Matt Mackall. Free use of this software is granted under the terms of the GNU General Public License version 2 or any later version.