Convert multiple hg repositories to single git repository with multiple branches
I am switching to git from Mercurial and have been using hg-fast-export successfully. Now I have a tricky situation. I have a project which is using separate hg repositories per-branch and I want to conver开发者_如何转开发t these to a single git repository with 'proper' branches, keeping my hg changesets if possible.
So the current structure looks like this - each folder is an hg repository:
Project-v1.0
Project-v2.0
Project-v3.0
I want to end up with a single git repository called 'Project' that contains 3 branches, v1.0, v2.0 and v3.0.
Is this possible?
When the hg repositories are clones from one base repo, you can use the hggit extension to export them into one git repo. Say your branches live in the directories b1/, b2/ and b3/, then all you need is to
cd b1; mkdir ../gb1 && git init --bare ../gb1 && hg push ../gb1; cd ..
cd b2; mkdir ../gb1 && git init --bare ../gb2 && hg push ../gb2; cd ..
cd b3; mkdir ../gb1 && git init --bare ../gb3 && hg push ../gb3; cd ..
# now you have one git repo for each hg branch
cd gb1
git remote add gb2 ../gb2
git remote add gb3 ../gb3
git fetch --all
# now you have all branches in the gb1 repo
rm -r ../gb2 ../gb3
# the other repos are now not used anymore
If the different hg repos are unrelated, you have to use the graft point solution which VonC mentioned.
This should be possible with:
- creating 3 distinct Git repos from the three Mercurial ones
- importing
Project-v2.0
history intoProject-v1.0
Git repo (by addingProject-v2.0
as a remote and fetching it in a 'v2.0
' branch: 2 distinct roots are created)
And, through a graft point, linking the two branches together (theHEAD
ofv1.0
branch becomes the parent of the first commit ofv2.0
branch). - using
filter-branch
to make those graft points permanent (i.e. not limited to your repo)
(repeat for the Project-v3.0
, fetch into the first one into a separate v3.0
branch, grafted to the HEAD
of v2.0
branch, and filter-branch to make the graft permanent)
You have a similar scenario (although it is about "prepend some history", not "append") in the SO question "How to prepend the past to a git repository?".
精彩评论