编辑一个已经存在的补丁文件

Editing an already existing patch file

使用编辑器编辑 .patch 是标准做法吗?

场景

我在 Yocto 应用程序中使用 .patch,我想在其中对我希望移植到我的嵌入式设备的存储库进行一些小的更改。

其中一个补丁如下(为了简洁删除了一些细节):

From 85987c659762939241e4bdd4223e63eb5997b181 Mon Sep 17 00:00:00 2001

OE ships php5 as php

---
 airmar/airmar.php             | 2 +-
 n2kd/n2kd_monitor             | 2 +-
 send-message/format-message   | 2 +-
 util/list-product-information | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/airmar/airmar.php b/airmar/airmar.php
index ccd4b4d..46ed49d 100755
--- a/airmar/airmar.php
+++ b/airmar/airmar.php
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
 <?php
 if (!is_array($argv))
 {
diff --git a/n2kd/n2kd_monitor b/n2kd/n2kd_monitor
index f8cfd42..4cb4766 100755
--- a/n2kd/n2kd_monitor
+++ b/n2kd/n2kd_monitor
@@ -233,7 +233,7 @@ for (;;)
         open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
         open STDOUT, '>>', $MONITOR_LOGFILE or die "Can't write to $MONITOR_LOGFILE $!";
         open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
-        exec 'php5', '/usr/local/bin/n2k.php', '-monitor';
+        exec 'php', '/usr/bin/n2k.php', '-monitor';
       }
       if (!$monitor)
       {
diff --git a/send-message/format-message b/send-message/format-message
index 590a815..2d91185 100755
--- a/send-message/format-message
+++ b/send-message/format-message
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
 <?
 #
 # Format a particular N2K command
diff --git a/util/list-product-information b/util/list-product-information
index d958ae4..a54a0f2 100755
--- a/util/list-product-information
+++ b/util/list-product-information
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
 <?php
 #
 # A very limited script engine that sends and receives CAN messages.
-- 
2.17.0

此补丁只是将 php5 替换为 env php

但是,主代码存储库更改了其中一个文件,其中以前有一个 php 的 shebang,如下所示:

   #!/usr/bin/php5

现在经过几次提交后它没有。

根据我的理解,当前的补丁将无法工作,因为它会尝试首先找到要删除的行号和内容,但会遇到错误,因为它无法在文件了。 (已经试过了)

可能的方法

然而,这需要付出很多努力,并且当更改的文件超过一定数量时,此过程似乎很乏味。

使用编辑器编辑补丁合理吗(我很确定不合理)?或者是否有一些 git 功能可以帮助直接修改补丁而不是相应的文件?

还有一种替代方法是使用 quilt refresh。简而言之,当使用 quilt 时,您会将所有补丁复制到一个名为 patches 的目录中(IMO 这可以在 quiltrc 中配置)。

这个补丁目录中名为series的文件存储了所有的补丁文件名。当您应用补丁时,

quilt push

quilt push -a

您将错误退出。假设您有 10 个补丁,并且无法直接应用第 3 个补丁,因为您已经对存储库进行了一些更改。

那你可以打电话

quilt push -f

将尝试应用所有可能的位置并将无法应用的行存储到 .rej 文件中。示例输出,

Applying patch patches/0001-To-apply.patch
patching file README.md
Hunk #2 FAILED at 51.
1 out of 2 hunks FAILED -- saving rejects to file README.md.rej

我的 README.md 文件中有帅哥。

现在您可以通过比较原始文件来检查未完全应用的更改。在上述情况下,介于 README.mdREADME.md.rej 之间。您可以解决失败的地方并致电

quilt refresh

刷新后,您在patches中的原始补丁文件将根据更改进行更新,现在您可以继续使用quilt pushquilt push -a

注意:Yocto 默认使用被子,除非使用 PATCHTOOL 变量进行更改。