记录一下git 打patch导入patch遇到的问题

  • Post author:
  • Post category:其他


背景:

工作中经常要从公版上合并patch 到项目上,需要保留每个patch 提交的信息

1. git format-patch -N   b91de2b9c9a0d3bcc //从b91de2b9c9a0d3bcc 这个提交开始,往回N个提交,一次性生成N个patch。从b91de2b9c9a0d3bcc 开始生成序号是倒序的patch。如下图所示

git log看当前提交

$ git log
commit ce3992eb91de2b9c9a0d3bccee9f1f7b9b68d378 (HEAD)
Author: san.zhang <san.zhang@xxxx.com>
Date:   Wed Jul 29 10:48:28 2020 +0800

    vdec: fix h265 interlace jitter problem [1/1]
    
    PD#SWPL-12345
      
    Change-Id: I0ff2d1bacb3963dad19785345a4ef21ff00794d7
    Signed-off-by: san.zhang <san.zhang@xxxx.com>

commit e06f4ce0ddac39194347aefc07b5081795c3c0a2
Author: si.li <si.li@xxxx.com>
Date:   Tue Aug 4 16:59:02 2020 +0800

    decode: notify backend secure flag. [1/1]
    
    PD#SWPL-23456
    
    Problem:
    decode provided the secure flag to backend.

    Change-Id: I2804f606145445b295ae225ba85dc4cff698cac2
    Signed-off-by: si.li <si.li@xxxx.com>

commit d4699f74ff7cce0c27827b463b6bdb8069bbae99
Author: wu.wang <wu.wang@xxxx.com>
Date:   Thu Jul 23 17:17:49 2020 +0800

    v4l: fixed the issue of vp9 can't playback on linux. [1/1]
    
    PD#SWPL-34567
    
    Change-Id: Ie3cf4858c2c4160b9ca551e39faca5a5c127fe19
    Signed-off-by: wu wang <wu.wang@xxxx.com>

生成patch,从下面生成patch的名称0001-xxxx,0002-xxxx,0003-xxxx 看到,跟上面git log的顺序倒过来。合patch时按名称照序号从小到大即可

$git format-patch -3 ce3992eb91de2b9c9a0d3bccee9f1f7b9b68d378
0001-v4l-fixed-the-issue-of-vp9-can-t-playback-on-linux.-.patch
0002-decode-notify-backend-secure-flag.-1-1.patch
0003-vdec-fix-h265-interlace-jitter-problem-1-1.patch


2. git am (–continue | –skip | –abort) PATCH_NAME  //打补丁

大多数时候都不会有那么顺利的,会出现诸如

error: xxxx.c: patch does not apply

报错。现象如下

$ git am 0001-vdec-fix-h265-interlace-jitter-problem-1-1.patch
Applying: vdec: fix h265 interlace jitter problem [1/1]
error: patch failed: drivers/frame_provider/decoder/h265/vh265.c:196
error: drivers/frame_provider/decoder/h265/vh265.c: patch does not apply
Patch failed at 0001 vdec: fix h265 interlace jitter problem [1/1]
hint: Use 'git am --show-current-patch=diff' 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".

3.

error: xxxx.c: patch does not apply

这种错误,网上多数文章都写的不太完整。经过汇总、实践、整理如下:

$

git status 查看状态,

下面的log.说明am过程暂时停止了,但是还处在am的对话中.

$ git status
On branch p-x32a0-20190930

You are in the middle of an am session.
  (fix conflicts and then run "git am --continue")
  (use "git am --skip" to skip this patch)
  (use "git am --abort" to restore the original branch)

nothing to commit, working tree clean


4. git apply –reject  PATCH_NAME

//强制应用补丁,

$ git apply --reject 0001-vdec-fix-h265-interlace-jitter-problem-1-1.patch
Checking patch drivers/frame_provider/decoder/h265/vh265.c...
error: while searching for:
        bit 0, stream base resend data when decoding buf empty
*/
static u32 data_resend_policy = 1;

static u32 dirty_time_threshold = 2000;
static u32 dirty_count_threshold = 200;

error: patch failed: drivers/frame_provider/decoder/h265/vh265.c:196
Hunk #2 succeeded at 432 (offset -21 lines).
error: while searching for:
        u64 again_timeout_jiffies;
        u32 pre_parser_video_rp;
        u32 pre_parser_video_wp;
};


error: patch failed: drivers/frame_provider/decoder/h265/vh265.c:1791
Hunk #4 succeeded at 11428 (offset -980 lines).
Hunk #5 succeeded at 11504 (offset -967 lines).
Hunk #6 succeeded at 12970 (offset -1169 lines).
Applying patch drivers/frame_provider/decoder/h265/vh265.c with 2 rejects... 
Rejected hunk #1.              提示有两个错误合不上,需要手动修改
Hunk #2 applied cleanly.
Rejected hunk #3.
Hunk #4 applied cleanly.
Hunk #5 applied cleanly.
Hunk #6 applied cleanly.

5. 参考drivers/frame_provider/decoder/h265

/vh265.c.rej

提示的错误,vi drivers/frame_provider/decoder/h265

/vh265.c

打开手动修改错误,修改完毕保存退出

6. $ git add drivers/frame_provider/decoder/h265

/vh265.c

//添加到缓冲区

7. $ rm drivers/frame_provider/decoder/h265/vh265.c.rej    //删除rej 文件

8. $ git am –resolved  提示如下信息表示合并patch成功

$ git am --resolved
Applying: vdec: fix h265 interlace jitter problem [1/1]

这时候git log 就有这个提交信息了

$ git log
commit 44ae4c789540c575efa22cf0b5b5e4a2773f4299 (HEAD -> p-x32a0-20190930)
Author: san.zhang <san.zhang@xxxx.com>
Date:   Wed Jul 29 10:48:28 2020 +0800

    vdec: fix h265 interlace jitter problem [1/1]
    
    PD#SWPL-12345
    
    Change-Id: I0ff2d1bacb3963dad19785345a4ef21ff00794d7
    Signed-off-by: san.zhang <san.zhang@xxxx.com>



版权声明:本文为storm_peng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。