【问题标题】:Converting Mercurial folder to a Git repository将 Mercurial 文件夹转换为 Git 存储库
【发布时间】:2012-05-29 10:18:03
【问题描述】:

我在 Mercurial 方面没有丰富的经验,我主要是一个 Git 人。

我希望在 git 存储库中镜像特定的 Mercurial 文件夹/文件。我实际上想要做的是将文件的历史从 Mercurial 存储库导出到 Git,并能够与未来的提交保持同步。

您对如何进行有什么建议吗?我相信要走的路应该是获取 Mercurial 补丁的历史记录,定期将每个提交导出为补丁并将 Mercurial 补丁应用到 Git 存储库。

【问题讨论】:

标签: git mercurial


【解决方案1】:

Linux 或任何带有bash/sh 或类似名称或python 的平台上,请尝试使用fast export

cd
git clone git://repo.or.cz/fast-export.git
git init git_repo
cd git_repo
~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD

【讨论】:

  • 好的,你想让 git 与 mercurial 保持同步吗?喜欢this
  • 注意 '/path/to/old/mercurial_repo' 必须是文件系统上的路径(不是 URL),所以你必须先克隆原始存储库。
  • 在我的情况下必须使用PYTHON=python2 ~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo。除此之外,它完美无缺。
  • 感谢您的简洁回答!我必须先sudo easy_install mercurial。在说明中会很高兴
  • 如果你在 Windows 机器上使用 Git bash 并运行 hg-fast-export.sh
【解决方案2】:

您可以(从 Mercurial 方面):

  • 使用 Convert extension--filemap 选项将原始 repo 的一部分转换为更小的只有需要的文件|目录
  • 使用 hg-git 扩展将剥离的 repo 推送到 Git

或(而不是 hg-git),使用 Mercurial bridge in Git,克隆|从 Git 中提取存储库

【讨论】:

    【解决方案3】:

    Gitify

    似乎是一种更现代且易于使用的替代方法来执行转换 https://github.com/buchuki/gitifyhg

    pip install gitifyhg
    git clone gitifyhg::<hgrepoaddress>
    # done, you have a git repo with the entire history of the hg one
    

    【讨论】:

    • 我不想转换整个仓库,只是一个文件夹。
    • 太棒了!尽管github.com/buchuki/gitifyhg/pull/98 谨防 unicode 错误
    • 注意 - gitifyhg 目前与最新的 Mercurial 版本严重过时。
    【解决方案4】:

    Windows:TortoiseHG Hg-Git 扩展

    Hg-Git 可用于将 Mercurial 存储库转换为 Git。您可以使用本地存储库或通过 SSH、HTTP 或 HTTPS 访问的远程存储库。

    本地存储库转换示例。

    1. 安装 Hg-Git。

      • 在 Windows 上,TortoiseHg 带有 Hg-Git,但您需要通过设置工具(在扩展部分中)enable it

        或手动输入~/mercurial.ini

        [extensions]
        hggit =
        
    2. 使用以下命令转换存储库:

      $ mkdir git-repo; cd git-repo; git init; cd ..
      $ cd hg-repo
      $ hg bookmarks hg
      $ hg push ../git-repo
      

    hg 书签对于防止出现问题是必要的,否则 hg-git 推送到当前签出的分支会混淆 Git。这将在 Git 存储库中创建一个名为 hg 的分支。要获取 master 中的更改,请使用以下命令(仅在第一次运行时需要,以后只需使用 git mergerebase):

    $ cd git-repo
    $ git checkout -b master hg
    

    【讨论】:

    • 我发现 git-hg 有很多错误,但这就像一个魅力,并且不需要任何额外的下载,这很好。
    • 我想要一个文件夹,而不是整个仓库。
    • github 现在有一个工具可以直接从 github 支持这个,见 stackoverflow.com/questions/16037787/…
    • @SimoneCarletti 看看this question。它应该可以帮助您将文件/文件夹及其历史记录导出到临时存储库中。然后,您可以使用提供的任何解决方案将临时 Mercurial 存储库转换为 Git。
    【解决方案5】:

    在 Windows 上可能有点棘手。在 mercurial(hggit) 中启用正确的插件后,也可以使用 TortoiseHG。

    1. 克隆 mercurial 回购
    2. 克隆 git 仓库
    3. 启用控制台: Enabling console
    4. 使用控制台:

      % hg bookmarks hg

      % hg push &lt;relative path to&gt;/&lt;git-repo&gt;

    【讨论】:

      【解决方案6】:

      hg-git-fast-import

      https://github.com/kilork/hg-git-fast-import

      另一个具有以下功能的实用程序:

      1. 将单个和多个 Mercurial 存储库导入到 Git 存储库。
      2. 将新修订从之前导入的 Mercurial 存储库导入到 Git 存储库。
      3. 标签。
      4. 关闭的分支机构。
      5. 使用差异验证最终结果。

      您可以为您下载二进制文件platform 并将其放在路径中的某个位置或使用cargo 安装(要求rustinstalled):

      cargo install hg-git-fast-import
      

      那么用法是这样的:

      hg-git-fast-import single /path/to/source_hg /path/to/target_git
      

      不需要安装PythonMercurial。高级配置允许替换作者或分支,使分支前缀等等。

      【讨论】:

        【解决方案7】:

        在 Windows 10 上将 Mercurial 存储库转换为 Git

        如果编码没有问题 - 使用 TortoiseHG Hg-Git 扩展

        md new-repo && cd new-repo
        git init --bare .git
        cd ..\old-mercurial-repo
        hg bookmark -r default master
        hg push ..\new-repo
        cd ..\new-repo
        git config --bool core.bare false
        

        如果编码有问题 - 使用快速导出

        安装 Bash

        以管理员身份打开 PowerShell 并运行:

        Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
        

        Microsoft Store 安装 Ubuntu 16.04 LTS

        打开 Bash 并运行

        安装 mercurial

        sudo -s
        apt-get update
        apt install mercurial
        

        获取快速导出 v180317(目前 180317 之后的版本无法正常工作)

        cd /mnt/c/path_to_work_folder
        git clone https://github.com/frej/fast-export.git
        cd fast-export
        git checkout tags/v180317
        cd ..
        

        转换存储库

        git init new-repo && cd new-repo
        git config core.ignoreCase false && git config core.quotepath off
        ../fast-export/hg-fast-export.sh -r ../path_to_mercurial_repo/ --fe cp1251
        git checkout master
        

        编码选项:

        • -f 编码,如-f cp1251
        • --fe 文件名编码如--fe cp1251

        【讨论】:

          【解决方案8】:

          如果您使用的是 github.com,它们似乎具有导入功能,您只需输入 hg 项目的 URL。

          首先创建一个新存储库,然后在新存储库的登录页面上滚动到底部并点击“导入代码”按钮

          然后输入您之前存储库的 URL 并点击“开始导入”。

          然后 GitHub 会处理剩下的事情!

          请注意,如果需要,GitHub 会要求您提供旧存储库的凭据。

          哦!我找到了official guide

          【讨论】:

            【解决方案9】:

            也许它对今天的某人有所帮助(将 mercurial 存储库转换为 git,同时保留历史记录)。经测试可与 mercurial 4.0.1 一起使用。

            ~$ git clone https://*old_hg_repo*
            ~$ git clone https://github.com/frej/fast-export.git
            ~$ cd fast-export
            ~$ git checkout tags/v180317
            ~$ cd ..
            ~$ mkdir new_git_repo
            ~$ cd new_git_repo
            ~$ git init
            ~$ .../fast-export/hg-fast-export.sh -r ../old_hg_repo/ --force
            ~$ git checkout HEAD
            

            最后推送你新转换的本地仓库。

            ~$ git push REMOTE '*:*'
            

            【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-03-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多