Random Tech Thoughts

The title above is not random

Mercurial Notes for Git Users

Getting help

Book: Mercurial: The Definitive Guide

Common usage is like git:

hg cmd --option argument

Use hg help cmd or hg cmd --help to get detailed help information.

Note many Mercurial commands has preset aliases, and can be seen in the command help.

Git commands in Mercurial

Getting changes from remote repositories:

git fetch = hg pull
git pull = hg pull; hg update = hg pull -u

hg update will change the working copy to reflect the specific revision in the commit history.

Switching branches or checkout to specific version:

git checkout = hg update

To see which commit of our working copy is reflecting:

git log -n1 = hg parents

Note hg log will always show revision history of entire repository or files.

Branches

Mercurial has 2 models of branches:

  • Naming branches within one repository (this is the same as git’s branch model)

    git branch = hg branches
    git checkout -b newbranch ~= hg branch newbranch
    git checkout newbranch = hg update newbranch
    
  • Use separate repositories for different branches. When using this model, it’s somewhat like working with multiple users working on a same project.