Linux 无法使用嵌套目录应用修补程序
我试图创建简单的补丁,但文件在不同的目录 我的目录结构是:Linux 无法使用嵌套目录应用修补程序,linux,patch,Linux,Patch,我试图创建简单的补丁,但文件在不同的目录 我的目录结构是: /-|hello_new.c |-1/-| |-2/-| |-3/hello.c //hello_new.c: #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello World\n"); } //hello.c: #include <stdio.h> int main
/-|hello_new.c
|-1/-|
|-2/-|
|-3/hello.c
//hello_new.c:
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello World\n");
}
//hello.c:
#include <stdio.h>
int main()
{
printf("Hello World\n");
}
我的补丁文件是hello.patch:
--- 1/2/3/hello.c 2016-02-09 13:31:04.904763020 +0530
+++ hello_new.c 2016-02-08 18:35:47.299940190 +0530
@@ -1,6 +1,5 @@
#include <stdio.h>
-int main()
-{
+int main(int argc, char *argv[]) {
printf("Hello World\n");
}
-1/2/3/hello.c 2016-02-09 13:31:04.904763020+0530
+++你好,纽约时间2016-02-08 18:35:47.299940190+0530
@@ -1,6 +1,5 @@
#包括
-int main()
-{
+int main(int argc,char*argv[]){
printf(“Hello World\n”);
}
现在,我使用以下方法应用修补程序:
diff -u 1/2/3/hello.c hello_new.c > hello.patch
patch < hello.patch
patch
但是我得到了补丁文件hello\u new.c
检测到反向修补程序。您可以使用
修补程序解决此问题:
-p
编号
--strip=
编号
将文件名strip count设置为number。请参阅
如果修补程序文件中的“前/后”级别不同,请记住,patch
优先于“前”部分(标题的第一行)中的级别数。因此,您可以这样做
patch -p3 < hello.patch
测试补片时,例如,如果补片不完全匹配(例如制表符/空格转换、回车线结束),我预览修补程序,可以添加一个-l
选项来帮助修补程序
减少拒绝次数。我这样做了,然后它让我的文件应用修补程序。我必须再次指定1/2/3/hello.c作为输入。然后它应用此修补程序。是否可以在修补程序不要求进一步输入的情况下完成此操作…因为我想在生成系统中添加此命令。@littleboy很可能您还需要--directory
选项。可能不需要:我应用了补丁,但不需要该选项。
$ patch -p3 --dry-run < hello.patch
patching file hello.c
Hunk #1 succeeded at 2 with fuzz 2 (offset 1 line).