linux patch 简单学习

使用patch 我们可以方便的进行软件补丁包处理,以下演示一个简单的c 项目补丁处理

原代码

app.c

#include <stdio.h>
int main(){
 printf("this is a demo app");
 return 0;
}

补丁修改代码

命名旧的app.c 为app.c.origin

cp app.c  app.c.origin

#include <stdio.h>
int main(){
 printf("dalong demo app");
 return 0;
}

diff 查看变动

diff -Nur app.c.origin app.c

效果

--- app.c.origin    2019-05-22 16:57:58.027468908 +0800
+++ app.c   2019-05-22 15:55:00.007459150 +0800
@@ -1,5 +1,5 @@
 #include <stdio.h>
 int main(){
- printf("this is a demo app");
+ printf("dalong demo app");
  return 0;
 }

生成patch

 diff -Nur app.c.origin app.c > app-output-patch.patch

效果

--- app.c.origin    2019-05-22 16:57:58.027468908 +0800
+++ app.c   2019-05-22 15:55:00.007459150 +0800
@@ -1,5 +1,5 @@
 #include <stdio.h>
 int main(){
- printf("this is a demo app");
+ printf("dalong demo app");
  return 0;
 }

代码打补丁

  • 重命名app.c.origin 为app.c 删除新的app.c 通过补丁文件添加
  • 应用patch
patch < app-output-patch.patch 

效果

cat app.c 
#include <stdio.h>
int main(){
 printf("dalong demo app");
 return 0;
}

说明

以上只是一个简单的patch 测试,linux 软件包的开发好多都是基于patch bug修复,git 也有类似的功能

参考资料

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/rpm_packaging_guide/preparing-software-for-packaging#patching-software

posted on 2019-05-22 17:11  荣锋亮  阅读(208)  评论(0编辑  收藏  举报

导航