LinuxCommandLibrary

hg

Manage Mercurial version control repositories

TLDR

Create an empty Mercurial repository

$ hg init
copy

Clone a remote Mercurial repository from the internet
$ hg clone [https://example.com/repo]
copy

View the status of a local repository
$ hg status
copy

Add all new files to the next commit
$ hg add
copy

Commit changes to version history
$ hg commit [[-m|--message]] [message_text]
copy

Push local changes to a remote repository
$ hg push
copy

Pull any changes made to a remote
$ hg pull
copy

Reset everything the way it was in the latest commit
$ hg update [[-C|--clean]]; hg purge
copy

SYNOPSIS

hg [global-options] command [command-options] [arguments]

PARAMETERS

--help, -h
    Show help message for a command or global options.

--verbose, -v
    Enable verbose output, showing more details of operations.

--quiet, -q
    Suppress output, showing only critical messages.

--repository REPO, -R REPO
    Operate on the specified repository instead of the current working directory's repository.

--config SECTION.NAME=VALUE
    Set or override a configuration option for the current command execution.

--cwd DIR
    Run the command as if the current working directory were DIR.

--noninteractive
    Disable interactive prompts, useful for scripting.

--version
    Show Mercurial version information and exit.

DESCRIPTION

hg is the command-line interface for Mercurial, a powerful, distributed revision control system (DVCS). Designed for speed and scalability, Mercurial efficiently manages source code and tracks changes in projects of any size.
It allows developers to maintain local repositories, providing full history and enabling offline work. Key features include robust branching and merging capabilities, strong data integrity, and a user-friendly command set. It supports various development workflows, from centralized to fully distributed, and is often praised for its simplicity and clear command structure compared to other DVCS tools. Written primarily in Python, hg provides a reliable and flexible solution for version control, widely used in open-source and commercial projects.

CAVEATS

Mercurial commands are numerous and context-dependent; each subcommand (e.g., clone, commit, pull) possesses its own set of unique options and arguments, which are not exhaustively listed here. Users should consult hg help <command> for specific command details. While generally user-friendly, understanding core distributed version control concepts is beneficial for effective use. Mercurial's strong emphasis on repository integrity means some operations might seem more restrictive compared to other DVCS tools.

KEY CONCEPTS & WORKFLOWS

Mercurial operates on a distributed model, where every clone is a full repository. Common workflows include cloning (hg clone), pulling changes from others (hg pull), updating your working copy (hg update), committing local changes (hg commit), and pushing changes to other repositories (hg push). It provides powerful tools for branching (named branches, bookmarks) and merging changesets. Extensions (hg help extensions) significantly expand its functionality, offering features like rebase, largefiles support, and more.

HISTORY

Mercurial was created by Matt Mackall in 2005, primarily as a free and open-source alternative to BitKeeper, following changes in its licensing model that affected the Linux kernel development. Developed mainly in Python, with performance-critical parts in C, it quickly gained popularity as a robust and scalable distributed version control system. Its development emphasized simplicity, strong data integrity, and efficient handling of large repositories, leading to its adoption by significant projects like Mozilla for Firefox development and previously OpenSolaris. Mercurial continues to be actively maintained and used, offering a reliable choice for version control.

SEE ALSO

git(1), svn(1)

Copied to clipboard