Tutorial :convert old repository to mercurial



Question:

I've been playing around with different versioning systems to find one I'm comfortable with. I started with SVN (lets call this version of the project "f1"), then changed over to GIT. But I didn't know how to convert the old SVN repo to GIT, so I just copied the folder, deleted the .svn stuff, and turned it into a GIT repo (lets call this copied version "f2").

Now I'm playing around with Mercurial and was very pleased to find that it has a Tortoise client for Windows. I was also please to find how easy it was to convert the GIT repo into Mercurial, so I preserved the history (I still cloned it first, just in case. So I'm calling this hg version "f3").

But now what I'm wondering is: what do I do with the old SVN repo that still holds my history from before I played with GIT?

I guess I can convert the old SVN repo to Mercurial, but can I then merge those two histories into the one repository so I have a complete set of histories in one place? In other words, can I prepend f1 to f3?


Solution:1

You can't prepend f1 to f3 in the literal history/ancestor sense without fundamentally altering f3, because every revision in mercurial is identified by a hashcode, and that hashcode is constructed from (among other things) the content of the revision and the hashes of its parents. So changing the parent of f3's first node would change all of f3's hashcodes.

So you can prepend f1 to f3 if you're willing to regenerate f3 in the process yielding, say f4. Doing so would invalidate all the clones of f3 out there -- but if you're a one person team that might be okay with you.

If you're not okay with altering every hash in f3 (and I wouldn't be) another (not so great) option is to use hg convert to create a new mercurial repo from f1, let's call it f5, and then to hg pull -f f5 into f3. Since no changeset in f5 would be an ancestor or child of any changeset in f3 -- no common lineage -- you'd end up with two heads and two streams of changesets. Some folks do that, but honestly I don't see any real benefit in doing it.

Where I you, I'd just convert f1 into f5 (a mercurial repo with all your old history) and then keep it around for reference.


Solution:2

Have you tried the Transplant extension? It allows you to pull changes, even if the repository is unrelated.

So what you could do is take f1, do a convert it to your new repo, called HGSVN. This repo will hold you whole svn-created history. If you've done no more modifications in f1, you know that f3 holds all modifications after the copy (f2). Now you can use transplant, to get all the later changes into HGSVN. Yes, the sha1-sums would have been changed, but since HGSVN now contains your entire development history, you can forget about the other repositories.

BTW. I recommend you do a backup clone before doing the actual transplant. This way you can just do it again, if you get the commands wrong. Hope this help.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »