LinuxCommandLibrary

hg-update

Update working directory to a specific revision

TLDR

Update to the tip of the current branch

$ hg update
copy

Update to the specified revision
$ hg update [[-r|--rev]] [revision]
copy

Update and discard uncommitted changes
$ hg update [[-C|--clean]]
copy

Update to the last commit matching a specified date
$ hg update [[-d|--date]] [dd-mm-yyyy]
copy

SYNOPSIS

hg update [-C] [-c] [-d DATE] [-r REV] [REVISION]

PARAMETERS

-C, --clean
    discard uncommitted changes (no backup)

-c, --check
    abort if working directory is not clean

-d, --date DATE
    tip revision matching date (YYYY-MM-DD format)

-r, --rev REV
    revision to update to (hash, tag, or branch)

-m, --merge
    deprecated: update to merge revision parent

-I, --include PATTERN
    include paths matching glob patterns

-X, --exclude PATTERN
    exclude paths matching glob patterns

-q, --quiet
    suppress output

-v, --verbose
    enable verbose output

DESCRIPTION

The hg update (or hg up, hg checkout) command in Mercurial synchronizes the working directory with a specific changeset or the tip of the current branch. It is essential for switching branches, checking out historical revisions, or pulling latest changes into the local copy.

By default, without arguments, it updates to the latest revision on the current branch. Use -r REV to specify a revision by hash, tag, or branch name. It merges changes if possible but warns about uncommitted modifications. The --clean option discards local changes irreversibly, while --check prevents updates if the directory is dirty.

This command does not fetch remote changes; pair it with hg pull first. It supports date-based updates via --date and pattern-based includes/excludes for selective updates. Ideal for developers navigating repositories without committing.

CAVEATS

Irreversible with --clean; always commit or shelve changes first. Does not fetch remotes—use hg pull beforehand. May fail on divergent branches without merge.

ALIASES

Supports up, checkout, co as shortcuts.

STATUS CODES

Exits 0 on success, 1 on clean abort, 10+ on errors like missing revision.

HISTORY

Introduced in Mercurial 0.9b (2005) by Matt Mackall. Evolved with branch support in 0.9.3, clean/check options in 1.0 (2008). Remains core in modern versions like 6.x.

SEE ALSO

hg(1), hg-pull(1), hg-merge(1), git-checkout(1)

Copied to clipboard