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:
Modify the most recent commit
Stage all files (shows warning that this is automatic)
Set the commit message
hg update / hg up
Description: Update working directory to specified revision Regex:/^hg +(update|up)($|\s+)/
Delegates to: git checkout
Options:
Specify revision to update to
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:
Create bookmark at specific revision
Force move bookmark
Delete bookmark
- Without args →
git branch(list) - With name →
git checkout -b <name>(create and switch) - With
-r→git branch <name> <rev>(create at revision) - With
-d→git branch -D <name>(delete)
History Modification
hg rebase
Description: Move changesets to a different parent Regex:/^hg +rebase($|\s+)/
Options:
Destination revision
Source revision
Base revision (defaults to
. - current)-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:
git rebase -i <revision>
hg graft
Description: Copy changesets from another branch Regex:/^hg +graft($|\s)/
Delegates to: git cherry-pick
Options:
Specify revision to graft
-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:
Revision to back out
Remote Operations
hg pull
Description: Pull changes from another repository Regex:/^hg +pull($|\s+)/
Delegates to: git pull
Examples:
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 log
Description: Show revision history Regex:/^hg +log($|\s)/
Delegates to: git log
Golf: Does not count for golf scoring
Options:
Follow history (required)
-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:
. (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:
Special Mercurial Syntax
Dot Notation
Mercurial uses. to refer to the current working directory parent (similar to HEAD in Git):
. 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.)
Command Delegation Flow
Mercurial commands follow this delegation process:- Parse - Command matches Mercurial regex pattern
- Transform - Options and arguments are transformed:
.→HEAD-rarguments extracted and repositioned- Option names mapped (e.g.,
-d→-Dfor delete)
- Delegate - Transformed command passed to Git command handler
- Execute - Git command executes with transformed parameters
Example: hg bookmark -r 3 feature
Unsupported Mercurial Features
Golf Scoring
These Mercurial commands don’t count toward Golf Mode scores:hg status/hg sthg loghg export
Terminology Mapping
| Mercurial | Git | Description |
|---|---|---|
| Changeset | Commit | A single change to the repository |
| Bookmark | Branch | A movable pointer to a commit |
| Revision | Commit ID | Identifier for a changeset |
. | HEAD | Current working directory parent |
| Update | Checkout | Switch to a different revision |
| Graft | Cherry-pick | Copy changes from another branch |
| Backout | Revert | Reverse changes from a commit |
Getting Help
For help with Mercurial commands:See Also
Git Commands
Complete Git command reference
Special Commands
Learn Git Branching specific commands