• git am冲突解决办法


    0. 前言

    我们在合并patch的时候,希望将patch 作者的基本信息也一并合并,这样就需要git am命令,但是在git am 合并的时候会出现冲突,如何快速有效的解决呢?本文基于git am 命令提供两种方法。

    1. 使用git am 命令尝试合并

    ​​​​​​​

     

    2. git apply --reject合入不冲突部分,保留冲突部分

    1. git apply --reject 0001-62412e5b8c33ee711aa20500cb1a9bb948c1f7d7.patch
    2. Checking patch mm/page_alloc.c...
    3. warning: mm/page_alloc.c has type 100755, expected 100644
    4. error: while searching for:
    5. const struct alloc_context *ac)
    6. {
    7. unsigned int noreclaim_flag;
    8. unsigned long pflags, progress;
    9. cond_resched();
    10. /* We now go into synchronous reclaim */
    11. cpuset_memory_pressure_bump();
    12. psi_memstall_enter(&pflags);
    13. fs_reclaim_acquire(gfp_mask);
    14. noreclaim_flag = memalloc_noreclaim_save();
    15. error: patch failed: mm/page_alloc.c:4476
    16. Hunk #2 succeeded at 4254 (offset -236 lines).
    17. Hunk #3 succeeded at 4267 (offset -236 lines).
    18. Hunk #4 succeeded at 4289 (offset -236 lines).
    19. Applying patch mm/page_alloc.c with 1 reject...
    20. Rejected hunk #1.
    21. Hunk #2 applied cleanly.
    22. Hunk #3 applied cleanly.
    23. Hunk #4 applied cleanly.

    3. git status 查看apply 之后的状态

    1. git apply --reject 0001-62412e5b8c33ee711aa20500cb1a9bb948c1f7d7.patch
    2. Checking patch mm/page_alloc.c...
    3. warning: mm/page_alloc.c has type 100755, expected 100644
    4. error: while searching for:
    5. const struct alloc_context *ac)
    6. {
    7. unsigned int noreclaim_flag;
    8. unsigned long pflags, progress;
    9. cond_resched();
    10. /* We now go into synchronous reclaim */
    11. cpuset_memory_pressure_bump();
    12. psi_memstall_enter(&pflags);
    13. fs_reclaim_acquire(gfp_mask);
    14. noreclaim_flag = memalloc_noreclaim_save();
    15. error: patch failed: mm/page_alloc.c:4476
    16. Hunk #2 succeeded at 4254 (offset -236 lines).
    17. Hunk #3 succeeded at 4267 (offset -236 lines).
    18. Hunk #4 succeeded at 4289 (offset -236 lines).
    19. Applying patch mm/page_alloc.c with 1 reject...
    20. Rejected hunk #1.
    21. Hunk #2 applied cleanly.
    22. Hunk #3 applied cleanly.
    23. Hunk #4 applied cleanly.
    24. ~/work/jr510_r_1.0_dev/android/kernel/jlq-5.4:
    25. git status .
    26. HEAD detached at f315c6d67d28
    27. You are in the middle of an am session.
    28. (fix conflicts and then run "git am --continue")
    29. (use "git am --skip" to skip this patch)
    30. (use "git am --abort" to restore the original branch)
    31. Changes not staged for commit:
    32. (use "git add <file>..." to update what will be committed)
    33. (use "git checkout -- <file>..." to discard changes in working directory)
    34. modified: mm/page_alloc.c
    35. Untracked files:
    36. (use "git add <file>..." to include in what will be committed)
    37. mm/page_alloc.c.rej

    会在文件目录下产生一个 .rej 后缀的文件,里面就是无法自动合并的冲突,需要手动修改。

    4. git am --continue 进行中断后的操作

    • 因为修改后的文件是modified 状态,需要git add 将其修改位added 状态,然后进行
    • git am --continue 进行之前中断后的操作。
    • 有可能需要Changed Id,git commit --amend 可以生成;
    • git log 查看是否已经添加成功;
    • git show 查看patch 是否是自己需要的;

    5. 第二种方法

    • 对于修改起来比较简单的,可以手动修改之后产生一个修改的manual.patch;
    • 然后同样git am source.patch,这个时候会提示冲突;
    • 不要管上面这一步,直接git apply manual.patch,这个patch 肯定可以apply的;
    • git add -> git am --continue -> git commit --amend -> git push。。

  • 相关阅读:
    Mac系统每次更改vscode中的文件都提示权限不足
    Typescript-----面试题
    ubuntu18.04 +CUDA11.1 + pytorch1.8.1 环境配置
    关于利用rundll32执行程序的分析
    samba服务器的功能是什么
    vue中使用高德地图的热力图方法1
    基于小程序制作一个猜拳小游戏
    C练题笔记之:Leetcode-137. 只出现一次的数字 II
    Spring boot 实践Rabbitmq消息防丢失
    Taurus .Net Core 微服务开源框架:Admin 插件【4-2】 - 配置管理-Mvc【含请求日志打印】
  • 原文地址:https://blog.csdn.net/jingerppp/article/details/125544022