Pergunta

In Mercurial (preferably via TortoiseHG interface) is it possible to copy a committed file, and for the new destination file to share the history for the source file?

I'm pretty sure this is not possible, but I'm asking in the hope that it's just really well hidden in the documentation.

I have a file with a fairly long history of changes, but I now need to have have a 2nd copy of this file within the project which will contain it's own individual changes. However, it would be exceedingly useful to be able to view the history of this copied file and see all the changes that took place on the original before the copy took place (as well as those that have taken place since the copy).


Update

Thanks to @Inspired for their answer. As I said in my comment to them, I was at fault...

I just realised why it wasn't working: I didn't copy the file through either the command line or THG, but through Visual Studio (2010) using VisualHG. VHG must copy the file and then add it, rather than using the mercurial copy function. So I need to remember to use mercurial directly in the future!

Or to be more precise, my guess is that VisualHG cannot override the default functionality of Visual Studio, and therefore can only work with the copied file, rather than run the mercurial copy command. This is purely my guess.

Foi útil?

Solução

From command line, you can issue hg copy <old name> <new name>. Mercurial does save the history log when you perform copy or rename (hg cp / hg mv).

In TortoiseHG the copy is a bit tricky: you have to copy the file manually (e.g. via cp), then in THG in Commit mode right-click at the left low pane with the unversioned new file and select Detect renames. Uncheck Only consider deleted files, let TortoiseHG find similar files and click the source file when it finishes. TortoiseHG will record the new file as a copy. I haven't found a simpler way.

When viewing history from command line, you need to specify -f (or --follow) when you are viewing the history: hg log -f <filename>. TortoiseHG already does that.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top