git 中的提交和具有相同历史记录的 Mercurial 存储库是否具有相同的哈希值?

Will commits in git and mercurial repositories with the same history have the same hash?

当使用 git 克隆 hg 存储库时,或者当从 hg 迁移到 git 时,哈希值会保持不变吗?

通过检查,答案似乎是 "no"。

hg clone ssh://some.server.com/path/hgproject/

git clone hg::ssh://some.server.com/path/hgproject/

其次是:

hg log -l 5

git log -n 5

为相同的提交显示不同的提交哈希值。

虽然 git 和 hg 都使用 SHA-1 散列,但它们散列的内容肯定有所不同,也许是元数据。

任何依赖于散列的工具都需要为迁移重写历史记录。

更深入的上下文

根据@ngoldbaum 的评论 & https://www.mercurial-scm.org/wiki/Nodeid:

nodeid = sha1( min(parent1, parent2) + max(parent1, parent2) + contents )

而 git computes it as:

sha1(
    meta data
        commit message
        committer
        commit date
        author
        authoring date
    hash-of-tree-object (effectively the working directory)
)

映射

如果使用 git-remote-hg 进行查看或转换,您可以在 .git/hg/origin/marks-{hg,git}

中找到足够的信息来创建映射