• 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。。

  • 相关阅读:
    Ubuntu 大压缩文件解压工具
    e为底数的指数运算e^x,math.exp(x)
    ChatGPT降温背后:大模型发展迎来真正转折点?
    【2022】Nginx使用ngx_http_upstream_module实现负载均衡功能
    87、Redis 的 value 所支持的数据类型(String、List、Set、Zset、Hash)---->List相关命令
    5分钟Python安装实战(MAC版本)
    专业还没选,有必要报班自学python吗?
    记录在搭建Jenkins时,所遇到的坑,以及解决方案
    Java诊断利器Arthas安装和使用
    【ArcGIS风暴】CASS建立标准分幅图框并在ArcGIS中DOM批量分幅案例教程
  • 原文地址:https://blog.csdn.net/jingerppp/article/details/125544022