Linux下patch打补丁命令

1.作用

  此命令用于为特定软件包打补丁,他使用diff命令对源文件进行操作。

2.用法

  $patch [-R] {-p(n)} [--dry-run] < patch_file_name
  • p:为path的缩写。
  • n:指将patch文件中的path第n条’/’及其左边部分取消。
  • -R:卸载patch包。还原到打patch之前。
  • --dry-run:尝试patch软件,并不真正修改软件。

3.示例

  • 用文本工具打开patch文件,如sensor.patch,它的后缀可能不是.patch
 1 Index: android/vendor/qcom/proprietary/sensors/dsps/sensordaemon/common/inc/sns_reg_common.h
 2 ===================================================================
 3 --- android/vendor/qcom/proprietary/sensors/dsps/sensordaemon/common/inc/sns_reg_common.h    (revision 31573)
 4 +++ android/vendor/qcom/proprietary/sensors/dsps/sensordaemon/common/inc/sns_reg_common.h    (revision 31670)
 5 @@ -1376,6 +1376,10 @@
 6    {0x20,0x45,0x83,0xd2,0x26,0xa4,0x41,0xc4,0xa2,0x54,0x15,0xbc,0xe1,0x29,0x36,0x31}
 7  #define SNS_REG_UUID_BMA250 \
 8    {0xf3,0x7a,0x60,0xdf,0x0c,0x82,0x4a,0xc7,0xba,0xd7,0x98,0x94,0x5e,0x58,0x21,0x8a}
 9 +#define SNS_REG_UUID_BMM050 \
10 +  {0xa0,0xd3,0x35,0xb2,0x16,0xa9,0x44,0xbf,0x94,0x51,0xaa,0xb1,0xd7,0x3f,0x1f,0x88}
11  #define SNS_REG_UUID_LIS3DH \
12    {0x14,0xb6,0xfa,0xeb,0xe0,0x28,0x4b,0x3a,0xbf,0xff,0x7d,0x04,0xf5,0x75,0xac,0x14}
13  #define SNS_REG_UUID_LIS3DSH \
14 @@ -1418,8 +1422,6 @@
15    {0x1c,0xc8,0xd8,0x96,0x0f,0x75,0x40,0x5b,0xa0,0x00,0x31,0x1e,0x0d,0x27,0x3e,0xe9}
16  #define SNS_REG_UUID_BMG160 \
17    {0x45,0x03,0xe9,0x5b,0x57,0xc5,0x47,0xc3,0x8d,0x49,0x90,0xe9,0xbe,0xf9,0xb3,0xc0}
18 -#define SNS_REG_UUID_BMM050 \
19 -  {0xbc,0xfd,0xbf,0x4d,0xa5,0x5d,0x42,0x8c,0xa6,0x0a,0x97,0xbf,0x6b,0xc0,0x1b,0x29}
20  #define SNS_REG_UUID_GYRO_EWTZNA \
21    {0x33,0xb9,0x0e,0x55,0xd1,0xb3,0x43,0x71,0x93,0xc1,0xc9,0x5b,0x6a,0x26,0xc8,0x1d}
22  #define SNS_REG_UUID_BMA2X2 \
23 Index: android/vendor/qcom/proprietary/sensors/dsps/reg_defaults/sensor_def_qcomdev.conf
24 ===================================================================
25 --- android/vendor/qcom/proprietary/sensors/dsps/reg_defaults/sensor_def_qcomdev.conf    (revision 31573)
26 +++ android/vendor/qcom/proprietary/sensors/dsps/reg_defaults/sensor_def_qcomdev.conf    (revision 31670)
27 ......
  • 把sensor.patch放在与android同级目录下

    

  • 运行patch命令打补丁,-R参数可以还原。
    $patch -p0 < sensor.path
  • $patch -p0 -R < sensor.path
  • 如有冲突,解决它。

 

posted @ 2017-02-06 16:22  f9q  阅读(803)  评论(0编辑  收藏  举报