将 PHP 更改与 diff/patch 合并
我有三个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用这个:
$ 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.