git am冲突解决办法

0. 前言

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

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

​​​​​​​

 

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

git apply --reject 0001-62412e5b8c33ee711aa20500cb1a9bb948c1f7d7.patch
Checking patch mm/page_alloc.c...
warning: mm/page_alloc.c has type 100755, expected 100644
error: while searching for:
                                        const struct alloc_context *ac)
{
        unsigned int noreclaim_flag;
        unsigned long pflags, progress;

        cond_resched();

        /* We now go into synchronous reclaim */
        cpuset_memory_pressure_bump();
        psi_memstall_enter(&pflags);
        fs_reclaim_acquire(gfp_mask);
        noreclaim_flag = memalloc_noreclaim_save();


error: patch failed: mm/page_alloc.c:4476
Hunk #2 succeeded at 4254 (offset -236 lines).
Hunk #3 succeeded at 4267 (offset -236 lines).
Hunk #4 succeeded at 4289 (offset -236 lines).
Applying patch mm/page_alloc.c with 1 reject...
Rejected hunk #1.
Hunk #2 applied cleanly.
Hunk #3 applied cleanly.
Hunk #4 applied cleanly.

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

git apply --reject 0001-62412e5b8c33ee711aa20500cb1a9bb948c1f7d7.patch
Checking patch mm/page_alloc.c...
warning: mm/page_alloc.c has type 100755, expected 100644
error: while searching for:
                                        const struct alloc_context *ac)
{
        unsigned int noreclaim_flag;
        unsigned long pflags, progress;

        cond_resched();

        /* We now go into synchronous reclaim */
        cpuset_memory_pressure_bump();
        psi_memstall_enter(&pflags);
        fs_reclaim_acquire(gfp_mask);
        noreclaim_flag = memalloc_noreclaim_save();


error: patch failed: mm/page_alloc.c:4476
Hunk #2 succeeded at 4254 (offset -236 lines).
Hunk #3 succeeded at 4267 (offset -236 lines).
Hunk #4 succeeded at 4289 (offset -236 lines).
Applying patch mm/page_alloc.c with 1 reject...
Rejected hunk #1.
Hunk #2 applied cleanly.
Hunk #3 applied cleanly.
Hunk #4 applied cleanly.
~/work/jr510_r_1.0_dev/android/kernel/jlq-5.4:
git status .
HEAD detached at f315c6d67d28
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)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   mm/page_alloc.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

私房菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值