linux+文件夹补丁,linux – 编辑现有的补丁文件

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

脚本

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

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

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

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

#

# A very limited script engine that sends and receives CAN messages.

--

2.17.0

这个补丁只需用env php取代php5就可以了.

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

#!/usr/bin/php5

而现在经过一些提交它没有.

从我的理解,当前的补丁将无法工作,因为它将寻求首先找到行号和要删除的内容,但将通过错误,因为它将无法再找到文件中的上述shebang.

(已经试过了)

可能的方式

>一个明确的方法是使用更新的代码克隆存储库,并将所需的shebang(env php而不是php5)添加到代码中,并使用git format-patch -1获取要恢复的新补丁.

然而,这需要付出很多努力,当有超过一定数量的文件发生变化时,这个过程似乎很乏味.

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

解决方法:

使用quilt刷新还有另一种替代方法.简而言之,当使用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.md和README.md.rej之间.您可以解决失败的地方并致电

quilt refresh

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

注意:Yocto默认使用quilt,否则使用PATCHTOOL变量进行更改.

标签:git,linux,patch,yocto

来源: https://codeday.me/bug/20190705/1387691.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值