views:

26357

answers:

17

I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.

Has anyone made a side-by-side comparison between git and hg? I'm interested to know what differs hg and git without having to jump into a fanboy discussion.

+3  A: 

I'm currently in the process of migrating from SVN to a DVCS (while blogging about my findings, my first real blogging effort...), and I've done a bit of research (=googling). As far as I can see you can do most of the things with both packages. It seems like git has a few more or better implemented advanced features, I do feel that the integration with windows is a bit better for mercurial, with TortoiseHg. I know there's Git Cheetah as well (I tried both), but the mercurial solution just feels more robust.

Seeing how they're both open-source (right?) I don't think either will be lacking important features. If something is important, people will ask for it, people will code it.

I think that for common practices, Git and Mercurial are more than sufficient. They both have big projects that use them (Git -> linux kernel, Mercurial -> Mozilla foundation projects, both among others of course), so I don't think either are really lacking something.

That being said, I am interested in what other people say about this, as it would make a great source for my blogging efforts ;-)

Erik van Brakel
Yes, they are both open-source projects.
Martin Geisler
+106  A: 

These articles may help:

John
Hahaha. That's a funny Analogy. Thanks for pointing that.
jpartogi
From your first link, point nr. 4: "Shut up about the tools you use and write some code." I like this conclusion. :)
bjarkef
+3  A: 

Sometime last year I evaluated both git and hg for my own use, and decided to go with hg. I felt it looked like a cleaner solution, and worked better on more platforms at the time. It was mostly a toss-up, though.

More recently, I started using git because of git-svn and the ability to act as a Subversion client. This won me over and I've now switched completely to git. I think it's got a slightly higher learning curve (especially if you need to poke around the insides), but it really is a great system. I'm going to go read those two comparison articles that John posted now.

Greg Hewgill
Take a look at hgsubversion: http://bitbucket.org/durin42/hgsubversion/. It currently requires a development version of Mercurial, but they will make a release for Mercurial 1.3, which is due July 1st.
Martin Geisler
+2  A: 

Nothing. They both do the same, both perform about equally. The only reason you should choose one over the other is if you help out with a project that already uses one..

The other possible reason for choosing one is an application or service which only supports one of the system.. For example, I pretty much chose to learn git because of github..

dbr
Looks like your answer was far too pragmatic. :)
Arafangion
+3  A: 

There is a great and exhaustive comparison tables and charts on git, Mercurial and Bazaar over at InfoQ's guide about DVCS.

Spoike
+22  A: 

The big difference is on Windows. Mercurial is supported natively, Git isn't. You can get very similar hosting to github.com with bitbucket.org (actually even better as you get a free private repository). I was using msysGit for a while but moved to Mercurial and been very happy with it.

mmiika
git is supported natively in windows, don't spread FUD.
felipec
So "natively" is not quite the right word, but it is not well supported under windows, that is for sure.
Ian Kelling
git is supported to a point on Windows. But try using Unicode filenames cross-platform and see what pain you get.
Craig McQueen
@Craig: That's more of a platform shortcoming. A competent platform would allow you to switch to a suitable locale. If you stick to utf-8, you'll be mostly fine except that Mac OS X has slightly different normalisation of utf-8, however, I'm not sure if windows even lets you use utf-8...
Arafangion
Windows supports Unicode, though MS chose to go for UTF-16 in its API rather than UTF-8. Despite that, it would be quite possible for git to support Unicode cross-platform. SVN has solved that problem quite well. But it's just not a high priority for the msysGit development at the moment. http://code.google.com/p/msysgit/issues/detail?id=80
Craig McQueen
+22  A: 

Git is a platform, Mercurial is “just” an application. Git is a versioned filesystem platform that happens to ship with a DVCS app in the box, but as normal for platform apps, it is more complex and has rougher edges than focused apps do. But this also means git’s VCS is immensely flexible, and there is a huge depth of non-source-control things you can do with git.

That is the essence of the difference.

Git is best understood from the ground up – from the repository format up. Scott Chacon’s Git Talk is an excellent primer for this. If you try to use git without knowing what’s happening under the hood, you’ll just end up confused. This may sound stupid when all you want is a DVCS for your daily programming routine, but the genius of git is that the repository format is actually very simple and you can understand git’s entire operation quite easily.

For some more technicality-oriented comparisons, the best articles I have personally seen are Dustin Sallings’:

He has actually used both DVCSs extensively and understands them both well – and ended up preferring git.

Aristotle Pagaltzis
I've often read people mention git being a "platform", but that's more of a theory or common myth because there no major examples of it as a platform to do something other than run git.
Ian Kelling
+5  A: 

There is a dynamic comparison chart over at the versioncontrolblog where you can compare several different version control systems.

Here is a comparison table between git, hg and bzr.

Spoike
The information on Mercurial is not entirely accurate: Mercurial do have "intelligent merges after moves or renames". Concretely, this means that if I rename `dir-a/foo.c` to `dir-b/foo.c` and keep working on `dir-b/foo.c`, then your work on `dir-a/foo.c` will be correctly merged with my work after a pull.
Martin Geisler
+2  A: 

Yet another interesting comparison of mercurial and git: Mercurial vs Git. Main focus is on internals and their influence on branching process.

Konstantin
+8  A: 

I think the best description about "Mercurial vs. Git" is:

"Git is Wesley Snipes. Mercurial is Denzel Washington"

Cyberdrow
How ist that supposed to help? Does that mean that git is more the martial arts type?
fmuecke
Excuse me. But have you actually read the article this link points to? I see that the answer has lost 1 point. Have you downvoted it?
Paidhi
+62  A: 

I work on Mercurial, but fundamentally I believe both systems are equivalent. They both work with the same abstractions: a series of changesets which make up the history. Each changeset knows where it came from (the parent changeset) and can have many child changesets. The recent hg-git extension provides a two-way bridge between Mercurial and Git and sort of shows this point.

Git has a strong focus on mutating this history graph (with all the consequences that entails) whereas Mercurial does not encourage history rewriting, but it's easy to do anyway and the consequences of doing so are exactly what you should expect them to be (that is, if I modify a changeset you already have, your client will see it as new if you pull from me). So Mercurial has a bias towards non-destructive commands.

As for light-weight branches, then Mercurial has supported repositories with multiple branches since..., always I think. Git repositories with multiple branches are exactly that: multiple diverged strands of development in a single repository. Git then adds names to these strands and allow you to query these names remotely. The Bookmarks extension for Mercurial adds local names, and with Mercurial 1.6, you can move these bookmarks around when you push/pull..

I use Linux, but apparently TortoiseHg is faster and better than the Git equivalent on Windows (due to better usage of the poor Windows filesystem). Both http://github.com and http://bitbucket.org provide online hosting, the service at Bitbucket is great and responsive (I haven't tried github).

I chose Mercurial since it feels clean and elegant -- I was put off by the shell/Perl/Ruby scripts I got with Git. Try taking a peek at the git-instaweb.sh file if you want to know what I mean: it is a shell script which generates a Ruby script, which I think runs a webserver. The shell script generates another shell script to launch the first Ruby script. There is also a bit of Perl, for good measure.

Martin Geisler
Note that TortoiseHg also works together with Nautilus, the Gnome file manager on Linux.
oenli
I use Mercurial much more than git, but in my experience github has always been faster and more responsive than bitbucket unfortunately...
romkyns
The Ruby script is only generated if it the httpd is Webrick, the ruby webserver.
mathepic
+9  A: 

There's one huge difference between git and mercurial; the way the represent each commit. git represents commits as snapshots, while mercurial represents them as diffs.

What does this means in practice? Well, many operations are faster in git, such as switching to another commit, comparing commits, etc. Specially if these commits are far away.

AFAIK there's no advantage of mercurial's approach.

felipec
Changesets (diffs) advantage is in taking up less space. Git recovers the space used for commits by using compression, but this requires an occasional explicit recompress step ("git pack").
quark
It is now called 'git gc', but there are different levels of garbage collection, and some levels are executed automatically in recent versions of git.
felipec
+1. Yes, that's the main difference, I think (from the technical side).
Olivier
actually mercurial uses snapshots as well
Ronny
+2  A: 

There are quite significant differences when it comes to working with branches (especially short-term ones).

It is explained in this article (BranchingExplained) which compares Mercurial with Git.

cysiek10
+4  A: 

Also google's comparison (though it's a bit old, done in 2008)

http://code.google.com/p/support/wiki/DVCSAnalysis

KalEl
+2  A: 

If you are interested in a performance comparison of Mercurial and Git have a look at this article. The conclusion is:

Git and Mercurial both turn in good numbers but make an interesting trade-off between speed and repository size. Mercurial is fast with both adds and modifications, and keeps repository growth under control at the same time. Git is also fast, but its repository grows very quickly with modified files until you repack — and those repacks can be very slow. But the packed repository is much smaller than Mercurial's.

asmaier
A: 

They are almost identical. The most important difference, from my point of view (I mean, the reason that got me to choose one DVCS over the other) is how the two programs manage branches.

To start a new branch, with Mercurial, you simply clone the repository to another directory and start developing. Then, you pull and merge. With git, you have to explicitly give a name to the new topic branch you want to use, then you start coding using the same directory.

In short, each branch in Mercurial needs its own directory; in git you usually work in on single directory. Switching branches in Mercurial means changing directories; in git, it means asking git to change the directory's content with git checkout.

I'm honest: I don't know if it's possible to do the same with Mercurial, but since I usually work on web projects, using always the same directory with git seems much confortable to me, since I don't have to re-configure Apache and restart it and I don't mess my filesystem everytime I branch.

Edit: As Deestan noted, Hg has named branches, which can be stored in a single repository and allow the developer to switch branches within the same working copy. git branches are not exactly the same as Mercurial named branches, anyway: they are permanent and not throw away branches, like in git. That means that if you use a named branch for experimental tasks even if you decide to never merge it it will be stored in the repository. That's the reason why Hb encourages to use clones for experimental, short-running tasks and named branches for long-running tasks, like for release branches.

The reason why a lot of Hg users prefere clones over named branch is much more social or cultural than technical. For example, with last versions of Hg, it's even possible to close a named branch and recursively remove metadata from changesets.

On the other side, git invites to use "named branches" which are not permanent and are not stored as metadata on each changeset.

From my personal point of view, then, git's model is deeply linked to the concept of named branches and switch between a branch and another withing the same directory; hg can do the same with named branches, but yet it encourages the use of clones, which I personally don't like too much.

Arialdo Martini
This is not a difference; Hg has named branches too. We use them all the time during normal development instead of clone-branches.
Deestan
AFAIK, named branch in Hg are obtained storing metadata in each commit; I may be wrong, but I read that once you create a branch, its metadata will be embedded in each changeset and become part of the history. This is a huge difference with git. "Clones are great for quick experiments where you don't want to record a branch name, and named branches are good for long term branches" http://tinyurl.com/2wz39qxWhat I was trying to say with my post is that git's standard workflow invites you to use a single working copy; Hg standard workflow includes clones, which don't suite my personal needs.
Arialdo Martini
+1  A: 

I realize this isn't a part of the answer, but on that note, I also think the availability of stable plugins for platforms like NetBeans and Eclipse play a part in which tool is a better fit for the task, or rather, which tool is the best fit for "you". That is, unless you really want to do it the CLI-way.

Both Eclipse (and everything based on it) and NetBeans sometimes have issues with remote file systems (such as SSH) and external updates of files; which is yet another reason why you want whatever you choose to work "seamlessly".

I'm trying to answer this question for myself right now too .. and I've boiled down the candidates to Git or Mercurial .. thank you all for providing useful inputs on this topic without going religious.

joho
+1, because the "seamless" experience is more important than people who don't work with these things think. A solid plugin for the IDE makes a lot of difference.
eksortso