When using git to clone an hg repository, or when migrating from hg to git, will the hashes remain the same?
Asked
Active
Viewed 137 times
1 Answers
4
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}

Catskul
- 17,916
- 15
- 84
- 113
-
1That's right: Mercurial hashes commits, but commits contain very different data from Git commits. Mercurial does not hash files' contents and there is no concept of a *tree* or *blob* object; commits store their branch name (well, actually an index) and are therefore permanently attached *to* that branch; and commits have a local sequential index number, in Mercurial. – torek Apr 02 '19 at 16:09
-
1Mercurial does hash file contents, according to the formula on this page: https://www.mercurial-scm.org/wiki/Nodeid – ngoldbaum Apr 05 '19 at 21:01