Use Mercurial for easy local revision backup

I regularly make backups of all my data, it’s also synchronized on several computers and hard disks. But since I backup only once a week, I don’t really have several revisions from files available between the backups. This is espacially necessary if you work on some code of a small project, which is not revisioned via svn or cvs – and you don’t want to or have no access to svn. Also you don’t want to set up a local svn or cvs repository. You could use Time Machine on Mac OS X and there are some other tools available on Windows, like FileHamster. But FileHamster wasn’t always trouble free and by coincidence I found another solution which is rather appealing: Mercurial.

The nice thing about Mercurial is, that it is a fast, distributed, lightweight Source Control Management system – you don’t need a server for it. The revisions are save to the local .hg folder. In this post I just explain some basics to get started (on Windows – but apart from the installation process, it’s the same for Mac OS X and Linux).

First download the binary distribution of Mercurial at the download page. Download the latest installer and let the installer change the system PATH variable, so that hg.exe (chemical symbol for Mercurial) is found in all opened CLIs. There is also a GUI Mercurial client available (TortoiseHg), but since I already have TortoiseCSV and TortoiseSVN installed, I didn’t want to bloat my contect menu any further.
Open a Windows CLI (Start->Run…, enter cmd.exe) and cd into the directory where your files are which need to be revisioned. You create now a repository with

hg init

A .hg directory will be created and the repository initialized. Now we add files we want to be in the revision with e.g.

hg add *.php

Adding a folder will add also the content of that folder. After that you need to commit the files to the repository with

hg commit -m "Adding files"

You can check which files were changed or need to be commited with

hg status

A log will be shown with

hg log

In order to ignore files you need to create a .hgignore text file in the same directory where the .hg directory is and add something like

syntax: glob
.hgignore
*.m4

If you didn’t commit your changes to a file you can revert to the revision in the repository with

hg revert file

In order to go back to a special revision of a file use the

hg backout

command (see the help (hg help backout) for the exact use).

As said, these are only the basic features. For further information head to the tutorial or the quick reference cards. Extensive documentation about all features can be found in the freely available book “Distributed revision control with Mercurial”.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

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