gpt4 book ai didi

linux - 补丁对差异文件过于严格

转载 作者:太空宇宙 更新时间:2023-11-04 09:51:28 29 4
gpt4 key购买 nike

我需要一种自动方式来向配置文件添加一行。我使用 diff 创建了一个 .diff 文件,我想用 patch 应用它。但是,我需要修补的文件可能会在其他地方稍作修改。例如。在配置文件的其他地方添加了一些其他行。

我假设 patch 实际上会对此很聪明,并弄清楚补丁是否仍然可以在没有冲突的情况下应用,但是每当我尝试将补丁应用到配置文件时我都会收到错误消息与原始文件略有不同。

我是否需要将任何其他标志传递给 patchdiff 以使其不那么严格?我正在使用

生成 .diff 文件
diff -ruN oldfile.conf newfile.conf > mypatch.diff

然后使用打上补丁

patch myconfig.conf mypatch.diff

我想要的是补丁将尝试相当自由地应用补丁,如果它不知道如何应用,则只返回警告,而不是错误。目前我看到这些错误:

jeroen@jeroen-ubuntu:~/Desktop$ diff -ruN default.conf default_new.conf > mypatch.diff
jeroen@jeroen-ubuntu:~/Desktop$ patch default2.conf mypatch.diff
patching file default2.conf
Hunk #1 FAILED at 28.
1 out of 1 hunk FAILED -- saving rejects to file default2.conf.rej
jeroen@jeroen-ubuntu:~/Desktop$

最佳答案

I assumed that patch would actually be smart about this and figure out if the patch could still be applied without conflicts, but I am getting an error whenever I try to apply the patch to a config file that is slightly different from the original file.

其实是这样的。但是,这在很大程度上取决于您对“略有不同”的定义。基本上,更改需要远离补丁修改的地方。

您可以尝试使用 -F 参数调用 patch

-F num or --fuzz=num

Set the maximum fuzz factor. This option only applies to diffs that have context, and causes patch to ignore up to that many lines of con- text in looking for places to install a hunk. Note that a larger fuzz factor increases the odds of a faulty patch. The default fuzz fac- tor is 2. A fuzz factor greater than or equal to the number of lines of context in the context diff, ordinarily 3, ignores all context.

但我不建议这样做。

只要你想

an automated way to add a line to a configuration file

您是否考虑过使用 perlawked 来完成这项工作?我认为 patch 不是适合它的工具。

关于linux - 补丁对差异文件过于严格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657102/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com