Git 是反复无常的客户? 为什么没有 Git-hg?

这个问题困扰我有一段时间了。我做了功课,检查了堆栈溢出,发现至少有两个主题与我的问题有关: Git for Mercurial 就像 Git-svn Git 与 Mercurial 存储库的互操作性

为了解决这个问题,我在谷歌上做了一些认真的搜索,但是到目前为止还没有结果。我也读过 Git Internals幕后黑手的书,试图找出这个问题的答案。我仍然有点困惑,为什么我没有能够找到任何合适的 git-hg 类型的工具。

从我的角度来看,git-svn 是主要特性之一,这也是为什么我选择在工作中使用 git 而不是 mercurial 的原因。它允许我使用我喜欢的工作流程,如果其他人不在乎的话,他们就不用费心了。我只是不明白使用中间的汞回购来回转换的意义,正如其中一个链中所建议的那样。

总之,从我读到的 hg 和 git 在楚格设计上看起来非常相似。有 不同之处,但是它们都不应该阻止为 hg 创建 git 客户机。在我看来,远程跟踪分支和章鱼合并使得 git 比 hg 更强大。

那么,真正的问题是,为什么 git-hg 不存在(或者至少很难找到) ,有什么真正的原因吗? Git 用户(和开发人员)对 hg 对应方是否存在某种敌意,从而导致了 git-hg 工具的缺乏? 你们有谁有计划开发这样的东西,然后公之于众吗?我可以自愿参与(尽管我的 C 技能很弱)来完成这项工作。我只是没有足够的知识来自己启动这个程序。

这是否可能成为永久终结所有 DVCS 战争的工具?

21099 次浏览

I think there really just isn't much incentive to create one. No one's going to be horribly crippled by having to use one over the other; they're both DVCS. Sure, everyone probably has their preference, but they'll generally just suck it up and use the other if they have to. I assume hg-git has come about because git is very widely used, while far fewer projects have adopted hg.

In constrast, if a project is using svn or cvs, anyone who's had a taste of DVCS is going to be hurting - and they'll want that git-svn/hg-svn utility. There are a lot of projects out there using cvs/svn still, so plenty of demand.

You're probably right that it'd be a useful thing to have, though, assuming one of the two doesn't slowly win out over the other (git really does have a much larger userbase, I believe).

You're also right that there are no big technical obstacles - hg-git is bidirectional, so clearly it's possible to map the information between the two.

hg-git and the author's Pycon presentation explaining his take on the situation.not sure if you came across these while googling but they answered my questions.

hg-git apparently can be used to work with git locally, with a remote mercurial repo: http://traviscline.com/blog/2010/04/27/using-hg-git-to-work-in-git-and-push-to-hg/

Don't miss the comments there too.

I haven't tried this, but there seems to be a git-hg project. The project describes itself on the page and the README as:

A git-hg utility for checking out and tracking a mercurial repo.

A set of scripts for checking out and tracking a mercrial [sic] project.

It doesn't seem to work bi-directionally though (see issue tracker).

There is a new project that accomplishes just that:

It does the two-way thing nicely integrated.

There is another project to realize this: git-remote-hg. Actually two of them, a native one (see https://github.com/msysgit/msysgit/wiki/Guide-to-git-remote-hg) and another one based upon hg-git (see https://github.com/rfk/git-remote-hg). The former is much faster than the latter, but still incomplete and under development.

There are actually git remote helpers (as these tools are called) for other systems, either already there or under development; this includes support for Subversion, CVS, bazaar, and even MediaWiki.

Cloning a Mercurial repository via git then is simply done like this:

git clone hg::https://hg.example.com/some-mercurial-repo

UPDATE: By now there is a third one, also "native", namely the one by Felipe which he mentions in his answer here. This one looks like it soon might be part of the git 'contrib' dir: https://github.com/felipec/git-remote-hg It works without requiring patches to git itself, though some patches to git (under review now) can be applied to improve the overall user experience.

UPDATE 2: And now there is yet another contender, this one being under quite active development, and based on felipe's code: https://github.com/buchuki/gitifyhg -- it works quite well for me so far, but there are still some rough spots.

UPDATE 3: Both gitifyhg and Felipe's git-remote-hg are currently not actively maintained. For the time being, I made a form of Felipe's code with some fixes, including some to make it work with recent Mercurial versions. You can get it from https://github.com/fingolfin/git-remote-hg. Finally, therere is yet another recent contender, git-cinnabar, using a completly different approach internally (though if you don't care about that, using it is more or less the same as for the other git-remote-hg implementations). I have not yet tried it myself, but you can find it at https://github.com/glandium/git-cinnabar

Somebody already mentioned two git-remote-hg's, but here's a new one:

Bridge support in git for mercurial and bazaar

It has more features and should work more reliably than the msysgit one, but most importantly; you don't need any dependencies or a custom git build. Just copy to your $PATH, and that's it.

It has extensive tests to check that the output is exactly the same as hg-git, so it should work at least as well.