Show Menu

Mercurial (Hg) Cheat Sheet by

Cheat Sheet for the Mercurial distributed source version control management tool. System.

Hg - Work Directory

A local Work folder containing one Revision and any uncommited changes you've made.

Hg - Undos and Fixes

hg rollback can undo commit, import, pull, local push, and unbundle. Only use in private repos.
hg update --clean can cancel an uncomm­itted merge while losing changes.

Hg - Create an Archive

hg archive -rREV filena­
hg archive -rREV filena­me.t­ar.gz

Hg - Work Files and Tracking

hg add file
Begin tracking changes
hg addremove
Track new, forget missing
hg forget file
Stop tracking file
hg remove file
Stop tracking & del
hg copy file target
Copy file
hg move file target
Move file
These changes to Work must also be Committed to avoid data loss.

Hg - Work Directory Updates

hg update tip
Update Work to match Tip
hg update -rREV
Update Work to specified Revision
hg revert
Undo all uncomm­itted changes

Hg - Work Status

hg diff
Lists tracked file changes
hg diff file
List changes to a file
hg status
Lists status of files
Added, Clean, Deleted,
Ignored, Modified, Unknown

Hg - Local Repository

A complete Local repository of changesets that is saved in Work/.hg/ (don't edit!)

Hg - Local Repo History

hg log file/dir
History of changesets
hg annotate file
Who changed what, when
hg paths
Lists known remote Repos
hg heads
List heads
hg diff -rREV -rREV
Shows differ­ences between REVs

Hg - Create a Local Repo

hg init Work
Creates ./.hg/ subfolder & Repo
hg add
Begin tracking all files
hg commit -m 'Initial commit'
Save files and Commit message to Repo

Hg - Clone Remote Repo

hg clone Remote Work

Hg - Update from Remote Repo

hg incoming Remote
List changesets available
hg pull
Pull all new changesets into Local
hg pull -r Remote
Pull specified changesets into Local
Also Update Working Directory

Hg - Union Merge

hg pull --force unrela­ted­_pr­oject
hg merge
hg commit
Powerful simpli­city! Use wisely.

Hg - Resources


Hg - Remote Repository

A Remote repository reached via url path, often a main team repo from which Local is cloned.

Hg - Remote Update and Publish

hg push Remote
Push changesets to Remote
hg share
Sync history with parent and siblings

Hg - Termin­ology

Repo. Collection of Revisions.
Rev. Commited changeset, by REV number.
Set of Work changes saved as Diffs.
Changes between files.
Name for a specific Rev.
Immediate ancestor of Rev or Work.
Child of Rev.
Rev with two parents.
Latest Rev in Branch.
Latest Rev in ANY Branch.
All Diffs between two Revs.
Patch with permis­sions and rename support.

Hg - Help

Basic command list.
hg help
Full command list.
hg help command
Detailed help reference.

Hg - Command Line

hg command -option... argume­nt...
required non-li­teral reference

Hg - Common Options

Specify a Rev number (default parent.)
Don't prompt; pick each first option.
Quiet (supress output.)
Verbose (addit­ional detail)
Force (override reasonable warnings.)


Wow! Great cheat sheet! :)

codeshane codeshane, 09:48 15 Aug 12

Thanks. Plenty of room for improvement, but getting started is the hardest part. :D

Does "hg share" require an extension? Running "hg help share" gets me the "unknown command" error.

Sorry for the late reply, wasn't expecting a Q&A here .. the "share" extension is included with Hg, but disabled by default. The link below explainshow to set it up, hope it helps!

Can't start download. is referring back to :(

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Subversion Cheat Sheet
          VI Editor Cheat Sheet
          Bazaar version control system Cheat Sheet