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.
Asked
Active
Viewed 1.0k times
50
-
2As an alternative, you could commit a copy of the file, with a pointer to the repository and the revision id. – jilles Sep 04 '10 at 21:42
2 Answers
58
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.
-
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 :| – o0'. Sep 09 '10 at 14:21
-
10ffs 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) – o0'. Sep 09 '10 at 14:31
-
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? – iteal Mar 16 '21 at 16:09
11
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"

Jiehong
- 786
- 1
- 7
- 16