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