Skip to main content

Mercurial Support

Learn Git Branching supports Mercurial (hg) commands as an alternative to Git. Mercurial commands are internally translated to Git operations, allowing you to practice similar version control concepts with different syntax.
Most Mercurial commands use delegation - they translate to equivalent Git commands behind the scenes.

Core Commands

hg commit / hg ci

Description: Record changes to the repository Regex: /^hg +(commit|ci)($|\s)/ Delegates to: git commit Options:
--amend
flag
Modify the most recent commit
-A
flag
Stage all files (shows warning that this is automatic)
-m
string
Set the commit message
Examples:
hg commit                     # Create new commit
hg ci                         # Short form
hg commit --amend             # Modify last commit
hg commit -m "Add feature"    # Commit with message
hg commit -A                  # Stage all (shows warning)

hg update / hg up

Description: Update working directory to specified revision Regex: /^hg +(update|up)($|\s+)/ Delegates to: git checkout Options:
-r
string
Specify revision to update to
Examples:
hg update main                # Update to main bookmark
hg up -r 5                    # Update to revision 5
hg update .                   # Current revision (no-op)

hg bookmark / hg book

Description: Create or list bookmarks (similar to Git branches) Regex: /^hg (bookmarks|bookmark|book)($|\s)/ Delegates to: git branch or git checkout Options:
-r
string
Create bookmark at specific revision
-f
flag
Force move bookmark
-d
string
Delete bookmark
Examples:
hg bookmark                   # List bookmarks
hg bookmark feature           # Create and switch to feature
hg bookmark -r 3 stable       # Create stable at revision 3
hg bookmark -d feature        # Delete feature bookmark
Translation:
  • Without args → git branch (list)
  • With name → git checkout -b <name> (create and switch)
  • With -rgit branch <name> <rev> (create at revision)
  • With -dgit branch -D <name> (delete)

History Modification

hg rebase

Description: Move changesets to a different parent Regex: /^hg +rebase($|\s+)/ Options:
-d
string
Destination revision
-s
string
Source revision
-b
string
Base revision (defaults to . - current)
Examples:
hg rebase -d main             # Rebase current onto main
hg rebase -d main -b feature  # Rebase feature onto main
Note: Requires both -d (destination) and optionally -b (base). Uses custom engine.hgRebase() implementation.

hg histedit

Description: Interactively edit revision history Regex: /^hg +histedit($|\s+)/ Delegates to: git rebase -i Examples:
hg histedit 3                 # Interactive edit from revision 3
Translation: Converts to git rebase -i <revision>

hg graft

Description: Copy changesets from another branch Regex: /^hg +graft($|\s)/ Delegates to: git cherry-pick Options:
-r
string
Specify revision to graft
Examples:
hg graft -r 3                 # Graft revision 3
hg graft -r 5 -r 7            # Graft multiple revisions
Translation: Converts -r options to git cherry-pick arguments.

hg backout

Description: Reverse the effects of a changeset Regex: /^hg +backout($|\s+)/ Delegates to: git revert Options:
-r
string
Revision to back out
Examples:
hg backout -r 3               # Back out revision 3

Remote Operations

hg pull

Description: Pull changes from another repository Regex: /^hg +pull($|\s+)/ Delegates to: git pull Examples:
hg pull                       # Pull from default remote

Information Commands

hg status / hg st

Description: Show working directory status Regex: /^hg +(status|st) *$/ Golf: Does not count for golf scoring Note: Throws error message that status is not implemented.
hg status                     # Not functional
hg st                         # Not functional

hg log

Description: Show revision history Regex: /^hg +log($|\s)/ Delegates to: git log Golf: Does not count for golf scoring Options:
-f
flag
Follow history (required)
Examples:
hg log -f                     # Show history (must use -f)
Note: The -f flag is required. Without it, throws an error. The . (dot) is mapped to HEAD.

hg export

Description: Export changesets as patches Regex: /^hg +export($|\s)/ Delegates to: git show Golf: Does not count for golf scoring Examples:
hg export .                   # Export current changeset
hg export 3                   # Export revision 3
Translation: The . (dot) is mapped to HEAD before delegating to git show.

hg summary / hg sum

Description: Summarize working directory state Regex: /^hg +(summary|sum) *$/ Delegates to: git branch Examples:
hg summary                    # Show summary
hg sum                        # Short form

Special Mercurial Syntax

Dot Notation

Mercurial uses . to refer to the current working directory parent (similar to HEAD in Git):
hg update .                   # Stay at current revision
hg log -f                     # . is implied and mapped to HEAD
hg export .                   # Export current changeset
Translation: The . is automatically converted to HEAD when delegating to Git commands.

Revision Numbers

Mercurial traditionally uses sequential revision numbers (0, 1, 2, 3…). In Learn Git Branching:
  • Revision numbers are accepted as commit identifiers
  • They map to commit IDs (C0, C1, C2, etc.)
hg update -r 3                # Updates to the 3rd commit
hg bookmark -r 5 feature      # Creates bookmark at 5th commit

Command Delegation Flow

Mercurial commands follow this delegation process:
  1. Parse - Command matches Mercurial regex pattern
  2. Transform - Options and arguments are transformed:
    • .HEAD
    • -r arguments extracted and repositioned
    • Option names mapped (e.g., -d-D for delete)
  3. Delegate - Transformed command passed to Git command handler
  4. Execute - Git command executes with transformed parameters

Example: hg bookmark -r 3 feature

1. Parse: Matches /^hg (bookmarks|bookmark|book)($|\s)/
2. Transform:
   - Extract -r value: "3"
   - Extract branch name: "feature"
   - Create Git args: ["feature", "3"]
3. Delegate: {vcs: 'git', name: 'branch'}
4. Execute: git branch feature 3

Unsupported Mercurial Features

Some Mercurial features are not supported:
  • Mercurial phases (public, draft, secret)
  • MQ (Mercurial Queues)
  • Mercurial bundles
  • Subrepos
  • File-level operations

Golf Scoring

These Mercurial commands don’t count toward Golf Mode scores:
  • hg status / hg st
  • hg log
  • hg export
All other Mercurial commands count normally for golf scoring.

Terminology Mapping

MercurialGitDescription
ChangesetCommitA single change to the repository
BookmarkBranchA movable pointer to a commit
RevisionCommit IDIdentifier for a changeset
.HEADCurrent working directory parent
UpdateCheckoutSwitch to a different revision
GraftCherry-pickCopy changes from another branch
BackoutRevertReverse changes from a commit

Getting Help

For help with Mercurial commands:
show commands                 # List all commands (including hg)
hg help                       # Not implemented, use show commands

See Also

Git Commands

Complete Git command reference

Special Commands

Learn Git Branching specific commands

Build docs developers (and LLMs) love