相忘于江湖

泉涸,鱼相与处于陆,相呴以湿,相濡以沫,不如相忘于江湖。《庄子.大宗师篇》

Differences between Subversion and Mercurial

Thursday May 17, 2007

I'm using both Subversion (SVN) and Mercurial (HG) for source codes management (SCM). There are some differences between them for daily using. I document them in this article and update it when I find new differences.

  1. commit : push
    'svn ci' will commit the server directly
    'hg ci' will commit to local history
    'hg push' will push the changes to server

  2.  locally : globally
    all svn cmds will check current and subdirs only, eg commit, status
    but hg cmds will check globally, including the whole workspace
    if you want to check current and subdirs only, append '.' to hg cmds
    eg, hg status .

  3. partially checkout : fully checkout
    svn can checkout a portion of the workspace (a module or subdir)
    hg can't, it will clone the whole workspace

  4. empty dir
    mercurial will ignore empty dirs when invoking 'hg add', more details
    if you want to add those dirs into mercurial, add a hidden file under it
    $ touch subdir/.hidden
    $ hg add subdir

  5. symbolic link
    mercurial 0.9.3 doesn't support symbolic link file type:

    [qd139970@agc141 rtc]$ hg --version
    Mercurial Distributed SCM (version 0.9.3)

    Copyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    [qd139970@agc141 rtc]$ hg add RTC_Template_O5U1
    RTC_Template_O5U1: unsupported file type (type is symbolic link)
    [qd139970@agc141 rtc]$

    PS: link1 and link2 mentioned that this feature is supported in trunk.
    PS2: Mercurial 0.9.4 supports symbolic links now(Jun 25, 2007).

  6. account name
    Mercurial will look at $HOME/.hgrc to get the account info when 'hg commit',
    if there's not 'username' entry in $HOME/.hgrc, Mercurial will use
    $USER@$HOSTNAME as the username in log message.
    if this is not what you want, please specify your username in $HOME/.hgrc
        [ui]
        username = [your prefer username]
     
  7. multiple heads
    it's quite easy to create multiple heads in Mercurial workspace.
    you commit new changeset locally, and 'hg pull' from parent workspace
    to get new changesets from team members, then two heads created.
    'hg heads' will show the heads information.
    if multiple heads exist, you need to 'hg up && hg merge && hg commit'
    before you can 'hg push' your changeset to parent workspace.

    one possible way to avoid the mess is running 'hg pull && hg up' before
    you commit any modifications.

    if you enable hgext.fetch extension, 'hg fetch' will do this for you:
    'hg pull && hg up && hg merge && hg commit'

    add following two lines in $HOME/.hgrc can enable hgext.fetch extension
        [extensions]
        hgext.fetch =

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

Very useful post. Thanks.

Posted by serge on December 13, 2007 at 10:54 PM CST #

Post a Comment:
  • HTML Syntax: NOT allowed