一:生成patch 和打patch
有这样的 目录层次 x/xx/xxx/xxx/test.c
我的当前位置是在 x/ 下 ,执行 git diff> test.patch
在test.patch补丁文件里的路径信息是这样的:
- - - a/xx/xxx/xxx
+++b/xx/xxx/xxx
如果 应用 test.patch 的时候的 位置 是在 x/ 下,
执行:
patch -p1 < test.patch
--------------------------------------
git diff> test.patch,这是产生patch的方式。
注意,使用gitdiff产生的patch都应该在执行 patch 命令时, 指定-p1,当 位置是 【在哪里制作的patch,就在哪里 执行】
二:
$git apply 0006-Philips-VSO-library-Report-only-the-actual-data-to-a.patch
error: patch failed: sensors-see/sensors-hal/sensors/philips_rr.cpp:81
error: sensors-see/sensors-hal/sensors/philips_rr.cpp: patch does not apply
error: patch failed: sensors-see/sensors-hal/sensors/philips_spo2.cpp:81
error: sensors-see/sensors-hal/sensors/philips_spo2.cpp: patch does not apply
$ git am --reject 0006-Philips-VSO-library-Report-only-the-actual-data-to-a.patch
Applying: Philips VSO library: Report only the actual data to application i.e. data[5].
Checking patch sensors-see/sensors-hal/sensors/philips_rr.cpp...
warning: sensors-see/sensors-hal/sensors/philips_rr.cpp has type 100755, expected 100644
Checking patch sensors-see/sensors-hal/sensors/philips_spo2.cpp...
Applied patch sensors-see/sensors-hal/sensors/philips_rr.cpp cleanly.
Applied patch sensors-see/sensors-hal/sensors/philips_spo2.cpp cleanly.
git apply --reject xxxx.patch
自动合入 patch 中不冲突的代码改动,同时保留冲突的部分。这些存在冲突的改动内容会被单独存储到目标源文件的相应目录下,以后缀为 .rej 的文件进行保存。
比如对 ./test/someDeviceDriver.c 文件中的某些行合入代码改动失败,则会将这些发生冲突的行数及内容都保存在 ./test/someDeviceDriver.c.rej 文件中。我们可以在执行 git am 命令的目录下执行 find -name *.rej 命令以查看所有存在冲突的源文件位置。
$ git am --reject 0007-Adjust-the-touch-threshold-as-low-as-possible-to-mak.patch
Applying: Adjust the touch threshold as low as possible to make the off-body distance shorter
Checking patch sensors-see/registry/config/A4100/sdm429w_pah_8131_0.pah_8136.param_cal.json...
error: while searching for:
"8": {
"type": "int",
"ver": "0",
"data": "124328280"
},
"9": {
"type": "int",
"ver": "0",
"data": "40961131"
},
"10": {
"type": "int",
error: patch failed: sensors-see/registry/config/A4100/sdm429w_pah_8131_0.pah_8136.param_cal.json:48
error: while searching for:
"data": "1117"
}
}
}
error: patch failed: sensors-see/registry/config/A4100/sdm429w_pah_8131_0.pah_8136.param_cal.json:81
Applying patch sensors-see/registry/config/A4100/sdm429w_pah_8131_0.pah_8136.param_cal.json with 2 rejects...
Rejected hunk #1.
Rejected hunk #2.
Patch failed at 0001 Adjust the touch threshold as low as possible to make the off-body distance shorter
Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".