When I converted our SVN repository to Mercurial (Kiln), I left out some of our branches. Last night I wanted to get them ported back over to our Mercurial repository, and here’s how I did it:
- Browsed the old SVN repository using Tortoise SVN.
- Went to “View Log” for the branch I wanted to port over.
- In the log, I selected the first revision of the branch (where it was branched from trunk), and the last revision of the branch.
- Right-clicked, and clicked “View difference as unified diff”
- Copied the text that appeared and pasted it in a file called: branchPatch.txt
- Noted the date that I had originally made the branch in SVN. Let’s call it SVN Change # 500, on June 8, 2010
- In Mercurial, viewed history to find the corresponding changeset in Mercurial for SVN Change #500 on June 8th. Let’s call it revision #100
- Updated to that revision:
[code lang="as3"]hg up 100
- Made a branch:
[code lang="as3"]hg branch OldBranches/MyBranchName
hg commit -m "Creating a branch"[/code]
- Imported the patch:
[code lang="as3"]hg import -p 0 --no-commit ../branchPatch.txt
-p 0 tells it to use a “strip count” of 0. Otherwise, when applying the patch from SVN, it will try to strip the first part of the path off when finding files it needs to modify. You’ll get error messages that it couldn’t apply the patch.
–no-commit makes the changes to your working folder instead of submitting each of the changes separately. Without this, my first attempt gave me 12 separate revisions in Mercurial, one for each file I modified.
- Commit the changes:
[code lang="as3"]hg commit -m "Now Oldbranches/MyBranchName has been moved over from SVN"
Warning: This does not preserve full history of the branch. Your corresponding branch in mercurial will contain the final state of the branch in SVN, but it will not contain the intermediate revisions to get you there. I didn’t care in my case because my branches were small and only had a few revisions leading up to their final state.