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­me.zip
hg archive -rREV filena­me.t­ar.gz

Hg - Work Files and Tracking

hg add file Begin tracking changes
hg addrem­ove 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, De­leted,
Ig­nored, Mo­dified, Un­known


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
-u Also Update Working Directory

Hg - Union Merge

hg pull --force unrel­ate­d_p­roject
hg merge
hg commit

Powerful simpli­city! Use wisely.


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 - Terminology

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

Hg - Help

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

Hg - Command Line

hg command -opti­on... argume­nt...
requ­ired non-l­iteral reference

Hg - Common Options

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

Share This Cheat Sheet!

Favourited by 5 Members:

arnoldobr CITguy petraeus Theosis emansije


DaveChild DaveChild, 09:18 15 Aug 12

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

Isxek Isxek, 12:10 21 Aug 12

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

Shane Shane, 09:49 10 Sep 12

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! http://mercurial.selenic.com/wiki/ShareExtension

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.