Copied file sharing same mutual history in Mercurial (TortoiseHG)

我与影子孤独终老i 提交于 2021-01-29 04:09:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20882356/copied-file-sharing-same-mutual-history-in-mercurial-tortoisehg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!