如何使用 Perforce 在 Visual Studio 中重命名文件时保留更改历史记录
我知道关于使用版本控制系统重命名文件已经存在几个问题。但对于特殊的版本控制系统Perforce我并没有找到满意的答案。
我的问题: 当我在 Visual Studio 中重命名 C# 代码文件时,是否有插件/解决方案可以保留它的版本历史记录?
编辑:目前我正在使用VS2P4插件。
编辑2: 我找到了一种更短的重命名文件的方法:
- 在资源管理器中打开包含文件夹(在解决方案资源管理器中右键单击“在 Windows 资源管理器中打开”)。
- 选择文件并右键单击 Perforce->Show in P4V。
- 对所选文件执行正常的重命名/移动操作。
在找到正确的文件之前,这种情况比在 P4V 中的 Perforce Depot 中导航要短。但当然我正在寻找一种更短的方法。
Edit3:有没有办法在VS中直接执行“在P4V中显示”选择文件?
I know there are already several questions about renaming files by using a version control system. But I did not found a satisfactory answer to the special version control system Perforce.
My question:
Is there a plug-in/solution which keeps the version history of my C# code files when I renaming it within Visual Studio?
Edit: Currently I am using VS2P4 plug-in.
Edit2:
I have found a little shorter way to rename a file:
- Open containing folder in Explorer (in Solution Explorer right-click Open in Windows Explorer).
- Select file and right-click Perforce->Show in P4V.
- Do the normal rename/move action with selected file.
That scenario is shorter than navigating in Perforce Depot in P4V until I find the right file. But of course I am looking for a shorter way.
Edit3: Is there a way to directly do "Show in P4V" with file selection within VS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Perforce 有一个新的 Visual Studio 插件,很快就会推出测试版。它确实支持内置的 Visual Studio 重命名操作,并且也可以与 Resharper 配合使用。
在它问世之前,我担心现有的解决方案有点笨拙。
There's a new Visual Studio plugin for Perforce that will be out in beta shortly. It does have support for the built-in Visual Studio rename operation, and also works well with Resharper.
Until it's out I'm afraid the existing solutions are a bit clunky.
您可以通过在 VS 中设置外部工具(工具 -> 外部工具)来强制打开您已打开的文档,从而节省该过程中的一个步骤。不理想,但更接近你想要的。
You can save yourself a step in that process by setting up an external tool in VS (Tools->External Tools) to open perforce to the document you have open. Not ideal, but closer to what you want.
宏
我现在有一个很好的解决方案。只需处理宏事件 SolutionItemsEvents_ItemRenamed。
这是通过单击“工具”->“宏”->“宏 IDE”打开宏 IDE 来完成的。然后将以下事件处理程序添加到您的宏项目中:
参见屏幕截图:
如您所见,它只是调用“p4 move -k”。需要“-k”选项,因为重命名后旧文件已被删除,因此如果没有“-k”,Perforce 将抛出错误。 “-k”使 Perforce 仅重命名服务器上的文件。
如果您遇到 Perforce 连接错误,您需要添加定义连接的 P4CONFIG 文件。这是通过以下方式完成的:
将文件p4config.txt添加到项目的目录(或其任何父目录),内容为:
P4CLIENT=您的工作空间
P4USER=用户
P4PORT=p4server:1234
设置环境变量 P4CONFIG=p4config.txt
现在您可以通过任何方式更改文件(解决方案资源管理器项 -> 重命名、解决方案资源管理器项 - >F2,ReSharper 的重命名文件以匹配类型名称,ReSharper 的类重命名 (Ctrl+R,R),...)。
但请记住:如果我尝试在一次签入中编辑和重命名同一文件,或者在另一个人签出同一文件时重命名文件,则会遇到问题。
Macro
I have a good solution now. Just handle macro event SolutionItemsEvents_ItemRenamed.
This is done by open Macros IDE by clicking Tools->Macros->Macros IDE. Then add following event handler to your macro project:
See screenshot:
As you can see it just calls a "p4 move -k". "-k" option is needed because after a rename the old file is already deleted, so Perforce would throw an error without "-k". "-k" causes Perforce to rename the file on server only.
If you get Perforce connection errors you need to add a P4CONFIG file where connection is defined. This is done by:
Add file p4config.txt to the directory of your project (or any of its parent directories) with content:
P4CLIENT=your workspace
P4USER=user
P4PORT=p4server:1234
Set environment variable P4CONFIG=p4config.txt
Now you can change your files by any way (Solution Explorer Item->Rename, Solution Explorer Item->F2, ReSharper's Rename file to match type name, ReSharper's class Rename (Ctrl+R,R),...).
But keep in mind: I have problems if I try to edit and rename same file in one chek-in and if I rename a file while another person has checked-out same file.
Visual Studio 插件 提供与 Visual Studio 的出色集成。所有重命名操作都运行良好,并且历史记录可以正常跟踪。
The Visual Studio Plugin provides excellent integration with the Visual Studio. All renaming operations work well and the history is tracked ok.