Skip to content

Latest commit

 

History

History
executable file
·
84 lines (64 loc) · 3.68 KB

using_hg.asciidoc

File metadata and controls

executable file
·
84 lines (64 loc) · 3.68 KB

Using HG

While GIT is the major DVCS in use Mercurial (also known as hg) is also being used by a number of projects. In many cases the ideas of git and HG are similar, so if you have been using one switching to the other should not require much of a learning curve.

Note
HG is the chemical symbol for mercury, so that is the short name. All those of you who remember high school or college chemistry class knew that.

There are of course a number of technical differences in the internal workings of git and HG but they are beyond the scope of this book as I really want to focus on how to effectively use these tools to get work done. How the internals work are not really important, if you care of course then there are a number of books, videos and web sites that will cover how the internals work. That being said you can use both tools with out knowing how they index data internal.

In addition git is written in C while hg is written in Python. This doesn’t matter if you are using git and hg.

To create a repository in HG create a directory and use the command hg init. This will create an empty hg repository to which we can add files.

Most of the commands to work with HG are pretty similar to GIT. So you can add files with +hg add file* or commit with +hg commit " and so on.

Sharing HG Repositories

If we want to share that repository we can run the command hg serve which will open a web server on port 8000 which we can use the interact with the hg repository.

The hg serve command will produce a web page that looks a bit like the following image, with a history of the repository.

hg log

The nice this about this web page is that for free you get a number of nice features, that can help you manage a repository.

If you want to see a graphical version of the network of commits you can use the graph option which will give you a screen that looks like this image. Here you can see the results of a repository where there was a branch and a merge. With the side branch in green.

hg graph

NOTE: run +hg serve+ will by default not run in the background but
keep logging to the terminal in the standard, HTTP log format.

so run it on a spare tab on in a session with screen or tmux.

listening at http://Galileo.local:8000/ (bound to *:8000)
127.0.0.1 - - [15/Sep/2012 21:50:31] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2012 21:50:31] "GET /static/style-paper.css HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2012 21:50:31] "GET /static/mercurial.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2012 21:50:31] "GET /static/hglogo.png HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2012 21:50:31] "GET /static/hgicon.png HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2012 21:51:06] "GET / HTTP/1.1" 304 -
127.0.0.1 - - [15/Sep/2012 21:51:06] "GET /static/style-paper.css HTTP/1.1" 304 -
127.0.0.1 - - [15/Sep/2012 21:51:06] "GET /static/mercurial.js HTTP/1.1" 304 -
127.0.0.1 - - [15/Sep/2012 21:51:06] "GET /static/hglogo.png HTTP/1.1" 304 -
127.0.0.1 - - [15/Sep/2012 21:51:06] "GET /static/hgicon.png HTTP/1.1" 304 -

You can also use the server to clone a repository by simply typing hg clone URL which will pull the changes.

In terms of how to add files, like in git you use hg add <files> followed by hg commit and like in git the -m option will let you set the commit message.

If you made some changes that you don’t want to keep you can use the hg revert <files> to roll one or more files back to the last commit. When you do this hg will save any files you rolled back with the ending .orig so that they are not lost.