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

  • 相关阅读:
    ArcGIS10.1软件安装教程
    CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
    JavaCV音视频开发宝典:UDP广播推流 使用UDP方式推送广播TS流 实现UDP一对多广播
    51单片机实验03-定时器T0来实现流水灯从左到右再从右到左
    el-select单选
    Android单编模块报FAILED: ninja: unknown target ‘MODULES-IN-vendor错误解决
    C++算法题 - 矩阵
    ConcurrentHashMap为什么不允许插入null值?
    消息中间件解析 | 如何正确理解软件应用系统中关于系统通信的那些事?
    pytest中allure特性
  • 原文地址:https://blog.csdn.net/jingerppp/article/details/125544022