51

I'm wondering if I can copy one file and its history from one repository to another, without having to import the whole other repository.

1
  • 2
    As an alternative, you could commit a copy of the file, with a pointer to the repository and the revision id. Commented Sep 4, 2010 at 21:42

2 Answers 2

59

You can use the ConvertExtension to export just that one file from the first repository into a new temporary repository, then use hg pull -f to import the new repository into the target repository.

Create a filemap for the ConvertExtension with the single line:

include path/to/file 

Then use:

hg convert path/to/original path/to/temporary --filemap filemap 

to create the temporary repository. Next, in the target repository, do:

hg pull -f path/to/temporary 

to pull in that file with its history. This will create a new head, so use hg merge to merge it with the head in your target repository.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't get it: I've made a lot of tries, and almost every time Iget a repository with just two commits (but with the correct files). It worked just ONCE and I don't have the slightest idea on what I did different :|
ffs I got it: it doesn't handle file renames! You have to explicitly "include" all the previous names of the files too (and I don't know if he will remember they were renames instead of new files)
Hi! I follow this method but I can't push the result, it says " push create new remote head on branch [an old branch that is closed]" What can I do?
12

Just to add to Niall C.'s answer, you can rename the files you are importing to place them at the correct place too.

You must first rename the file, then include it. Your filemap would look like that:

rename "original/path" "wished/path" include "original/path" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.