De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page Mercurial et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%



Mercurial is a distributed (decentralized), fast and secure Source Code Management system. Many pages compare Git and Mercurial, and in practice there are very similar for an ordinary user. This page, for example, compares Git to McGyver, and Mercurial to James Bond, in the sense that Git consists of a large number of tools, whereas Mercurial consists of just one extremely efficient executable which can realize the same tasks.


Contrary to the tools CVS and SVN, but similar to Git, Mercurial works in a distributed fashion (decentralized). This means that developers are not dependent on a central depository to store any changes. Each Git repository contains the history of the complete working tree. Each object (modification, file, directory) corresponds to a leaf of a tree with multiple branches. Developing a project with Mercurial is based on a model where a branch corresponds to a certain feature. Multiple interations of a feature branch can be archived before it is merged with the common trunk. For a detailed explanation of development models using branches, we recommend this page. This pages is based on Git, but the fundamental principles remain valid for Mercurial.

Basic usage

Generally, a project developer must be able to:

  1. clone or create the repository;
  2. make changes;
  3. commit changes;
  4. push changes toward the original repository.

Since Git is distributed, there may not be an authoritative repository.

Summary of commands

Basic commands
Command Description
hg init Create a new repository
hg clone Clone an existing repository
hg add Add a file or a directory to the index
hg rm Remove a file or a directory from the index
hg commit Save your modifications
hg push Propagate your saved modifications to another repository
hg pull Retrieve data from another repository without applying the changes to yours
hg pull -u Retrieve data from another repository and apply the changes to yours
hg update Apply the changes that where retrieved to the local repository
hg merge Merge the changes
hg rollback Erase the effect of the last (and only the last) set of saved changes

Commands to see changes
Command Description
hg annotate Discover the origin of each modification
hg log View the log (history) of changes
hg diff View differences between two versions
hg status Show the status of the files in the repository

Commands for branches, tags and remote repositories
Command Description
hg branch Manage development branches
hg tag Manage version tags
hg update branch Move to a named branch
hg update -C Update the local repository removing all local modifications

Commands for patches
Command Description
hg export revision > file Create a patch
hg import fichier Apply a patch to the current branch

Creating of cloning a repository

To get started, it is possible to create your own repository or to clone an existing repository.

Creating a repository:

[name@server $]  hg init my-project

Cloning a repository:

[name@server $]  hg clone

Commiting a change

When the repository is ready, you change directory and edit the file

 [name@server $] cd my-project
 [name@server $] nano file.txt

When work is done, you add the file:

[name@server $]  hg add file.txt

and commit the change

[name@server $]  hg commit

It is then possible to push changes to the originating repository with:

[name@server $]  hg push

Hosting Mercurial repositories

Bitbucket is one of the main Mercurial hosting services that is commercially available. This page provides a list of sites that host Mercurial repositories.

Outils personnels
Espaces de noms

Ressources de Calcul Québec