I’ve played around with three version control systems during my learning and working period. The first was CVS, where it was the first time I’ve touched a version-control mechanism during university. The second being Mercurial and lastly, Git; two of which I’ve learnt partially for supporting customers while I was working with Atlassian.
Now as I’m in a developer’s role, I would feel the need to pick up a version-control system as what most developers do. Thus, I re-learnt Mercurial once more.
There are a few basic commands that one should know and understand for a better understanding on how Mercurial works. Here’s a list of common commands that I’ve stumbled upon thus far.
- initialize the current directory to be a repo
- add
%FILE_NAME%to the repo - confirms changes to the repo
-margument: for adding a commit message to the commithg clone %REPO_URL% %NEW_FOLDER%- for cloning online repos
%REPO_URL%= repo URL
hg clone %CUR_REPO% %NEW_REPO%- for cloning existing local repo to a new one
%CUR_REPO%= repo to clone%NEW_REPO%= destination for the clone repo
- to view which revision is currently checked out
- shows a summary of every event that occurs in the repo:
$ hg log changeset: 1:82e55d328c8c tag: tip user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 summary: Create a makefile changeset: 0:0a04b987be5a user: mpm@selenic.com date: Fri Aug 26 01:20:50 2005 -0700 summary: Create a standard "hello, world" program changeset– identifies the changeset.- first number before the colon = revision number.
- short identity of the changeset
- only valid in the current repo
- hexadecimal string after the colon = changeset ID
- actual identity of the changeset
- valid in all repos that contains this changeset
- first number before the colon = revision number.
tag– symbolic name of the changeset.
may contain tip (to identify the most recent changeset).
user– identifies the user who created this changeset.date– local time of when this changeset was created.summary– changeset description.parent– identifies the parent changesets.- detailed view of a repo’s history:
$ hg log -v changeset: 1:82e55d328c8c tag: tip user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 files: Makefile description: Create a makefile (...) files– lists the modified files in this changeset.description– multi-line description of the changeset.- an even more detailed view of a repo’s history:
$ hg log --debug changeset: 1:82e55d328c8ca4ee16520036c0aaace03a5beb65 tag: tip parent: 0:0a04b987be5ae354b710cefeba0e2d9de7ad41a9 parent: -1:0000000000000000000000000000000000000000 manifest: 1:0c7c1d435e6703e03ac6634a7c32da3a082d1600 user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 files+: Makefile extra: branch=default description: Create a makefile (...) changeset– now provides the unabbreviated changeset ID.parent– now has 2:changeset IDof both parents of this changeset.-1:0000000000000000000000000000000000000000refers to a non-existent parent.
manifest– provides the manifest ID for the changeset.
manifestdescribes the contents of a repo at a particular changeset ID.file+– list files added to the changeset.file-– list files removed to the changeset.- view specific changesets; specified with the
%CHANGESET_ID%:$ hg log -r1 changeset: 1:82e55d328c8c tag: tip user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 summary: Create a makefile - show patches associated with the changesets:
$ hg log -r1 -p changeset: 1:82e55d328c8c tag: tip user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 summary: Create a makefile diff -r 0a04b987be5a -r 82e55d328c8c Makefile --- /dev/null Fri Aug 26 01:20:50 2005 -0700 +++ b/Makefile Fri Aug 26 01:21:28 2005 -0700 @@ -0,0 +1,1 @@ +all: hello - show info of the latest changeset:
$ hg tip changeset: 1:82e55d328c8c tag: tip user: mpm@selenic.com date: Fri Aug 26 01:21:28 2005 -0700 summary: Create a makefile - adding the -q argument will just output the latest changeset’s ID:
$ hg -q tip 1:82e55d328c8c - shows the status of files in the repo.
- a few denotations:
Status Definition Mmodified ?untracked in repo (not added) - a detailed view of the actual changes made to files:
$ hg diff diff -r 82e55d328c8c hello.c --- a/hello.c Fri Aug 26 01:21:28 2005 -0700 +++ b/hello.c Mon May 05 00:27:56 2008 +0200 @@ -12,5 +12,6 @@ int main(int argc, char **argv) { printf("hello, world!\n"); + printf("sure am glad I'm using Mercurial!\n"); return 0; } - reverts
%FILE_NAME%to its unmodified state. - to modify all files, replace
%FILE_NAME%with--all. - creating a changeset.
- enter any message(s) on the first line.
- grab latest changesets that does not exist in the current repo.
- can specify a path for a specific repo.
- updates the current repo with changes pulled from another.

