Reputation: 321
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.
Upvotes: 6
Views: 2154
Reputation: 11
Disclaimer: the following solution only works if you are willing to fold the subrepos into the main repository, which may or may not be acceptable to you.
In short: convert each subrepo to git, convert the main repo to git, and have git merge the repos.
Set up fast-export. It requires Python 2.7 and Mercurial 4.6.
For each subrepo:
git init; git config core.ignoreCase false;
git reset --hard HEAD
to repopulate the directorygit remote add subrepo1 path/to/subrepo1
git fetch subrepo1 --tags
git merge subrepo1/master --allow-unrelated-histories
git remote remove subrepo1
1For instance, in my case, the initial folder structure was like:
Main Repo
|- SubRepo1
L SubRepo1-Data
|- SubRepo2
L OtherStuff
And after conversion, the new repo was configured as:
SubRepo1 (master)
L SubRepo1-Data
So we needed to add a folder level to the the subrepos so that they were like:
SubRepo1 (master)
L SubRepo1
L SubRepo1-Data
Upvotes: 0
Reputation: 1296
Having a similar problem (moving a Mercurial project with subrepositories to Git with a unified layout) I intend to follow a 2-fold approach:
I'm just about to test this myself and will update this answer according to the results...
Upvotes: 1
Reputation: 1831
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.
Upvotes: 1