如何在版本控制系统中连接两个文件

发布于 2024-10-07 09:19:02 字数 515 浏览 4 评论 0原文

我正在重构包含许多源文件的 C++ 项目。 当前的重构步骤包括将两个文件(例如,x.cppy.cpp)合并为一个更大的文件(例如,xy.cpp) )其中一些代码被丢弃,并且添加了更多代码。

我想告诉我的版本控制系统(在我的情况下为 Perforce),生成的文件基于两个先前的文件,因此将来当我查看 xy.cpp 的修订历史记录时,我还看到对 x.cppy.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掐死时间 2024-10-14 09:19:02

您可以尝试与无基础的合并集成(命令行上的 -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.

四叶草在未来唯美盛开 2024-10-14 09:19:02

我不认为这可以在经典的 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).

alt text

瞄了个咪的 2024-10-14 09:19:02

简单的部分是这样的:

p4 edit x.cpp y.cpp
p4 move x.cpp xy.cpp
p4 move y.cpp xy.cpp

然后棘手的部分变成解决 y.cpp 的移动并进行重构。但这会告诉 Perforce 文件已合并。

The easy part would be this:

p4 edit x.cpp y.cpp
p4 move x.cpp xy.cpp
p4 move y.cpp xy.cpp

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文