如何在版本控制系统中连接两个文件
我正在重构包含许多源文件的 C++ 项目。 当前的重构步骤包括将两个文件(例如,x.cpp
和 y.cpp
)合并为一个更大的文件(例如,xy.cpp
) )其中一些代码被丢弃,并且添加了更多代码。
我想告诉我的版本控制系统(在我的情况下为 Perforce),生成的文件基于两个先前的文件,因此将来当我查看 xy.cpp 的修订历史记录时,我还看到对 x.cpp
和 y.cpp
所做的所有更改。
Perforce 支持重命名文件,因此如果 y.cpp 不存在,我会确切地知道该怎么做。 Perforce 还支持合并,因此如果我有 2 个不同版本的 xy.cpp,它可以从中创建一个版本。由此,我发现连接两个不同的文件是可能的(不确定);然而,我搜索了一些关于 Perforce 和其他源代码控制系统的文档,但没有找到任何有用的东西。
我想做的事情到底有可能吗?
它是否有一个约定的名称(搜索有关“合并”或“加入”的文档未成功)?
I am doing a refactoring of my C++ project containing many source files.
The current refactoring step includes joining two files (say, x.cpp
and y.cpp
) into a bigger one (say, xy.cpp
) with some code being thrown out, and some more code added to it.
I would like to tell my version control system (Perforce, in my case) that the resulting file is based on two previous files, so in future, when i look at the revision history of xy.cpp
, i also see all the changes ever done to x.cpp
and y.cpp
.
Perforce supports renaming files, so if y.cpp
didn't exist i would know exactly what to do. Perforce also supports merging, so if i had 2 different versions of xy.cpp
it could create one version from it. From this, i figure out that joining two different files is possible (not sure about it); however, i searched through some documentation on Perforce and other source control systems and didn't find anything useful.
Is what i am trying to do possible at all?
Does it have a conventional name (searching the documentation on "merging" or "joining" was unsuccessful)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试与无基础的合并集成(命令行上的 -i )。如果我正确理解文档(并且我自己从未使用过它),这将强制两个文件的集成。然后,您需要按照您选择的方式解决集成问题,从而生成接近您设想的文件的文件。
完成此操作后,我假设 Perforce 历史记录将显示其集成历史记录中不相关文件的集成,允许您在需要时追溯到该文件。
You could try integrating with baseless merges (-i on the command line). If I understand the documentation correctly (and I've never used it myself), this will force the integration of two files. You would then need to resolve the integration however you choose, resulting in something close to the file you are envisioning.
After doing this, I assume the Perforce history would show the integration from the unrelated file in it's integration history, allowing you to track back to that file when desired.
我不认为这可以在经典的 VCS 中完成。
这些版本控制系统有两种风格(获取 git,作者:Scott Chacon 的幻灯片 50+) :
基于增量的历史记录:您获取一个文件,并记录其增量。在这种情况下,单位是文件,您不能将其历史记录与另一个文件关联。
基于 DAG 的历史记录:您获取一个内容并记录其补丁。在这种情况下,文件本身可以变化(可以随意重命名/移动),并且它可以是其他两个内容的结果(因此它接近您想要的内容)...但仍在 < 的历史记录内em>一个文件(内容来自其 DAG 的不同分支)。
I don't think it can be done in a classic VCS.
Those versioning systems come in two flavors (slide 50+ of Getting git by Scott Chacon):
delta-based history: you take one file, and record its delta. In this case, the unit being the file, you cannot associate its history with another file.
DAG-based history: you take one content and record its patches. In this case, the file itself can vary (it can be renamed/moved at will), and it can be the result of two other contents (so it is close of what you want)... but still within the history of one file (the contents coming from different branches of its DAG).
简单的部分是这样的:
然后棘手的部分变成解决 y.cpp 的移动并进行重构。但这会告诉 Perforce 文件已合并。
The easy part would be this:
Then the tricky part becomes resolving the move of y.cpp and doing your refactoring. But this will tell Perforce that the files are combined.