This post will be a quick introduction to a revision control tool called Mercurial.
(Mercurial is also known as hg from the chemical element Mercury’s symbol in the periodic table.)
Background
On my development machine I have a repository with a couple of commits I want to share with the rest of the team.
Exporting
I begin with checking how many change sets I have.
F:\work\Hailstorm\code>hg log changeset: 1:e189d5bef702 tag: tip user: herrdahl@....com date: Thu Oct 22 22:30:46 2009 +0200 summary: Dummy implementation of a highscore post with Castle… changeset: 0:b49b8b762899 user: herrdahl@....com date: Thu Sep 24 20:04:38 2009 +0200 summary: Creted project
It turns out there are two change sets committed, 0 and 1.
In order to share them with the team I need to export the sets from my local repository into regular files (diffs) that could be distributed to all team members.
So I export them both by using the hg export command. (It is also possible to export multiple change sets into one file but that is a later topic.)
F:\work\Hailstorm\code>hg export 0 -g -o 0.diff F:\work\Hailstorm\code>hg export 1 -g -o 1.diff
The –g option tells mercurial to use git extended diff format and is needed in order to export the binary files correctly.
The –o option just tells which file to output the result in. One could also use some formatting rules in the filename, type hg help export for details.
Importing
Now I want to import the changes on another machine.
Copy the diff-files above onto the new machine (in our project the files are located in the shared patches directory).
First I need to clone our public master repository.
C:\Work\Net>hg clone https://hailstorm.googlecode.com/hg/ hailstorm no changes found updating working directory 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
Then I clone my local repository in order to get a sandbox that I can safely test importing the changes in.
C:\Work\Net>hg clone hailstorm integration updating working directory 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
Move into the sandbox and apply the patches.
C:\Work\Net>cd integration C:\Work\Net\integration>hg import ...diff applying ...diff C:\Work\Net\integration>hg import ..\1.diff applying ..\1.diff
If the patches where applied correctly we can now pull the changes into the local repository.
C:\Work\Net\integration>cd ..\hailstorm C:\Work\Net\hailstorm>hg pull ..\integration pulling from ..\integration requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 68 changes to 65 files (run 'hg update' to get a working copy) C:\Work\Net\hailstorm>hg update 64 files updated, 0 files merged, 0 files removed, 0 files unresolved
The changes have now successfully been imported on a different machine.
Commit
Now that we have setup a new working copy on a different machine we can go ahead and perform our work.
In my case I’m adding support for running the tests on a 64-bit machine.
When done I commit my changes by issuing the hg commit command together with my username.
C:\Work\Net\hailstorm>hg commit -u herrdahl@...com
When executing this command, notepad will popup and prompt you for a commit message.
If no error messages are displayed I can now export my changes by repeating the export procedure above.
C:\Work\Net\hailstorm>hg log changeset: 2:a3015ff7e07e tag: tip user: herrdahl@...com date: Thu Nov 12 15:17:12 2009 +0100 summary: Added support for building (testing) on 64-bit machines… changeset: 1:e189d5bef702 user: herrdahl@...com date: Thu Oct 22 22:30:46 2009 +0200 summary: Dummy implementation of a highscore post with Castle… changeset: 0:b49b8b762899 user: herrdahl@...com date: Thu Sep 24 20:04:38 2009 +0200 summary: Creted project C:\Work\Net\hailstorm>hg export 2 -g -o 2.diff
Send the new diff to all team members and you are all done!
Additional resources
Learning Mercurial in workflows.
Update:
Joel Spolsky has written an excellent Mercurial tutorial over at HgInit.com.
No comments yet.