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

萝らか妹 提交于 2021-01-28 02:54:48

问题


When using git to clone an hg repository, or when migrating from hg to git, will the hashes remain the same?


回答1:


By inspection, the answer appears to be "no".

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

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

Followed by:

hg log -l 5

git log -n 5

Show different commit hashes for the same commits.

While both git and hg use SHA-1 hashes, there must be a difference in what they are hashing, perhaps the metadata.

Any tooling dependent on the hashes will require history rewriting for a migration.

More in depth context

Per comment by @ngoldbaum & https://www.mercurial-scm.org/wiki/Nodeid:

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

Whereas git computes it as:

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

Mapping

if using git-remote-hg to do the view or conversion you can find enough information to create a mapping in .git/hg/origin/marks-{hg,git}



来源:https://stackoverflow.com/questions/55478180/will-commits-in-git-and-mercurial-repositories-with-the-same-history-have-the-sa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!