Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contributing patches from Mercurial to Git?

I'd like to fork a Git repository, convert it to Mercurial, and contribute my changes back to the original Git repository when I'm done. I am more concerned with a safe and stable conversion process than its convenience. I will be pulling changes from Git into Mercurial on a regular basis but rarely contributing any changes back.

I'm not comfortable using hg-git because many of the bugs reported against the project have gone unanswered for years. I suspect it's safer to use hg convert to convert Git to Hg than using hg-git.

My question is: say I've already converted the repository to Mercurial and made some changes, how do I contribute these changes back to the official repository? I'd like to contribute my changes back to the official Git repository without losing any history information (that is, I don't want to fold multiple changesets into a one).

What is the easiest and safest way to do this?

like image 472
Gili Avatar asked Jun 26 '12 14:06

Gili


People also ask

How do I migrate my repository from mercurial to Git?

All your branches and tags should be on your new Git server in a nice, clean import. Since Mercurial and Git have fairly similar models for representing versions, and since Git is a bit more flexible, converting a repository from Mercurial to Git is fairly straightforward, using a tool called "hg-fast-export", which you’ll need a copy of:

What happened to Mercurial repository?

Mercurial has lost the popularity war with Git and BitBucket claims that less than 1% of new repositories on their service use Mercurial. The surprising thing is that BitBucket announced that they are deleting Mercurial repositories from their service as of June 2020.

What is mercurial and is it better than Git?

Mercurial is a distributed source control management tool similar to, but less popular than Git. This move isn’t surprising. Mercurial has lost the popularity war with Git and BitBucket claims that less than 1% of new repositories on their service use Mercurial.

Does Bitbucket support Mercurial repositories?

In August 2019, BitBucket – a popular cloud source code hosting and project management service run by Atlassian – announced that it was dropping support for Mercurial repositories. Mercurial is a distributed source control management tool similar to, but less popular than Git. This move isn’t surprising.


1 Answers

You can try and export your Mercurial commits as patches:

hg export --git -r 1 >patch.diff

This .diff file should be recognized by Git and could be added to the git repo with git apply.
(This was suggested in "Convert a Mercurial Repository to Git", where the more up-to-date script hg-fast-export was also mentioned)

The --git option of hg export will make sure you generate diffs in the git extended diff format. See hg help diffs for more information.

like image 85
VonC Avatar answered Oct 05 '22 05:10

VonC