我在Mac上使用GIT。我有工具,我有经验。我想继续使用它。这里没有战争……

问题总是与互操作性有关。大多数人使用SVN,这对我来说很棒。Git SVN开箱即用,是一种简单的解决方案。人们可以继续愉快地使用SVN,我也不会丢失我的工作流程和工具。

现在…有些人跟着Mercurial。对他们来说很好:他们有自己的理由。但是我找不到任何现成的GIT HG。我不想切换到HG,但我仍然需要与他们的存储库进行互操作。

你们有谁知道简单的解决办法吗?


当前回答

有一个新的git-remote-hg提供本地支持:

Git中对Mercurial和Bazaar的桥接支持

只需要复制git-remote-hg到你的$PATH,让它可执行,就是这样,没有依赖(除了Mercurial):

git clone hg::https://www.mercurial-scm.org/repo/hg/

您应该能够从它中推入和拉出,就像它是一个原生Git存储库一样。

当您推送新的Git分支时,将为它们创建Mercurial书签。

有关更多信息,请参阅git-remote-hg wiki。

其他回答

我已经从https://github.com/cosmin/git-hg的git-hg取得了巨大的成功(也需要安装hg)。它支持取,拉和推,对我来说比hg-git更稳定(hg到git的类似功能)。

有关用法示例,请参阅https://github.com/cosmin/git-hg#usage。用户界面非常类似于git-svn。

git-hg对于每个克隆的hg repo都需要额外的磁盘空间。实现使用完整的mercurial克隆,一个额外的git裸克隆和实际的git回购。所需的磁盘空间大约是正常git使用量的3倍。额外的副本存储在工作目录的.git目录下(或通常由GIT_DIR指定的位置)。

注意:git-hg试图解决的基本问题是git和hg特性之间没有1:1的映射。最大的问题是git分支和hg未命名分支以及hg已命名分支和hg书签之间的阻抗不匹配(所有这些在git用户看来都很像分支)。一个相关的问题是hg试图在版本历史中保存原始的命名分支名称,而git在默认情况下只将分支名称添加到模板提交消息中。

任何声称在git和hg之间创建互操作桥梁的工具都应该解释它将如何处理这种阻抗匹配。然后您可以决定所选的解决方案是否适合您的需求。

git-hg使用的解决方案是丢弃所有hg书签,并将命名的分支转换为git分支。此外,它将git主分支设置为默认的未命名hg分支。

Hg-Git Mercurial插件。我自己还没试过,但可能值得一试。

您可以尝试hg2git,这是一个python脚本,是fast-export的一部分,您可以在http://repo.or.cz/w/fast-export.git上找到它。

不过,您需要安装mercurial。

由于hg-git是一个双向桥接,它还允许您将更改集从Git推到Mercurial。

2012年6月更新。目前,当开发者想从Git端工作时,Git/Hg的互操作性似乎有以下几种方法:

安装Mercurial和hg-git扩展。您可以使用包管理器或easy_install hg-git完成后一项操作。然后确保你的~/.hgrc中有以下文件: (扩展) hggit =

您可能会在这里看到一些关于指定书签扩展的参考,但这是自v 1.8以来内置到Mercurial的。这里有一些关于在Windows上安装hg-git的提示。

一旦你有hg-git,你可以使用类似Abderrahim Kitouni上面发布的命令。自2009年以来,这个方法已经得到了改进和调整,并且有一个友好的包装器:git-hg-again。这将同时使用顶层目录作为Mercurial和Git的工作目录。它创建一个与Mercurial存储库中默认(未命名)分支的提示保持同步的Mercurial书签,并从该书签更新本地Git分支。

git-remote-hg is a different wrapper, also based on the Mercurial hg-git extension. This additionally makes use of the git-remote-helpers protocols (hence its name). It uses the toplevel directory only for a Git working directory; it keeps its Mercurial repository bare. It also maintains a second bare Git repository to make synching between Git and Mercurial safer and more idiomatically gitlike. The git-hg script (formerly maintained here) uses a different method, based on hg-fast-export from the fast-export project. Like method 2, this also keeps a bare Mercurial repository and an additional bare Git repository.

对于拉取,该工具忽略Mercurial书签,而是将每个已命名的Mercurial分支导入Git分支,并将默认的(未命名的)Mercurial分支导入master。

一些评论讨论这个工具只是hg->git,但它声称已经在2011年12月7日合并到git->hg推送支持中。但是,正如我在对这些工具的回顾中所解释的那样,这个工具试图实现推送支持的方式似乎并不可行。

还有另一个项目叫做git-remote-hg。与上面列出的版本不同,这个版本不依赖hg-git,而是直接访问Mercurial Python API。目前,使用它还需要一个补丁版本的git。我还没试过。 最后,Tailor是一个在各种不同的vcs之间进行增量转换的项目。听起来这方面的发展不会继续下去。

The first three of these approaches looked lightweight enough to persuade me to investigate. I needed to tweak them in some ways to get them to run on my setup, and I saw some ways to tweak them further to improve them, and then I tweaked them still further to make them behave more like each other so that I could evaluate them more effectively. Then I thought others might like to have these tweaks too, to do the same evaluation. So I've made a source package that will enable you to install my versions of any of the first three tools. It should also take care of installing the needed hg-fast-export pieces. (You need to install hg-git on your own.)

我鼓励你尝试一下,自己决定哪种效果最好。我很高兴听到这些工具坏了的情况。我将努力使它们与上游的更改保持同步,并确保上游作者意识到我认为有用的调整。

正如我上面提到的,在评估这些工具时,我得出的结论是git-hg只能用于从Mercurial提取,而不能用于推送。

相关的,这里有一些Git和Mercurial之间有用的比较/翻译手册,在某些情况下针对已经了解Git的用户:

针对Git用户的Mercurial Git和Mercurial -比较和对比 Mercurial和Git的区别是什么 Mercurial和Git:技术上的比较 去罗塞塔石碑 自制编码:Mercurial Francisoud的博客:Git vs Mercurial Git vs Mercurial