简体   繁体   English

在 Windows 上将 Mercurial (hg) 存储库转换为 Git (7)

[英]Converting a Mercurial (hg) repository to Git on Windows (7)

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.我有一个现有的 hg 存储库,其中有数月的编码历史记录,我想将其放入私有 Github 存储库中,以便我可以从那里进行处理。 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.不幸的是,我使用 Windows,我似乎找不到任何方法来转换我实际上可以正常工作的存储库。 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.实际上,我可以在网上找到的每一点帮助和建议似乎都假设我是从某种 *nix shell 运行的,而我不是。

I currently have installed: TortoiseHG, Python 3.1 and Git for Windows.我目前已安装:TortoiseHG、Python 3.1 和适用于 Windows 的 Git。

What I've tried:我试过的:

  1. 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. hg 的 hg-init 插件 - 当我尝试使用 gexport 命令(以及来自 hg-git 的其他命令)时,我只得到 python 异常字符串。 I totally can't get git to even recognise the gremote command.我完全无法让 git 甚至识别 gremote 命令。 I tried following what was here: http://github.com/blog/439-hg-git-mercurial-plugin我尝试遵循这里的内容: http : //github.com/blog/439-hg-git-mercurial-plugin

  2. hg-to-git (fast-export) - All tutorials keep expecting me to run a .sh file. hg-to-git (fast-export) - 所有教程都希望我运行 .sh 文件。 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.另一个 stackoverflow 线程似乎暗示 Powershell 可以运行 .sh 文件,但我无法让它终生运行它们。 Example: http://hivelogic.com/articles/converting-from-mercurial-to-git示例: http : //hivelogic.com/articles/converting-from-mercurial-to-git

  3. 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. Mercurial 到 git 转换器 -http://permalink.gmane.org/gmane.comp.version-control.git/36601 - 当我通过 Python 运行它时,它不想工作,它抱怨它有语法错误在第 44 行。我不知道 python,所以我不知道。

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?任何人都可以提供任何帮助或建议让我尝试吗?

  1. Install Cygwin (with python, hg, git)安装Cygwin (使用 python、hg、git)
  2. Install git-hg安装git-hg
  3. run git-hg clone ...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.或者告诉我你的这个 hg repo 的 url 是什么,我可以为你转换它。

There is a lot of conflicting information about how to convert Mercurial repositories to Git on Windows.关于如何在 Windows 上将 Mercurial 存储库转换为 Git,有很多相互矛盾的信息。 It really is pretty easy and only requires TortoiseHg and Git to be installed.这真的很简单,只需要安装 TortoiseHg 和 Git。

Preparation准备

Enable hg-git by adding the following to your Mercurial config file ( %Userprofile%\\mercurial.ini ):通过将以下内容添加到 Mercurial 配置文件 ( %Userprofile%\\mercurial.ini ) 来启用 hg-git:

[extensions]
hggit = 
hgext.bookmarks =

[git]
intree = True

Conversion转换

Navigate to the repository directory (that contains the .hg subdirectory) on the command line and execute the following commands:在命令行上导航到存储库目录(包含.hg子目录)并执行以下命令:

hg bookmark -r default master
hg gexport --debug
git config --bool core.bare false
git reset HEAD -- .

More information更多信息

You can find a detailed description of these steps in my blog article on the subject.您可以在我关于该主题的博客文章中找到这些步骤的详细说明。

Everything I've read about these Hg converters for Git does point out one obvious error you've made: Using Python 3!我读到的关于这些用于 Git 的 Hg 转换器的所有内容都指出了您犯的一个明显错误:使用 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 错误是由于 hg-git 和 fast-export 等脚本是使用 Python 2.6 构建的。 Python 3 treats "print" differently, hence your errors. Python 3 以不同的方式对待“打印”,因此会出现错误。

Either rewrite the scripts to work with your version or install Python 2.6.重写脚本以使用您的版本或安装 Python 2.6。

Make sure to add it to your PATH setting.确保将其添加到您的 PATH 设置中。 Same goes for when you install msysGit.安装 msysGit 时也是如此。 Be sure you choose the second option at install to add Git to your path.确保在安装时选择第二个选项以将 Git 添加到您的路径。

You also need Mercurial For Python, available at TortoiseHG's thg-winbuild project:您还需要 Mercurial For Python,可在 TortoiseHG 的 thg-winbuild 项目中获得:

https://bitbucket.org/tortoisehg/thg-winbuild/downloads 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.对于 64 位 Windows,该文件将命名为“mercurial-2.2.2.win-amd64-py2.6.exe”,对于 32 位,该文件将命名为“mercurial-2.2.2.win32-py2.6.exe”。 While you're at it, get the companion Mercurial 2.2.2 installer, just in case.在此期间,请获取配套的 Mercurial 2.2.2 安装程序,以防万一。

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.尽管您声明不想再安装另一个 VCS 软件,但使用这些 Hg 转换器中的任何一个都需要安装 Mercurial。

Another pitfall to look out for is these converters may not work with the latest versions of Mercurial.另一个需要注意的陷阱是这些转换器可能不适用于最新版本的 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.有可用的补丁可以为 Git 和 msysGit 添加 Mercurial 支持,但是如果您希望遵循该路线,则需要对从源代码进行补丁和编译感到满意。

Have you considered installing msysgit ?您是否考虑过安装msysgit The git bash shell it gives you should be able to run .sh files.它给你的 git bash shell 应该能够运行 .sh 文件。

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.这可能看起来很愚蠢(或绝望的解决方案......)但我认为 Bazaar 对 Hg 和 Git 存储库都有很好的支持,并且它在 Windows 上运行良好。
So if all else fails, maybe you can use bzr-hg and bzr-git to make the conversion...因此,如果所有其他方法都失败了,也许您可​​以使用bzr-hg和 bzr-git 进行转换...

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:如果原始 Mercurial 存储库在网络上可用,并且您不介意使用 GitHub 来执行此操作,那么从 Mercurial 转换为 Git 现在非常简单:

  1. Log in to GitHub.登录到 GitHub。
  2. Click the + in the upper-right.单击右上角的+
  3. Select Import repository .选择Import repository
  4. Supply the Mercurial repository's URL, a name for it under your account, and whether it'll be public or private.提供 Mercurial 存储库的 URL、您帐户下的名称以及它是公共的还是私有的。
  5. Click Begin import and wait.单击Begin import并等待。

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.一段时间后,GitHub 将通过电子邮件通知您导入已完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM