hg
Manage Mercurial version control repositories
TLDR
Create an empty Mercurial repository
Clone a remote Mercurial repository from the internet
View the status of a local repository
Add all new files to the next commit
Commit changes to version history
Push local changes to a remote repository
Pull any changes made to a remote
Reset everything the way it was in the latest commit
SYNOPSIS
hg [OPTION]... [COMMAND] [ARGS]...
PARAMETERS
-R, --repository
Repository root directory; follows all other arguments
--cwd
Change working directory before command execution
-r, --rev
Revision identifier; repeatable for multiple revs
--config
Override config option; repeatable
-q, --quiet
Suppress non-critical output
-v, --verbose
Enable additional output
--debug
Enable debug logging
--traceback
Print Python traceback on errors
--encoding
Set console encoding
--version
Display version info and exit
-h, --help
Show help; hg help COMMAND for specifics
DESCRIPTION
hg is the command-line interface for Mercurial, a free, distributed source control management tool designed for efficiency and scalability. Written primarily in Python, it excels at handling projects of any size, from small personal repos to massive codebases.
Key strengths include:
• Decentralized workflow: Full clones enable offline commits, branches, and merges without a central server.
• Performance: Uses revlog format for fast operations, compression, and minimal bandwidth for changesets.
• Branching model: Supports named branches, anonymous heads, bookmarks, and phases for change control.
• Extensibility: Rich extension system (e.g., mq for patches, bisect for debugging, largefiles for binaries).
A typical repo lives in a directory with a .hg subdirectory storing metadata. Workflows mirror Git: clone, edit, add, commit, push/pull. It integrates with SSH, HTTP, and bundle files for sharing. Mercurial emphasizes simplicity and safety with features like pre-commit hooks and rollback.
While powerful, it shines in environments needing fine-grained history and reproducible builds. Modern versions support evolve for safe mutable history.
CAVEATS
hg requires Mercurial installation (not coreutils); disk usage grows with clones. Binary files need largefiles extension. Mutable history risky without evolve.
COMMON SUBCOMMANDS
hg init: Create new repo.
hg clone URL: Copy repo.
hg status: Show changes.
hg commit: Save changes.
hg log: View history.
hg push/pull: Exchange changesets.
CONFIG FILES
Global: ~/.hgrc; Repo: .hg/hgrc. Set username, paths.default, etc.
HISTORY
Created by Matt Mackall in April 2005 as BitKeeper alternative. First release 0.9b (June 2005), stable 1.0 (2007). Used by Mozilla, NetBSD; peaked pre-Git dominance.


