1

Rightly or wrongly (almost certainly wrongly) I've ended up in the following position:

We used to have one big mercurial repository. We have now moved a large portion of this code base in to a separate repository. Looking back, it seems we could have done this in such a way that kept the file history, but naively we simply copied the files in to the new repository.

We are now in a position where the two repositories have been split, but I want to attach the file history of the moved files to those in the new repository. The files have been deleted in the original repository - but this history obviously still exists.

Is there anyway to "pre-pend" the history of the files in the original repository to those in the split repository?

2 Answers 2

1

The convert extension allows you to convert a Mercurial repository to another one while excluding and modifying filenames (using the --filemap option).

So use the convert command twice, one for each split, and use a corresponding filemap which only involves the files supposed to be in the particular target repository.

If you already did commits in the split repos you do not want to loose, use the convert approach anyway and afterwards migrate your new commits made in the splits w/o history to your new split repos made with convert:

Suppose your old splits with lost history are os1 and os2 and your new splits made with the convert command are ns1 and ns2. Then in ns1 you would do

  1. hg pull --force os1 (force is required because you pull from an unrelated repo),
  2. hg rebase -s <first-new-commit-made-in-os1> -d <last-converted-commit-in-ns1> (rebase new commits onto your split made with convert)
  3. hg strip <first-commit-at-all-in-os1> (discard everything you pulled from os1 but not needed anymore)

Do it similarly with os2 and ns2

1

I don't know about attaching the file history after you've already done the split, but if you can do it all over again this is one option:

In your original repository, go back to the last revision (REV) before you deleted the files:

hg up -r REV

Go up one level from the original repository and make two new clones:

hg clone OriginalRepo Split1
hg clone OriginalRepo Split2

Go into Split1, delete the files you don't want in that repository, and commit. Do the same for Split2. These two are now your new split repositories, both with a complete history. Of course, the history for all deleted files (even those you initially didn't want in the repository) will exist equally in both repositories as well.

If you've done a lot of work in your new repositories after you made the split, you might be able to add these to your Split1 and Split2 by using export/import (check hg help import and hg help export). Depending on the number of changes you've made, there might be better ways to do this (e.g. mercurial queues), but this is what came to my mind first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.