温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux系统怎么生成补丁和打补丁

发布时间:2022-01-27 10:35:00 来源:亿速云 阅读:248 作者:kk 栏目:开发技术

Linux系统怎么生成补丁和打补丁,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

生成补丁:

制作 hello.c 和 hello_new.c 两个文件如如下所示。

 ➜  diff ls
 hello.c  hello_new.c  hello_test.c  hi.patch
 ➜  diff cat hello.c
 #include "stdio.h"
 int main(int argc ,char **argv)
 {
     printf("Hello World");
 }
 ➜  diff cat hello_new.c
 #include "stdio.h"
 int main(int argc ,char **argv)
 {
     printf("Hello World\n");
     return 0;
 }

使用 diff -uN 命令 进行生成patch

 ➜  diff diff -uN hello_new.c hello.c > hi.patch
 ➜  diff cat hi.patch
 --- hello_new.c    2018-07-17 16:58:23.679704122 +0800
 +++ hello.c    2018-07-17 16:57:59.190677641 +0800
 @@ -1,6 +1,5 @@
  #include "stdio.h"
  int main(int argc ,char **argv)
  {
 -    printf("Hello World\n");
 -    return 0;
 +    printf("Hello World");
  }

至此,patch 已经创建完毕。

之后,我们进行使用 patch 命令 对 hello.c 文件进行打补丁。

 ➜  diff patch -p0可见,补丁已经成功应用,并且生成了 .orig 源文件。 –backup-if-mismatch 选项,可以不进行生成orig 文件。 ➜  diff patch -p0 --no-backup-if-mismatchdiff 和 patch 命令介绍:1、diff--------------------NAME   diff – find differences between two filesSYNOPSIS   diff [options] from-file to-file--------------------简单的说,diff的功能就是用来比较两个文件的不同,然后记录下来,也就是所谓的diff补丁。语法格式:diff 【选项】 源文件(夹) 目的文件(夹),就是要给源文件(夹)打个补丁,使之变成目的文件(夹),术语也就是“升级”。下面介绍三个最为常用选项:-r 是一个递归选项,设置了这个选项,diff会将两个不同版本源代码目录中的所有对应文件全部都进行一次比较,包括子目录文件。-N 选项确保补丁文件将正确地处理已经创建或删除文件的情况。-u 选项以统一格式创建补丁文件,这种格式比缺省格式更紧凑些。2、patch------------------NAME   patch – apply a diff file to an originalSYNOPSIS   patch [options] [originalfile [patchfile]]   but usually just   patch -pnum ------------------简单的说,patch就是利用diff制作的补丁来实现源文件(夹)和目的文件(夹)的转换。这样说就意味着你可以有源文件(夹)――>目的文件(夹),也可以目的文件(夹)――>源文件(夹)。下面介绍几个最常用选项:-pnum or –strip=num Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was/u/howard/src/blurfl/blurfl.csetting -p0 gives the entire file name unmodified, -p1 givesu/howard/src/blurfl/blurfl.cwithout the leading slash, -p4 givesblurfl/blurfl.cand not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d option.具体的使用说明,可以使用 man diff 和 man patch 命令来进行查看。至此关于Linux系统中生成补丁和打补丁的方法分享完毕,欢迎大家在评论区留言。以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!

Linux有哪些版本

Linux的版本有:Deepin、UbuntuKylin、Manjaro、LinuxMint、Ubuntu等版本。其中Deepin是国内发展最好的Linux发行版之一;UbuntuKylin是基于Ubuntu的衍生发行版;Manjaro是基于Arch的Linux发行版;LinuxMint默认的Cinnamon桌面类似Windows XP简单易用;Ubuntu则是以桌面应用为主的Linux操作系统。

关于Linux系统怎么生成补丁和打补丁问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI