Search code examples
mercurial

Is there a way to add history to a file in mercurial?


We did some general code restructuring which resulted in parts of some projects moving into different new repositories. Now there are a few files (actually most importantly one specific file) where I would like to keep the history.

Question: Is it possible to export the history of individual files and import it into another repository where that file is already available?

Perhaps it helps that only the main branch is required.

Illustration: Current situation

Old Repo                                         Repo "New

          /--> V2---\    << not required
         /           \
V0 --> V1 ---> V3 --> V4  << required            V5 --> V6 ...

Illustration: Ideal situation

New Repo

V0 --> V1 --> V3 --> V4 --> V5 --> V6 ...

Solution

  • The short answer is no.

    The longer answer is still no, but with the reason. :-) Mercurial only ever adds to the repository, both physically and logically, so you have your arrows drawn backwards (or rather, not drawn backwards but they should be backwards). Since you already have V6 leading back to V5, which leads back to "nothing comes earlier", anything you add will be V7-or-later leading back to V6.

    What you can do is build yet another new repo, in which you copy and commit V0, then copy and commit V1, and so on, until you reach V6. This gives you a new series of commits, that has the desired history. Have everyone switch over to the new new repo and you're done. Wheher this is painful (and how painful it is) mostly depends on how recently you already switched once.