跳至主要内容

导入 Mercurial 仓库

您可以先将 Mercurial 仓库转换为 Git,然后将该 Git 仓库推送到 GitHub,从而导入 Mercurial 仓库。

先决条件

要执行以下步骤,您必须使用 macOS 或 Linux 系统,并且已安装以下工具。

导入 Mercurial 仓库

  1. 在 GitHub 上创建一个新仓库。为避免错误,请不要在新仓库中初始化 README、许可证或 .gitignore 文件。您可以在项目推送到 GitHub 后再添加这些文件。更多信息请参阅 创建新仓库

  2. 要确认您的机器上已安装 Mercurial,请运行 hg --version

    输出应类似于 Mercurial Distributed SCM (version 6.4)

  3. 要确认机器上已安装 Git,请运行 git --version

    输出应类似于 git version 2.40.0

  4. 要确认机器上已安装 Git LFS,请运行 git lfs --version

    输出应类似于 git-lfs/3.1.4 (GitHub; darwin arm64; go 1.18.1)

  5. 要确认您的机器上已安装 pip,请运行 pip --version

    输出应类似于 pip 21.2.4

  6. 要安装 mercurial Python 包,请运行 pip install mercurial

  7. 下载最新版本的 fast-export 到本机,然后解压归档文件。

  8. 进入解压后的目录,然后运行 ./hg-fast-export.sh --help

    输出应以 usage: hg-fast-export.sh 开头。

  9. 克隆您的 Mercurial 仓库。

    例如,要将 Mercurial 本身的源码克隆到 mercurial-repo 目录,运行 hg clone https://www.mercurial-scm.org/repo/hg mercurial-repo

  10. 创建一个新目录,进入该目录,然后初始化一个全新的 Git 仓库。

    例如,如果您想将新仓库命名为 mercurial-git,运行 mkdir mercurial-git && cd mercurial-git && git init

  11. 进入新创建的 Git 仓库所在的目录。

  12. 要使新 Git 仓库在文件名大小写处理上与 Mercurial 保持一致,运行 git config core.ignoreCase false

  13. 要获取 Mercurial 项目中的提交者列表并将其存入 committers.txt,请运行以下脚本。

    Shell
    hg log --template "{author}\n" | sort | uniq > committers.txt
    
  14. 更新您的 committers.txt 文件,将 Mercurial 仓库中使用的提交者姓名映射为您希望在 Git 仓库中使用的姓名,格式如下:

    “The Octocat <octocato@gmail.com>”=”Octocat <octocat@github.com>”
    
  15. 在已初始化的 Git 仓库中,运行 hg-fast-export.sh,并将 Mercurial 仓库的路径以及 committers.txt 文件的路径作为参数传入。

    例如,../fast-export-221024/hg-fast-export.sh -r ../mercurial-repo -A ../mercurial-repo/committers.txt -M main

  16. 导入完成后,检出新创建的 Git 仓库,运行 git checkout HEAD

  17. 要将 GitHub 仓库添加为远程仓库,请运行 git remote add origin URL,将 URL 替换为您之前创建的 GitHub 仓库的链接,例如 https://github.com/octocat/example-repository.git

  18. 要将仓库推送到 GitHub,请运行 git push --mirror origin

    如果仓库中包含任何超出 GitHub 文件大小限制的文件,推送可能会失败。请通过运行 git lfs import 将大文件迁移到 Git LFS,然后重新尝试。

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.