Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial -> Git migration with preserving commit hashes

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.

like image 651
Jan Avatar asked Oct 28 '19 18:10

Jan


People also ask

What is git migration?

We've broken down the SVN-to-Git migration process into 5 simple steps: Prepare your environment for the migration. Convert the SVN repository to a local Git repository. Synchronize the local Git repository when the SVN repository changes. Share the Git repository with your developers via Bitbucket.

How long are git commit hashes?

A commit in git always has a hash that contains 40 characters. But to make the id:s easier to handle it also supports using a short version of the id. The short commit id can actually be any number of characters as long as it's unique for a commit within the same repo.


1 Answers

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.

like image 136
torek Avatar answered Oct 10 '22 21:10

torek