1
votes

After using fast-export to migrate a mercurial repository to git, I've found that open named branches that weren't merged to default weren't converted. Now I want to import the outstanding changesets on these branches to the new git repos.

I've tried various approaches including hg-git and hg export, but the problem with these approaches is that the changesets or diffs I want to migrate have different changeset ids, and the processes error out since the history cannot be found.

I'm considering writing a script to automate exporting the changesets from Mercurial, locate the corresponding parent changeset in the new git repo, import to the git stage, and commit, but I'm wondering if a tool for something like this - importing diffs without matching history - already exists. Is there anything out there?

2

2 Answers

1
votes

You can convert hg to git by these steps:

  1. In TortoiseHg -> global setting -> Extensions Tab -> select hggit
  2. Create an initial git repo:

mkdir git cd git git init cd ..

  1. Clone a hg repo and push it to git

hg clone <URL for hg repo> hg bookmarks hg hg push ../git

  1. In git repo, find the changeset for hg

cd .. cd git git checkout hg git log

Then you will find the log histories.

update

If you still want to use faste-export to migrate. You can try below steps:

Inspired by migrate from mercurial to git, we can also create a changeset mapping file by hg log | grep changeset: | sort | uniq | sed 's/changeset: *//' > ../changeset.

When migrate hg to git just try /path/for/fast-export/hg-fast-export.sh -r /path/for/hg-repo -A /path/for/changeset instead (beacause windows OS seems has trouble to usehg-fast-export.sh, so sorry for that I can’t try it before update the answer).

1
votes

In the end, what the import needed was more complex than any conversion tool could support. I wrote a C# script that would export patches from the Mercurial repository, modify them as needed to match the new Git repo layout, then generate a series of git commands which, when run, would import the patches and make commits on the branch to import. This has worked well over a number of branches we've needed to import.

The LinqPad script can be found here and a Gist can be found here.