Is there any way to use hg copy from a specific revision?
I want to copy an earlier version of a file and work on it while preserving the history of the copied file at the point it was copied.
In other words if I have some program foo.py at rev 23 but I want to fork it into bar.py from rev 6 of foo.py, is there a way to specify:
hg copy foo.py@6 bar.py
I can't think of a single command that would do this because you have to add a commit as a child of the older revision. But it can certainly be done in a series of commands.
Example:
This will create file
bar.pywhich would be the contents offoo.pyat revision 6.(For private/unpublished changes you could also use
rebaseand/orhisteditbut that seems out of scope for this question).bar.pymay receive merges intended forfoo.pywhich can be undesirable, especially if a lot of changes have occurred since rev 6. You may just have to discard conflicts.If it is acceptable to have the copied file's lifetime start from the current revision its simpler:
Example:
In many cases this would be OK - for instance if there were no content changes to foo.py in all that time, but maybe only its location or filename changed.
FYI the reason
hg copyby itself can't be used for this is its basic definition:(according to
hg cp --help) so that is not what you should use; its just not designed for what you had in mind.