Introduction to Mercurial
Here I introduce a very basic use of Mercurial version control system (named Hg). Let’s say that we are working on a document in LaTeX (a PhD dissertation, and article/paper, a report etc). First it is based on a local directory but we want to be able to track all the changes on the text (the evolution of the document). I recommend a this point to read the previous post about version control where is explained the basic terminology. So we are going to create a repository of Hg.
Just typing Hg we have the main commands of our hg version. In my case,
Now to create a repository in our directory we just write:
ls -a command we can certificate that there is a new directory named .hg that is hidden to the usual ls. Right now we have no included anything in the repository. We can do with:
In my case the directory had two files and one folder with a figure. However we did not yet validated this changes. We can validate or commit
To see what happened:
Now I forgot to include a file with the bibliography. We copy a new file: biblio.bib in the directory and:
We forgot to add the new file:
Exactly like in SVN. The command hg is notificating the we have add a new file (but have not commit the addition).
We see the now how useful is mercurial to track all the changes!! Let’s say that our editor saves automatically files with the symbol ~ at the end but we do not want to keep track of these files. An easy way to handle with this is by creating a simple file called .hgignore with the following text inside:
Mercurial: next steps
If you tried the above tiny shown tutorial then probably you will be confortable with Hg. But probably also you will have a lot of questions about Hg. For instance, the username, the email, what means the code: changeset: 1:891564a37700 or other things.
Let’s go step by step. At the beginning we commented that we have a working installation of Hg. We can try to verify this with:
This command gives us information about the installation. In my case everthing seems correct. You have detected about Python, this is because all the extensions in Mercurial are written in Python. If you type the command
hg config you will have more information. The usual configuration file for a given user is found in /home/user/.hgrc. And looks like:
Here is the very basic configuration for the user mrmaggugg. The activated extensions are indicated here just with the name follow by = .Therefore the information about the user is taken from this configuration file. You can edit manually but before you should check
hg help config, but because the information given is very large you can try something like
hg help config | grep user just to have the information with the word user of the documentation. And just to give another examples of this configuration files it has graphlog, color or hgview. The first introduce the command
hg glog that is a kind of
hg log command but with additional information about branches, master version etc. color just add color to the outputs shown on your terminal when you use any hg command. Concerning hgview you will have
hgview command you will have a graphical frontend for Hg.
Text Editors and Hg
- In case you are using VIM, which is one of the main tools I use every day, I may recommend the plugin lawrencium
- Geany is another nice tool that might integrate a version control inside with a plugin and gedit has this posibility also with rabbitVCS. This utility is not specific of mercurial and you might use several control version software. Note that git has specific plugins.