我已经在Windows上使用git有一段时间了(使用msysGit),我喜欢分布式源代码控制的想法。就在最近,我一直在关注Mercurial (hg),它看起来很有趣。然而,我无法理解hg和git之间的区别。

有人把git和hg放在一起比较吗?我很想知道hg和git有什么不同,而不需要加入粉丝的讨论。


当前回答

mercurial和git的另一个有趣的比较:mercurial vs git。 主要关注内部结构及其对分支过程的影响。

其他回答

Git是一个平台,Mercurial“只是”一个应用程序。Git是一个版本控制的文件系统平台,附带了一个DVCS应用程序,但与平台应用程序一样,它比集中的应用程序更复杂,也更粗糙。但这也意味着git的VCS非常灵活,你可以用git做大量非源代码控制的事情。

这就是区别的本质。

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 end up confused at some point (unless you stick to only very basic functionality). 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.

对于一些更偏向技术的比较,我个人看过的最好的文章是Dustin Sallings的:

Mercurial和Git的区别 Reddit上有经验丰富的达斯汀回答他自己的新手问题的帖子

实际上,他已经广泛地使用了这两种DVCSs,并且对它们都很了解——最后他更喜欢git。

它们几乎一模一样。 从我的角度来看(我的意思是,让我选择一个DVCS而不是另一个的原因),最重要的区别是两个程序如何管理分支。

要使用Mercurial启动一个新分支,只需将存储库克隆到另一个目录并开始开发。然后,你拉并合并。 使用git,您必须显式地为您想要使用的新主题分支提供一个名称,然后使用相同的目录开始编码。

简而言之,Mercurial中的每个分支都需要自己的目录;在git中,你通常在单个目录下工作。 在Mercurial中切换分支意味着更改目录;在git中,这意味着要求git通过git checkout更改目录的内容。

老实说:我不知道是否可以用Mercurial做同样的事情,但因为我通常在web项目上工作,总是使用相同的目录和git对我来说似乎更舒服,因为我不需要重新配置Apache并重新启动它,而且每次分支时我都不会弄乱我的文件系统。

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 Hg encourages to use clones for experimental, short-running tasks and named branches for long-running tasks, like for release branches.

为什么许多Hg用户更喜欢克隆而不是命名分支的原因更多的是社会或文化而不是技术。例如,在Hg的最新版本中,甚至可以关闭已命名的分支并从变更集中递归地删除元数据。

另一方面,git邀请使用“命名分支”,这些分支不是永久的,也不是存储在每个变更集中的元数据。

从我个人的角度来看,git的模型与命名分支的概念有很深的联系,并在同一个目录下在一个分支和另一个分支之间切换;hg可以对命名的分支做同样的事情,但它鼓励使用克隆,这是我个人不太喜欢的。

我认为关于“Mercurial vs. Git”最好的描述是:

“Git是韦斯利·斯奈普斯。Mercurial是丹泽尔·华盛顿

git和mercurial之间有一个巨大的区别;表示每次提交的方式。Git将提交表示为快照,而mercurial将它们表示为差异。

这在实践中意味着什么?在git中,很多操作都更快,比如切换到另一个提交,比较提交等等。特别是当这些提交距离很远的时候。

说真的,mercurial的方法没有任何优势。

最大的不同在于Windows系统。Mercurial是本地支持的,Git不支持。你可以通过bitbucket.org获得与github.com非常相似的托管(实际上更好,因为你得到了一个免费的私有存储库)。我曾经使用过一段时间的msysGit,但后来转到Mercurial,我对它非常满意。