如何在 PHP 或 JavaScript 中合并文件的两个版本?

发布于 2024-09-27 15:22:21 字数 438 浏览 0 评论 0原文

我正在尝试编写一个允许多人同时处理一个文件的网站。在此过程中,我遇到的最大障碍是合并文件的新版本,版本控制风格。

我一直无法找到任何内置 JavaScript 或 PHP 函数可以帮助我解决这个问题。我发现的最接近的是 array_diff,它确实不是我需要的,因为它只是返回另一个数组中不存在的元素,并且如果我有一个单词数组,那么肯定会有重复;此外,array_diff 忽略某些内容出现的次数或其在文件中的位置。

我稍微研究了一下 Levenshtein 的距离算法,它确实作为 php 的内置函数,但我不确定它是否是我所需要的。如果是这样,请告诉我,我会进一步调查。

您知道有什么可以满足我的需求吗?

编辑:

让我澄清一下。我实际上并不是在设计版本控制系统。我只想合并文件,而不是存储旧版本等。安装 CVS 或 SVN 或类似的东西仍然是我最好的选择,只是为了使用一个功能吗?

I'm trying to code a site that will allow multiple people to be working on a file at the same time. In doing so, the biggest road-block I have come across is merging the new versions of the files, version-control style.

I have been unable to find anything in the vein of a built-in JavaScript or PHP function that will help me with this. The closest I have found is array_diff, which really isn't what I need, since that simply returns what elements are not present in the other array, and if I have an array of words, there are bound to be repeats; additionally, array_diff ignores the number of times something shows up or its position in the file.

I have looked a little into Levenshtein's distance algorithm, which does come built-in as a function with php, but I'm not sure if it's what I need. If so, please tell me, and I will look into that further.

Is there anything that you know of that will suit my needs?

EDIT:

Let me clarify a little. I am not actually designing a version control system. I only want to merge the files, not store old versions, etc. Is installing a CVS or SVN or something along those lines still my best bet just to get use of the one function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

執念 2024-10-04 15:22:21

核心算法是LCS

它用于在 WinMerge 等程序中生成并排视图。

我实际上制作了一个基于网络的版本,但我被困在同步两个窗口的滚动上,他们采用了一个更笨拙的解决方案。

The core algorithm is LCS.

Which is used to generate the side by side view in programs like WinMerge.

I actually made a web based version but I got stuck on synchronizing the scrolling of the two windows and they went with a clunkier solution.

不一样的天空 2024-10-04 15:22:21

为什么要重新发明轮子?我将 exec 与“diff”一起使用来查找两个文件之间的差异并从那里开始工作。

尽管如此,这也无法解决 cvs 无法解决的问题:如果发生冲突(因为两个或更多人更改了同一行代码),您将必须手动修复这些冲突(或者让编辑器来解决) )。

但话又说回来:为什么不立即使用 CVS 并与其一起使用 Web 查看器?
例如 http://www.viewvc.org

Why reeinvent the wheel? I'd use exec together with "diff" to find the differences between two files and start working from there.

Still, that won't solve problems that cvs cannot solve, too: if conflicts occur (because two or more persons have been changing the same line of code), you'll have to fix those conflicts manually (or let the editors do it).

But then again: why not use CVS right away and use a web-viewer together with it?
e.g. http://www.viewvc.org

染年凉城似染瑾 2024-10-04 15:22:21

Mercurial、subversion、cvs...确实不要重新发明轮子。

mercurial, subversion, cvs, ... Don't reinvent the wheel indeed.

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