溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Linux系統(tǒng)怎么生成補丁和打補丁

發(fā)布時間:2022-01-27 10:35:00 來源:億速云 閱讀:267 作者:kk 欄目:開發(fā)技術

Linux系統(tǒng)怎么生成補丁和打補丁,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

生成補?。?/h3>

制作 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 已經創(chuàng)建完畢。

之后,我們進行使用 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 選項確保補丁文件將正確地處理已經創(chuàng)建或刪除文件的情況。-u 選項以統(tǒng)一格式創(chuàng)建補丁文件,這種格式比缺省格式更緊湊些。2、patch------------------NAME   patch – apply a diff file to an originalSYNOPSIS   patch [options] [originalfile [patchfile]]   but usually just   patch -pnum ------------------簡單的說,patch就是利用diff制作的補丁來實現(xiàn)源文件(夾)和目的文件(夾)的轉換。這樣說就意味著你可以有源文件(夾)――>目的文件(夾),也可以目的文件(夾)――>源文件(夾)。下面介紹幾個最常用選項:-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系統(tǒng)中生成補丁和打補丁的方法分享完畢,歡迎大家在評論區(qū)留言。以上就是良許教程網為各位朋友分享的Linux系統(tǒng)相關內容。想要了解更多Linux相關知識記得關注公眾號“良許Linux”,或掃描下方二維碼進行關注,更多干貨等著你!

Linux有哪些版本

Linux的版本有:Deepin、UbuntuKylin、Manjaro、LinuxMint、Ubuntu等版本。其中Deepin是國內發(fā)展最好的Linux發(fā)行版之一;UbuntuKylin是基于Ubuntu的衍生發(fā)行版;Manjaro是基于Arch的Linux發(fā)行版;LinuxMint默認的Cinnamon桌面類似Windows XP簡單易用;Ubuntu則是以桌面應用為主的Linux操作系統(tǒng)。

關于Linux系統(tǒng)怎么生成補丁和打補丁問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業(yè)資訊頻道了解更多相關知識。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI