在 Windows 上将 Mercurial (hg) 存储库转换为 Git (7)
我现在真的很沮丧。我有一个现有的 hg 存储库,其中有几个月的编码历史,我想将其放入私有 Github 存储库中,以便我可以从那里对其进行处理。不幸的是,我使用 Windows,而且我似乎找不到任何方法来转换我实际上可以正常工作的存储库。实际上,我在网上可以找到的所有帮助和建议似乎都假设我是从某种 *nix shell 运行的,但我不是。
我目前已经安装了:TortoiseHG、Python 3.1 和 Git for Windows。
我尝试过的:
- hg 的 hg-init 插件 - 当我尝试使用 gexport 命令(以及来自 hg-git 的其他命令)时,我只得到 python 异常字符串。我完全无法让 git 识别 grmote 命令。我尝试按照这里的内容操作: http://github.com/blog/439- hg-git-mercurial-plugin
hg-to-git(快速导出) - 所有教程都期望我运行 .sh 文件。另一个 stackoverflow 线程似乎暗示 Powershell 可以运行 .sh 文件,但我无法让它在我的一生中运行它们。示例: http://hivelogic.com/articles/converting-from-mercurial-to -git
Mercurial 到 git 转换器 - http:// /permalink.gmane.org/gmane.comp.version-control.git/36601 - 当我通过 Python 运行它时,它不想工作,它抱怨它在第 44 行有语法错误。我不懂 python,所以我不知道。
我在谷歌上搜索了四个小时,费力地浏览了无用的教程,还有比我更幸运的人对每一篇据称有帮助的博客文章大加赞扬,但我却一无所获。有人可以提供任何帮助或建议让我尝试吗?
I'm really quite frustrated at this point. I have an existing hg repository that has months of coding history in it, and I want to get this into a private Github repository so I can work on it from there. Unfortunately I use Windows and I can't seem to find any way to convert the repository that I can actually get to work properly. Practically every bit of help and advice I can find online seems to assume I'm running from some kind *nix shell, which I'm not.
I currently have installed: TortoiseHG, Python 3.1 and Git for Windows.
What I've tried:
hg-init plugin for hg - When I try to use the gexport command (and others from hg-git), I just get strings of python exceptions. I totally can't get git to even recognise the gremote command. I tried following what was here: http://github.com/blog/439-hg-git-mercurial-plugin
hg-to-git (fast-export) - All tutorials keep expecting me to run a .sh file. Another stackoverflow thread seemed to imply that Powershell can run .sh files, but I can't make it run them for the life of me. Example: http://hivelogic.com/articles/converting-from-mercurial-to-git
Mercurial to git converter - http://permalink.gmane.org/gmane.comp.version-control.git/36601 - This one doesn't want to work when I run it via Python, which complains that it has a syntax error on line 44. I don't know python, so I've got no idea.
Four hours of Google searching and wading through useless tutorials and people-more-fortunate-than-me singing the praises of each supposedly-helpful blog post, but I haven't gotten anywhere with this. Can anyone offer any assistance or suggestions for me to try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
git-hg clone ...url...
或者告诉我这个 hg 的 url 是什么你的仓库,我可以为你转换它。
git-hg clone ...url...
Or tell me what the url is for this hg repo of yours, and I can convert it for you.
关于如何在 Windows 上将 Mercurial 存储库转换为 Git,存在很多相互矛盾的信息。这确实非常简单,只需要安装 TortoiseHg 和 Git。
准备工作
通过将以下内容添加到 Mercurial 配置文件 (%Userprofile%\mercurial.ini) 来启用 hg-git:
转换
导航到存储库目录(包含 .hg子目录)并执行以下命令:
更多信息
您可以在我的 关于该主题的博客文章。
There is a lot of conflicting information about how to convert Mercurial repositories to Git on Windows. It really is pretty easy and only requires TortoiseHg and Git to be installed.
Preparation
Enable hg-git by adding the following to your Mercurial config file (%Userprofile%\mercurial.ini):
Conversion
Navigate to the repository directory (that contains the .hg subdirectory) on the command line and execute the following commands:
More information
You can find a detailed description of these steps in my blog article on the subject.
您是否考虑过安装 msysgit?它为您提供的 git bash shell 应该能够运行 .sh 文件。
Have you considered installing msysgit? The git bash shell it gives you should be able to run .sh files.
我读到的有关 Git 的 Hg 转换器的所有内容都指出了您所犯的一个明显错误:使用 Python 3!
您遇到的那些 Python 错误是由于使用 Python 2.6 构建的 hg-git 和 fast-export 等脚本造成的。 Python 3 对待“打印”的方式不同,因此会出现错误。
重写脚本以适用于您的版本或安装 Python 2.6。
确保将其添加到您的 PATH 设置中。安装 msysGit 时也是如此。确保在安装时选择第二个选项以将 Git 添加到您的路径。
您还需要 Mercurial For Python,可从 TortoiseHG 的 thg-winbuild 项目获取:
https://bitbucket.org/ tortoisehg/thg-winbuild/downloads
对于 64 位 Windows,该文件将命名为“mercurial-2.2.2.win-amd64-py2.6.exe”
和 32 位的“mercurial-2.2.2.win32-py2.6.exe”。在此过程中,请获取配套的 Mercurial 2.2.2 安装程序,以防万一。
尽管您声明您不希望安装另一个 VCS 软件,但使用任何这些 Hg 转换器都需要安装 Mercurial。
另一个需要注意的陷阱是这些转换器可能无法与最新版本的 Mercurial 配合使用。您可能需要对旧版本进行一些试验,以找到与脚本配合良好的版本。
请务必仔细阅读您决定使用的任何转换器的教程和自述文件。看来你的很多悲伤和麻烦都源于在浏览完文档后不耐烦地跳入深渊。
有一些可用的补丁可以为 Git 和 msysGit 添加 Mercurial 支持,但如果您希望遵循该路线,则需要熟悉从源代码进行修补和编译。
Everything I've read about these Hg converters for Git does point out one obvious error you've made: Using Python 3!
Those Python errors you've been getting are due to scripts like hg-git and fast-export being built using Python 2.6. Python 3 treats "print" differently, hence your errors.
Either rewrite the scripts to work with your version or install Python 2.6.
Make sure to add it to your PATH setting. Same goes for when you install msysGit. Be sure you choose the second option at install to add Git to your path.
You also need Mercurial For Python, available at TortoiseHG's thg-winbuild project:
https://bitbucket.org/tortoisehg/thg-winbuild/downloads
The file will be named 'mercurial-2.2.2.win-amd64-py2.6.exe' for 64-bit Windows
and 'mercurial-2.2.2.win32-py2.6.exe' for 32-bit. While you're at it, get the companion Mercurial 2.2.2 installer, just in case.
Although you stated you don't wish to install yet another VCS software, using any of these Hg converters requires Mercurial to also be installed.
Another pitfall to look out for is these converters may not work with the latest versions of Mercurial. You might need to experiment a bit with older releases to find one that works well with the scripts.
Be sure to carefully read through the tutorials and the Readme files for whichever converter you settle upon using. It seems a lot of your grief and trouble stems from having impatiently jumped into the deep end after only skimming the documentation.
There are patches available that add Mercurial support to Git and msysGit, but you'll need to be comfortable with patching and compiling from source if you wish to follow that route.
这可能看起来很愚蠢(或者是绝望者的解决方案......),但我认为 Bazaar 对 Hg 和 Git 存储库都有很好的支持,并且它在 Windows 上运行良好。
因此,如果所有其他方法都失败,也许您可以使用 bzr-hg 和 bzr-git 进行转换...
It might seem silly (or a solution for the desperate...) but I think that Bazaar has good support for both Hg and Git repositories, and it works well on Windows.
So if all else fails, maybe you can use bzr-hg and bzr-git to make the conversion...
如果原始的 Mercurial 存储库在网络上可用,并且您不介意使用 GitHub 来执行此操作,那么从 Mercurial 转换到 Git 现在非常简单:
+
。导入存储库
。开始导入
并等待。之后您甚至不需要停留在该页面上。稍后,GitHub 会通过电子邮件通知您导入完成。
If the original Mercurial repo is available on the web, and if you don't mind using GitHub to do this, converting from Mercurial to Git is now trivially easy:
+
in the upper-right.Import repository
.Begin import
and wait.You don't even need to stay on the page after that. After a while, GitHub will notify you by e-mail that the import is finished.