简体   繁体   English

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

[英]How can I convert a Mercurial repository to Git (with LFS support)?

I have a Mercurial repo with 300-some commits in it that also contains a number of relatively large (say 10+ MiB) files.我有一个 Mercurial 存储库,其中包含 300 个提交,其中还包含许多相对较大的(比如 10+ MiB)文件。 I'd like to convert this to a Git repository, keep all of the branches and merges, and also use the LFS extension to manage the big files.我想将其转换为 Git 存储库,保留所有分支和合并,并使用 LFS 扩展来管理大文件。 Here's my process thus far:到目前为止,这是我的过程:

  1. Clone the Hg repo from its server using hg clone <URL>使用hg clone <URL>从其服务器克隆 Hg 存储库
  2. Create a new git repo somewhere else with git init使用git init其他地方创建一个新的 git repo
  3. cd into the git repo, then convert with hg-fast-export -r <hg-repo> -A <authors> . cd进入 git repo,然后使用hg-fast-export -r <hg-repo> -A <authors> At this point, I have a working repo, but all the big files are still part of the index.在这一点上,我有一个工作仓库,但所有大文件仍然是索引的一部分。 I want to wedge a new commit in "before" anything else to insert .gitignore and .gitattributes files.我想在“之前”插入一个新的提交来插入.gitignore.gitattributes文件。
  4. Make a new, empty branch with no parent commit: git checkout --orphan new-root && git rm -rf .创建一个没有父提交的新的空分支: git checkout --orphan new-root && git rm -rf .
  5. Create the two files and commit them to the new branch.创建两个文件并将它们提交到新分支。 git add * && git commit -m "Check in git metafiles"
  6. Now my "new" root commit is ready to go, so I try to uproot the whole thing: git checkout master && git rebase --root --onto new-root --preserve-merges现在我的“新”根提交已经准备好了,所以我试着把整个事情连根拔起: git checkout master && git rebase --root --onto new-root --preserve-merges

And this is where I'm stuck.这就是我被困的地方。 The rebase gets about 10 commits in before dumping this error on me.在将此错误转储给我之前,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

What's really confusing me here is that, in the original Hg repository, there is no merge at this point;真正让我困惑的是,在原始 Hg 存储库中,此时没有合并; the first merge commit is at 15. In addition, running git status lists 50-60 modified files, even though this particular commit only touched 8 files originally.第一次合并提交是在 15。此外,运行git status列出 50-60 个修改过的文件,即使这个特定的提交最初只涉及 8 个文件。 Finally, using git ls-files -u to try and see what files are conflicted returns nothing.最后,使用git ls-files -u尝试查看哪些文件有冲突,但不会返回任何内容。

Since most of the files listed by git status are PNG images, my first thought was that LFS was somehow getting in the way and trying to pull out the large blobs during the rebase.由于git status列出的大多数文件都是 PNG 图像,我的第一个想法是 LFS 以某种方式妨碍了并试图在 rebase 期间拉出大 blob。 However, I ran git lfs uninstall in a global context before starting this whole process, with the intent of doing git lfs migrate import --fixup after I was satisfied with the rebase operation.但是,在开始整个过程​​之前,我在全局上下文中运行了git lfs uninstall ,目的是在我对 rebase 操作感到满意后执行git lfs migrate import --fixup

What's causing these merge conflicts, and how can I get around it to finish the migration?是什么导致了这些合并冲突,我该如何解决它以完成迁移?

I just converted to git from a mercurial repo extended with large files recently.我刚刚从最近用大文件扩展的 mercurial repo 转换为 git。 Here are some points.这里有一些要点。

  1. You have to convert the mercurial repo to a "normal" one at first.首先,您必须将 mercurial 回购转换为“正常”回购。
  2. When doing "hg clone", better to pull all large files to local.执行“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>

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

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