Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1199632
  • 博文数量: 185
  • 博客积分: 495
  • 博客等级: 下士
  • 技术积分: 1418
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-02 15:12
个人简介

治肾虚不含糖,专注内核性能优化二十年。 https://github.com/KnightKu

文章分类

全部博文(185)

文章存档

2019年(1)

2018年(12)

2017年(5)

2016年(23)

2015年(1)

2014年(22)

2013年(82)

2012年(39)

分类: LINUX

2013-01-21 15:32:12

最近有个backport补丁集的工作,patchset是从maillist里面直接抓的,做的过程中自然会出现冲突,比如:

git am tree.eml 
Applying: xxxxx.patch added to -mm tree
error: patch failed: mm/sparse.c:805
error: mm/sparse.c: patch does not apply
Patch failed at tree
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".

刚开始一看有些懵,因为没有任何冲突在哪里的提示,后来找到一种方法:

1.am 操作出问题后先手工 apply patch中没有冲突的部分:

git apply --reject tree.eml 
Checking patch mm/memory_hotplug.c...
Checking patch mm/sparse.c...
error: while searching for:
                ms->section_mem_map = 0;
                ms->pageblock_flags = NULL;
        }

        clear_hwpoisoned_pages(memmap, PAGES_PER_SECTION);
        free_section_usemap(memmap, usemap);

error: patch failed: mm/sparse.c:805
Applied patch mm/memory_hotplug.c cleanly.
Applying patch mm/sparse.c with 1 rejects...
Hunk #1 applied cleanly.
Rejected hunk #2.

这样,就把没有冲突的文件先合并了,剩下有冲突的作了标记。先看输出,error: while searching for: 说明是这段代码有冲突,

error: patch failed: mm/sparse.c:805 指明了产生冲突的代码片断的开始行号,相应的,patch 中应该有这么一段:

同时,还会产生一个 mm/sparse.c.rej文件,里面也是上面这段因为冲突无法合并的代码片断。

2.根据apply的输出提示以及mm/sparse.c.rej文件中的描述,手动修正代码。

3.改好之后,用 git add 把 mm/sparse.c 添加到缓冲区,同时也要把其他没有冲突合并成功了的文件也加进来,因为在作 apply 操作的时候他们也发生了变化:

$ git add mm/sparse.c 

4.最后:$ git am --resolved

Applying: tree

冲突解决成功


大功告成。

中间如果处理乱了,用 git reset 恢复即可,所以合并 patch 在一个“干净”的分支上处理更好。



阅读(10638) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~