Moving file between repositories?

Matt Mackall mpm at selenic.com
Tue Jul 1 21:36:43 CDT 2008


On Tue, 2008-07-01 at 19:39 -0400, Joseph Turian wrote:
> I have a file in one repository. I would like to move it to another
> repository and preserve revision history.
> How do I do that?

There aren't any tools to do it automatically, but it's not hard to do
with a script. Here are the pieces you'll need:

You can get a list of revisions the file is in with:

 hg log -R otherrepo -r 0:tip -t '{rev}\n' <file>

You can get the contents of a file revision with:

 hg cat -R otherrepo -r <rev> <file>

You can get a description of a revision with:

 hg log -R otherrepo -t '{description}' -r <rev>

And you can check in a file with a description with:

 hg ci -m <desc> <file>

Adding users and dates to this recipe left as an exercise for the
reader.

Now here's a philosophical point: Mercurial doesn't have a notion of the
history of a single file. A commit says "this -collection- of files is
the state of the project at point x". Bringing the 'history' of a single
file out of one project in the past and putting it on top of another
project in the present is anachronistic. If you had a time machine, you
could conceivably pull Caesar out of ancient Rome and drop him in modern
New York. But you can't replay Caesar's life history in a meaningful way
in New York in 2008 when Cleopatra, Mark Antony, Brutus, the Gauls, etc.
are all back in 55BC.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial mailing list