Skip to content

Instantly share code, notes, and snippets.

@mivade
Last active March 6, 2019 20:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivade/8696dc8f3a58284475be to your computer and use it in GitHub Desktop.
Save mivade/8696dc8f3a58284475be to your computer and use it in GitHub Desktop.
How to import history from one Mercurial repository into another

Importing a Mercurial repository's full history into another repository

Convert the soon-to-be child repository

With the Mercurial convert extention, you can rename branches, move, and filter files. As an example, say we have a repo with only the default branch which is to be imported into a super-repository.

For starters, we will want all our files in the child repo to be in a subdirectory of the parent repo and not include the child's .hgignore. To do this, create a file filemap.txt with the following contents:

rename . child
exclude .hgignore

The first line will move all files in the repo's top level into a directory named child.

Next, optionally create a branchmap.txt file for renaming the default branch to something else:

default child-repo

Now convert:

hg convert --filemap branchmap.txt --branchmap branchmap.txt child/ converted/

Pull in the converted repository

From the parent repo:

hg pull -f ../converted

Ensure the child commits are in the draft phase with:

hg phase -f --draft -r <first>:<last>

Rebase as appropriate

hg rebase -s <child rev> -d <parent rev>

To keep the child's changed branch name, use the --keepbranches option.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment