Show Menu

Mercurial (Hg) Cheat Sheet by codeshane

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 fileBegin tracking changes
hg addrem­oveTrack new, forget missing
hg forget fileStop tracking file
hg remove fileStop tracking & del
hg copy file targetCopy file
hg move file targetMove file

These changes to Work must also be Committed to avoid data loss.

Hg - Work Directory Updates

hg update tipUpdate Work to match Tip
hg update -rREVUpdate Work to specified Revision
hg revertUndo all uncomm­itted changes

Hg - Work Status

hg diffLists tracked file changes
hg diff fileList changes to a file
hg statusLists 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/dirHistory of changesets
hg annotate fileWho changed what, when
hg pathsLists known remote Repos
hg headsList heads

hg diff -rREV -rREV
Shows differ­ences between REVs

Hg - Create a Local Repo

hg init WorkCreates ./.hg/ subfolder & Repo
hg addBegin 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 RemoteList changesets available
hg pullPull all new changesets into Local
hg pull -r RemotePull specified changesets into Local
-uAlso 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 RemotePush changesets to Remote
hg shareSync history with parent and siblings

Hg - Terminology

RepositoryRepo. Collection of Revisions.
RevisionRev. Commited changeset, by REV number.
ChangesetSet of Work changes saved as Diffs.
DiffChanges between files.
TagName for a specific Rev.
ParentImmediate ancestor of Rev or Work.
BranchChild of Rev.
MergeRev with two parents.
HeadLatest Rev in Branch.
TipLatest Rev in ANY Branch.
PatchAll Diffs between two Revs.
BundlePatch with permis­sions and rename support.

Hg - Help

hgBasic command list.
hg helpFull command list.
hg help commandDetailed help reference.

Hg - Command Line

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

Hg - Common Options

-rREVSpecify a Rev number (default parent.)
-yDon't prompt; pick each first option.
-qQuiet (supress output.)
-vVerbose (addit­ional detail)
-fForce (override reasonable warnings.)

Share This Cheat Sheet!

Favourited by 5 Members:

emansije Theosis petraeus CITguy arnoldobr


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!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.