Saturday, March 6, 2010

Version control of files using "hg" for your local system

Repository Maintenance

Maintaining a Subversion repository can be a daunting task, mostly due to the complexities inherent in systems which have a database backend. Doing the task well is all about knowing the tools—what they are, when to use them, and how to use them. This section will introduce you to the repository administration tools provided by hg, and how to wield them to accomplish tasks such as repository migrations, upgrades, backups and cleanups.

hg - mercurial is a open source version control 
At first the hg must be installed so do the following command.
sudo apt-get install mercurial

Prepare Mercurial
As first step, you should teach Mercurial your name. For that you open the file ~/.hgrc with a text-editor and add the ui section (user interaction) with your username:
[ui]
username = Mr. Johnson
 Initialize the project
Now you add a new folder in which you want to work
$ hg init project
Add files and track them
$ cd project
$ (add files)
$ hg add
 Note:
You can also go into an existing directory with files and init the repository there.
$ cd project
$ hg init
Alternatively you can add only specific files instead of all files in the directory. Mercurial will then track only these files and won't know about the others. The following tells mercurial to track all files whose names begin with "file0" as well as file10, file11 and file12.
$ hg add file0* file10 file11 file12
Save changes
$ (do some changes)
see which files changed, which have been added or removed, and which aren't tracked yet
$ hg status
see the exact changes
$ hg diff
commit the changes.
$ hg commit
now an editor pops up and asks you for a commit message. Upon saving and closing the editor, your changes have been stored by Mercurial.
Note:
You can also supply the commit message directly via hg commit -m 'MESSAGE'.
Move and copy files
When you copy or move files, you should tell Mercurial to do the copy or move or you, so it can track the relationship between the files.
Remember to commit after moving or copying. From the basic commands only commit creates a new revision
$ hg cp original copy
$ hg commit
(enter the commit message)
$ hg mv original target
$ hg commit
(enter the commit message)
Now you have two files, "copy" and "target", and Mercurial knows how they are related.

Check your history
$ hg log
This prints a list of changesets along with their date, the user who committed them (you) and their commit message.
To see a certain revision, you can use the -r switch (--revision). To also see the diff of the displayed revisions, there's the -p switch (--patch)
$ hg log -p -r 3

The procedure given for hg is so simple, if you follow up the commands and get practised with your local system then the other repository maintenances will be easy.So get practised with this hg and enjoy it.
Thanks to : http://mercurial.selenic.com/guide/



No comments:

Post a Comment