Mercurial

Create a Local Repository

hg init .

Create a mercurial repository of current directory with a .hg/ folder

hg add filename1 filename2

Begin tracking filename1 and filename2 in mercurial

hg commit -m 'Initial commit'

Save files and commit message to repository

Clone Remote Repository

hg clone remote-repo [local-directory]

Clone a remote mercurial repository to a local directory

Update from Remote Repository

hg incoming [remote-repo]

List changesets available

hg pull

Pull all new changesets into local

hg pull -r remote-repo

Pull specified changesets into local

-u

Option: also update working directory

Merge

hg merge

Merge changesets to local repository

hg merge branchname_or_revision

Merge from a named branch or revision into the current local branch

hg resolve --mark filename

Inform mercurial about the resolution of merge conflicts

hg commit

After successful merge, commit the changes

Undos and Fixes

hg rollback

Undo commit, import, pull, local push or unbundle

Only use in private repositories.

hg update --clean

Cancel an uncomm­itted merge and lose changes

hg revert

Undo all uncomm­itted changes

Create an Archive

hg archive

Create an archive

Example args: -rREV filena­me.zip or -rREV filena­me.t­ar.gz

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 & delete

hg copy file target

Copy file

hg move file target

Move file

These changes must also be committed to avoid data loss.

Work Directory Updates

hg update tip

Update work to match tip

hg update -rREV

Update work to specified revision

Work Status

hg diff

List tracked file changes

hg diff file

List changes to a file

hg status

List status of files

Added, Clean, De­leted, Ig­nored, Mo­dified or Un­known

Local Repository History

hg serve

Fire up a builtin local webserver for browsing and sharing repository over HTTP

hg log file/dir

History of changesets

hg annotate file

Who changed what, when

hg paths

List known remote repositories

hg heads

List heads

hg parents

Before merge, you can look up the parents of the branch

hg diff -rREV -rREV

Show differ­ences between REVs

Remote Update and Publish

hg push [remote-repo]

Push changesets to remote

hg share

Sync history with parent and siblings

Terminology

Repository

Collection of revisions

hgrc

A file which stores defaults for a repository. Global is ~/.hgrc and local is .hgrc inside the repository

revision

Committed changeset, by REV number

changeset

Set of work changes saved as diffs

diff

Changes between files

tag

Name for a specific revision

parent(s)

Immediate ancestor(s) of revision or work

branch

Child of a revision

head

A head is a changeset with no child changesets

merge

The process of merging two HEADS

tip

Latest revision in any branch

patch

All diffs between two revisions

bundle

Patch with permis­sions and rename support

Help and Usage

hg

Basic command list

hg help

Full command list

hg help command

Detailed help reference

hg command

-opti­on... argume­nt...

Common Options

-rREV

Specify a REV number (default parent)

-y

Do not prompt, pick each first option

-q

Quiet (supress output)

-v

Verbose (addit­ional detail)

-f

Force (override reasonable warnings)

Notes