Saturday, November 13, 2010

Inter-operation of Mercurial and Git

Recently, I had to incorporate into mynetworkfolders various fixes from the open-source gss base project. Unfortunately, when the initial version of mynetworkfolders was created, we didn't clone from gss and now we have two completely independent trees, one in mercurial (gss) and one in git (mynetworkfolders). Fortunately, there is a way to link the two repos, so that changes can easily be migrated from one to the other.

First of all, we need fast-export.

git clone git://repo.or.cz/fast-export.git

then create a new git repo that we 'll use to convert the mercurial repo into.

git init gss_git_repo
cd gss_git_repo
../fast-export/hg-fast-export.sh -r ../gss
git checkout HEAD

Now, we have converted the gss mercurial repo into the gss_git_repo Git repo.

Then, we fetch changes from this repo into the mynetworkfolders git repo.

cd ../mynetworkfolders
git remote add gss ../gss_git_repo
git fetch gss [gss_branch:new_branch]

The last option is not mandatory and is needed only if we want to fetch a particular branch from the gss_git_repo.
Now in the mynetworkfolders git repo we have a new branch containing the gss changesets. If we do a merge, all changes from the beginning of the two projects will be merged so we have a lot of work to do to keep only those changes needed. However after this step and a commit, a common node will be created in the mynetworkfolders repo, so from now on if we repeat the above procedure, only the new changes from gss will be fetched into mynetoworkfolders.

1 comment:

HERBCYCLOPEDIA said...

Interesting post
Well done