對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