Home > Just Learnt Something New (JLSN) > JLSN – Basic Mercurial usage

JLSN – Basic Mercurial usage

I have been using Subversion for a long time for version control but I wanted to learn something new. So picked Mercurial since some guys I know seem to love it. As usual I am just keeping this here for future reference. One thing I learnt was not to try to map svn commands to hg commands. I just approached this like someone who has never used a version control system before. My notes below

# Copy existing repository
# Over the network use the url
$hg clone http://hg.serpentine.com/tutorial/hello

# Always a good idea to keep a copy of the original repository
$hg clone hello my-hello
$cd my-hello

# Give a view of the history of changes in the repository
$hg log

# View a specific revision
$hg log -r 3
$hg log -r 1 -r 4
$hg log -r 2:4
$hg log -r 4:2

# More verbose log
$hg log -v r 3

# Get the description and content of the change.
$hg log -v -p -r 2

# Add a new line to hello.c
printf("Hello again\n");

# What does Mercurial know about the files in the repository
$hg status

# See what has changed
$hg diff
$ cd ../
$hg clone hello hello-pull

# How to pull changes in another repository(my-hello) into yours(hello-pull)
$cd hello-pull
$hg pull ../my-hello

# To pull specific changes specify the revision number or the change set number
# NB Pull does not make changes. It just tells you what has been changed.
# Update the working directory to the state it was in at any revision in the 
# history of the reposity. If no revision is specified it updates tip.
$hg update 
$hg update -r2
$hg update tip

# To pull and update tip
$hg pull -u

# To find out what revision the working directory is at
$hg parents

# Pushing changes from your repository (my-hello) 
# to another repository (hello-push)
$cd ..
$hg clone hello hello-push
$cd my-hello

# Find out what changes will be pushed to the other repository
$hg outgoing ../hello-push

# Do the actual push
$hg push

# NB. Not possible to update the working directory in the repository being pushed.
# One reason could be that someone is working on some stuff and you updating 
# their stuff will not be fun.

# To start a new project
$cd ..
$hg init myproject
$less goodbye.c
#include <stdio.h>

int main(){
    return 0;

$mv goodbye.c myproject/
$hg add
$hg status
$hg commit -m "Initial Commit"
$hg log

Mercurial: The Definitive Guide by Bryan O’Sullivan

Also read:

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: