Beginner
Beginner

Reputation: 5457

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 ...

Upvotes: 2

Views: 65

Answers (2)

StayOnTarget
StayOnTarget

Reputation: 12998

Yes, you can probably achieve your objective using hg convert and at least its --filemap parameter.

When you are setting up a new repository you CAN modify its history, at least before it is pushed to anyone else. In addition, you can use a modified derivative of your original as the basis to merge into your new one.

The approach should be to convert your old repository into a new one where only the history of the one particular file is left. You can then pull from the converted repository into the new one (see: pull from unrelated).

(Depending on your branching scheme you may also want to use the convert procedure with --branchmap to put the history of your important file in its own branch. This could help to identify those historical changes later. If so, then once you have combined the repos you can just merge that branch into the new one.)

When using convert I would recommend different steps (filemap, branchmap, etc.) be done as distinct individual "passes". Each one will create a new temporary repository. This just makes each step simple and more understandable.

Upvotes: 2

torek
torek

Reputation: 487875

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.

Upvotes: 1

Related Questions