無中生有diff/patch

Wisdomsoar
1 min readFeb 4, 2021

diff — ruN original_src modified_src > 0026-patch-name.patch
r: recursively compare any subdirectories found
u: output NUM (default 3) lines of unified context
-U NUM
N: treat absent files as empty

打patch:
testuser@localhost ~/p7zip_9.20.1 $ patch -p1 -i ../CVE-2015–1038.patch

-p1 的參數,代表要跳過一層目錄結構,
(因為patch檔內,通常有a, b 資料夾,我們用-p1去跳過這層資料夾)
-i patchfile or — input=patchfile

andy@t5r120a:/mnt/code/sa8155p/newES6/8155_LA_ES6_r00007.4_hlos_rm_repo/LINUX/android/vendor/qcom/proprietary/camx/ais$
patch -p1 < 0002-Fix-sa8155-camera-loopback-test_ais.patch

-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.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and 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.

ref: https://jyhshin.pixnet.net/blog/post/42727873-diff-and-patch-%E7%94%A8%E6%B3%95
— dry-run: 不會真的上補丁,而只是給你看會修改哪些檔案測試是否會成功。

--

--