将 PHP 更改与 diff/patch 合并

发布于 2024-10-07 11:59:47 字数 247 浏览 0 评论 0原文

我有三个 PHP 文件:

  • 1.php - OSS 软件 1.0 版(普通)
  • 1a.php - OSS 软件 1.0 版(带自定义)
  • 2.php - OSS 软件 1.1 版(普通)

我想使用 diff/ patch(或类似的)来创建单个补丁文件,该文件会将我对版本 1.0 所做的修改与版本 1.1 中所做的上游更改合并。实现这一目标的最佳方法是什么?

非常感谢。

I have three PHP files:

  • 1.php - Version 1.0 of OSS software (vanilla)
  • 1a.php - Version 1.0 of OSS software (with customisations)
  • 2.php - Version 1.1 of OSS software (vanilla)

I would like to use diff/patch (or similar) to create a single patch file that will merge the modifications I made to version 1.0 with the upstream changes made in version 1.1. What is the best way to achieve this?

Many thanks.

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

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

发布评论

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

评论(1

在梵高的星空下 2024-10-14 11:59:47

使用这个:

$ diff -u 1.php 1a.php > customizations.patch

这将为您提供文件版本 1.0 的普通副本和自定义副本之间所有更改的统一差异。

您可以尝试将这些更改应用到新文件 2.php,如下所示:

$ patch -p0 2.phpcustomizations.patch

但请注意,这可能会因大量拒绝的帅哥而失败如果源代码改变太多。尽管如此,仅仅获得统一的差异可能会被证明是有用的,因为您可以手动重新集成您的自定义以适应新的源代码。

如果可能的话,我会做的是获取自由软件项目使用的版本控制存储库的本地副本。然后,创建一个分支并集成您的自定义设置,然后看看是否可以通过将自那时以来的上游提交合并到您的分支中来推进事情。如果没有看到所涉及的所有内容,我既不能告诉您这将是一个微不足道也不复杂的过程,但它可能比仅使用 diff 和 patch 更容易。

注意这不适用于多个文件;如果您将来需要对多个文件执行此操作,则需要对两个不同目录树中的两组不同文件(具有相同文件名)使用 diff。我认为现在提及这一点也许不是一个坏主意,以防万一您将来遇到这种情况。

Use this:

$ diff -u 1.php 1a.php > customizations.patch

Which will give you a unified diff of all the changes between your vanilla and customized copy of version 1.0 of the file.

You can try to apply these changes to the new file, 2.php, like this:

$ patch -p0 2.php customizations.patch

Note, however, that this will likely fail with lots of rejected hunks if the source code has changed too much. Still, just getting that unified diff might prove to be useful since you can then manually reintegrate your customizations to fit the new source code.

What I would do, if it is possible, is to get a local copy of the version control repository that the free software project uses. Then, make a branch of it and integrate your customizations, and then see if you can bring things forward by merging the upstream commits since that time into your branch. Without seeing all of the stuff involved, I can neither tell you that it will be a trivial nor complex process, but it might be easier than just using diff and patch.

Note that this won't work for multiple files; if you need to do this in the future with multiple files, you'll want to use diff against two different sets of files (with the same filename) in two different directory trees. I thought it might not be a bad idea to mention this now just in case it proves to be a situation that you encounter in the future.

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