41

This sounds kind of complex, so let me explain:

Project_A has lived for some time within its own Mercurial repository. Project_A is now getting folded into a new super project, Super-Project_B. Super-Project_B also has a mercurial repository. We would prefer if Project_A were not a subrepo, but instead just a normal child, but we also don't want to lose the history. Is there a way to do this?

moswald
  • 11,491
  • 7
  • 52
  • 78

1 Answers1

50

Yeah. Use the convert extension to move projectA down one directory level:

hg convert --filemap filemap.txt projectA projectA-redone

where your filemap.txt has this line in it:

rename . projectA

(that dot might be a slash but I don't think so).

That will give you a new repo, projectA-redone, that has all the history of A though all the changesets will have different hashes since their content (paths) have changed to get "projectA" in front of all of them.

Then you go into Super-Project_B and do a hg pull -f /path/to/projectA-redone. You need the -f because otherwise you'll be told that the repos are unrelated since they have no changesets in common.

Finally you'll do a hg merge in Super_project_b which should have no conflicts (unless you already had a projectA directory, in which case you should've picked a different name or hg removed it first).

After doing that B will have all of A inside the projectA subdirectory and all history will be intact.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • was it a dot or a slash that worked. I thought it was a slash but the help says to use a dot if you're going the other way (rename projectA . to move it to top level) so I guessed that. – Ry4an Brase Jul 09 '10 at 21:54
  • @Ry4an It was dot. Still works perfectly. I first had to enable the convert extension in my mercurial.ini as well – jan Jul 27 '12 at 09:30
  • @Ry4an: Works! But how to do if i want projectA to be imported under a particular branch "xyz" of Super-Project_B? The above solution imports it to default branch. – Scrontch Dec 19 '13 at 16:46
  • 1
    Found it! Add `--branchmap branchmap.txt` to conversion, with branchmap.txt containing `default xyz` – Scrontch Dec 19 '13 at 17:11
  • 1
    For TortoiseHG users the **convert** extension is enabled in File->Settings in TortoiseHG Workbench – Glenn Lawrence Jul 06 '15 at 13:04
  • 1
    For windows users, the convert extension must be added to mercurial.ini under the current user's directory - c:\Users\currentUserName\mercurial.ini – Jenn Aug 28 '15 at 15:31