Mercurial: copying ONE file and its history to another repository

Mercurial

Mercurial Problem Overview


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.

Mercurial Solutions


Solution 1 - Mercurial

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.

Solution 2 - Mercurial

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"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiono0'.View Question on Stackoverflow
Solution 1 - MercurialNiall C.View Answer on Stackoverflow
Solution 2 - MercurialJiehongView Answer on Stackoverflow