Is there any existing tool that is able to export a mercurial repository to a git repository while preserving the commit hashes?
I'm aware of hg-git or fast-export.git, but those create new commits with new hashes (and there doesn't seem to be any option to configure this). We have hundreds of mercurial repositories hosted on Bitbucket with large amount of hooks, download links etc. dependent on exact hashes. Being able to preserve hashes would save us considerable amount of efforts needed to update all external resources.
It's not possible.
The hash ID of a Git object is a cryptographic checksum of the underlying object data. In the case of a commit object, that's a cryptographic checksum of the string commit
, a space, the size in bytes of the rest of the data expressed in decimal, an ASCII NUL, and then the headers, log message text, and trailers.
The hash ID of a Mercurial commit is a cryptographic checksum of an appropriate part of the Mercurial data for that commit (Mercurial's data structures are different so some commit data do not participate in the checksum).
The only known way today to construct a specific hash ID from some known data—as you would have in a Git commit—is to add a "junk" data area, then spend many CPU-years computing hashes with different contents in the junk-data. The team that created shattered used 110 GPU-years of compute-time to find one duplicate hash ID.