Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to migrate mercurial repo with subrepositories to git, preserving history?

I'm trying to migrate a mercurial repository to git, but the problem is that the mercurial repository has subrepositories (some with branches), and lots of merges and branches itself. I'd like the final git repository to keep all this history and be correct and complete when checking out earlier parts of the repository or other branches. I don't need the new repository to have submodules or subtrees, although I would accept a solution using that as well. Some methods I've seen merge all the subrepos at the top of the new repo as branches, which means that checking out in the past doesn't contain all the files that were in subrepos. I've also tried importing everything as branches, resetting the head into the past, merging, and rebasing upwards, but there are too many merges and many conflicts arise, even with --preserve-merges, so I'd rather avoid this. I also couldn't find any way of replicating the mercurial subrepository update history in git as submodule update history. Does anyone have any ideas? Thank you.

like image 909
user397114 Avatar asked May 28 '15 02:05

user397114


2 Answers

Perhaps one thing you could do (but I'm not sure if this would work), is to use hg-git to push to an empty git repository.

Alternatively, you could also look to extend git-cinnabar to support subrepo conversion into submodules.

like image 111
Mathiasdm Avatar answered Oct 08 '22 18:10

Mathiasdm


Having a similar problem (moving a Mercurial project with subrepositories to Git with a unified layout) I intend to follow a 2-fold approach:

  1. convert your subrepositories into a unified project layout in Mercurial - this is covered here: Join multiple subrepos into one and preserve history in Mercurial
  2. now you can migrate to Git easily, I found the official docs the best resource, with a good note on how to clean up commit history (authors): https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git#Mercurial

I'm just about to test this myself and will update this answer according to the results...

like image 42
Gregor Avatar answered Oct 08 '22 19:10

Gregor