如何将 Mercurial 存储库转换为 Git(支持 LFS)?

Dar*_*ord 5 git mercurial git-lfs

我有一个 Mercurial 存储库,其中包含 300 多个提交,其中还包含许多相对较大(例如 10+ MiB)的文件。我想将其转换为 Git 存储库,保留所有分支和合并,并使用 LFS 扩展来管理大文件。到目前为止,这是我的流程:

  1. 使用以下命令从服务器克隆 Hg 存储库hg clone <URL>
  2. 在其他地方创建一个新的 git 存储库git init
  3. cd进入 git repo,然后使用hg-fast-export -r <hg-repo> -A <authors>. 此时,我有一个可用的存储库,但所有大文件仍然是索引的一部分。我想在其他任何内容“之前”插入一个新的提交.gitignore并插入.gitattributes
  4. 创建一个新的空分支,没有父提交:git checkout --orphan new-root && git rm -rf .
  5. 创建这两个文件并将它们提交到新分支。git add * && git commit -m "Check in git metafiles"
  6. 现在我的“新”根提交已准备就绪,因此我尝试根除整个事情:git checkout master && git rebase --root --onto new-root --preserve-merges

这就是我被困住的地方。在将这个错误转储给我之前,rebase 得到了大约 10 次提交。

error: Your local changes to the following files would be overwritten by merge:
        assets/ui/sayscreen/blackarrow.png
        assets/ui/sayscreen/blackcircle.png
        assets/ui/sayscreen/thoughtbox.png
        assets/ui/sayscreen/translationbox.png
        assets/ui/sayscreen/whitearrow.png
        assets/ui/sayscreen/whitecircle.png
Please commit your changes or stash them before you merge.
Aborting
fatal: cherry-pick failed
Could not pick 01908b624e50709de07685ef8ab158feef02e9e0
Run Code Online (Sandbox Code Playgroud)

真正让我困惑的是,在原始的 Hg 存储库中,此时没有合并;第一次合并提交位于 15。此外,运行会git status列出 50-60 个已修改的文件,尽管此特定提交最初只涉及 8 个文件。最后,使用git ls-files -u尝试查看哪些文件有冲突不会返回任何内容。

由于列出的大多数文件git status都是 PNG 图像,我的第一个想法是 LFS 以某种方式妨碍并试图在变基期间拉出大斑点。然而,在开始整个过程​​之前,我git lfs uninstall在全局上下文中运行,目的是git lfs migrate import --fixup在我对变基操作感到满意之后再进行操作。

是什么导致了这些合并冲突,如何解决它以完成迁移?

小智 1

我最近刚刚从一个扩展了大文件的 Mercurial 存储库转换为 git。以下是一些要点。

  1. 您必须首先将 Mercurial 存储库转换为“正常”存储库。
  2. 在进行“hg clone”时,最好将所有大文件拉到本地。

$hg clone <hg-repo>
$hg -v lfpull --rev "all()"
$cd ..
$hg lfconvert --to-normal <hg-repo> <hg-repo-nolf>
... // verify the repo
$hg-fast-export -r <hg-repo> -A <authors>
Run Code Online (Sandbox Code Playgroud)