Wednesday 16 July 2014

Working with Mercurial

 

What is Mercurial

Mercurial is a Version Control System, just like Git with few changes, Mercurial is a Open Source Software, written in Python, unlike Git which is written in perl and C and was developed by Linus Torvalds. Although Git and Mercurial are almost same in there nature, different people have different preferences.
 According to Wikipedia, Mercurial is a cross-platform, distributed revision control tool for software developers. Mercurial's major design goals include high performance and scalability, decentralized, fully distributed collaborative development, robust handling of both plain text and binary files, and advanced branching and merging capabilities, while remaining conceptually simple.It includes an integrated web interface. Mercurial has also taken steps to ease the transition for SVN users.

Getting started with Mercurial

  • You can download and install Mercurial using
                      sudo apt-get install mercurial (for Ubuntu/debian)
                      yum install mercurial (for Fedora)

  • You have to create a .hgrc file in your home directory, as  "." in hgrc suggest that it is a hidden file, it is a configuration file and must be stored in home directory. Following is an example of .hgrc  file.

                       
[ui]
username = Rahul Mishra <rahulmishra@gmail.com>

[extensions]
purge =
strip =
color =
pager =
progress =
rebase =

[pager]
pager = LESS='FSRX' less
attend = tags, help, annotate, cat, diff, export, status,\
         outgoing, incoming, glog, log, grep




Using Mercirial

  • After setting up the .hgrc file we are ready to go, we can make a directory, mkdir dir_name then cd dir_name.
  •  Then we can create a file say vim Test.txt and we can write in it  and finally save and exit.
  • For intailizing Mercurial we have to give command hg init, just like git init, this command will initialize this directory as Mercurail repo.
  • hg init will add a hidden file .hg in this directory,also we have to add our file Test.txt to the empty repo by using command hg add Test.txt.
  • Next we have to commit the file, using hg commit <file_name>, this will open an editor, it is nano as default, you can also change with  select-editor command. Writing a good and precise and meaning full is very important, also give a space between the heading and the details.
  • A patch file is generated in the same way, now if we change our Test.txt and do a hg diff, we can see the difference made in the file. hg diff works only when you have not committed the changes, because once you have committed the changes the buffer are overridden and hg diff will not produce any output.
  • hg log gives the changes made in every commit and also gives the heading of the commit message. 
  •   hg status will give the currnt status of the files as Modified or  Added.     

No comments:

Post a Comment