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   荣锋亮  阅读(214)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示