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

 

背景:

工作中经常要从公版上合并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>

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 要使用gitpatch,你可以按照以下步骤进行操作。首先,你可以使用命令`git apply --stat 0001-limit-log-function.patch`来查看patch的情况。然后,你可以使用命令`git apply --check 0001-limit-log-function.patch`来检查patch是否能够成功应用,如果没有任何输出,则说明没有冲突,可以继续打patch。接下来,你可以使用命令`git apply 0001-limit-log-function.patch`来应用patch文件。\[1\]如果你想上传patch文件,你可以参考这篇文章:https://blog.csdn.net/qq_21583139/article/details/119588733。在正式打patch之前,一定要先备份原项目代码,并将patch文件放到线上项目目录下。确保线上的当前最新commit与打patch时生成的patch文件是相同的。最后,你可以使用命令`git apply --check 0001-bugfix-for-sg.patch`来检查patch文件是否与项目冲突。如果没有冲突,你可以继续进行打patch的操作。\[2\]另外,如果你想生成一个补丁文件,你可以使用命令`git diff > test.patch`。这个命令会将所有修改的文件都打成一个补丁文件,但需要注意的是,这里是本地修改的,没有执行add缓存的操作。\[3\]希望这些信息对你有帮助! #### 引用[.reference_title] - *1* [gitpatch的方法](https://blog.csdn.net/Chen_leilei/article/details/124153983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [git项目如何打patch以及打patch的注意事项](https://blog.csdn.net/qq_21583139/article/details/127036451)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Gitpatch (打补丁)的使用](https://blog.csdn.net/qq_33210042/article/details/128097580)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值