linux diff patch的應用

來源:互聯網
上載者:User

 對diff,patch的用法總是一知半解

在這裡做個標記

diff [options] oldfile newfile
[options]
-r:遞迴選項,包含子目錄檔案
-u:以統一格式建立補丁檔案,標準格式
-N:正確處理新建立或已刪除檔案的情況

cd ../old_dir
diff -urN old_dir new_dir >patchfile
例如:
$ cd ~/work
$ ls
  olduboot test temp
$ ls test

   newuboot
$ diff -urN olduboot test/newuboot >ubootpatch
註:diff時,應該是在olduboot的同級目錄下進行。

patch [options] [originalfile] [patchfile]
[options]
-p0:從目前的目錄尋找目標檔案(夾)
-p1:忽略第一次目錄,從目前的目錄開始尋找
-E:若發現空檔案,則刪除
-R:在補丁檔案中的“新”檔案和“舊”檔案調換過來。

例如:ubootpatch格式如下:
$ pwd
  ~/work #目前的目錄
$ head -3 ubootpatch
diff -urN olduboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c test/newuboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c
--- olduboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c      2011-09-27 14:55:50.000000000 +0800
+++ test/newuboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c 2011-09-27 14:25:25.000000000 +0800

-p0:表示從目前的目錄~/work下尋找一個叫做olduboot的檔案夾
-p1:表示忽略掉第一層目錄(olduboot),從目前的目錄~/work下尋找arch檔案夾,繼而遍曆尋找到check_reboot.c檔案
在這裡如果要用參數p1,則需要先進入olduboot檔案夾中,再運行:patch -p1 < ubootpatch

##然後在需要應用patch的地方使用下述命令即可:
$ patch -p0 < ubootpatch
or
$ cd olduboot
$ patch -p1 < ../ubootpatch

如果你需要打補丁的檔案夾olduboot在其他目錄,如:~/temp/olduboot
則需要如下操作:
$ cd ~/work/ubootpatch ~/temp/
$ cd ~/temp
$ ls
  olduboot
$ patch -p0 <ubootpatch
or
$ cd olduboot
$ patch -p1 <../ubootpatch

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.