在IT技术中,编辑.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
进行替换。然而,主代码存储库更改了其中一个文件,之前该文件中的shebang如下所示:
#!/usr/bin/php5
现在经过几次提交后,它不再起作用。
据我所知,当前的补丁不会起作用,因为它会首先寻找要删除的行号和内容,但由于文件中再也找不到上述提到的shebang了,所以会引发错误。(已经尝试过)
可能的方式
- 一种清晰的方法是使用更新代码克隆存储库,并向代码添加所需的shebang(
env php
而不是php5
),并使用git format-patch -1
获得新补丁以进行恢复操作。
然而,这需要很多努力,当更改的文件超过一定数量时,这个过程似乎变得很繁琐。
是否可以使用编辑器编辑补丁(我十分确定不可以)? 或者有没有一些git
功能可以直接修改补丁而不是相应的文件?