首页 热点资讯 义务教育 高等教育 出国留学 考研考公

如何用git-am来合并git format-patch生成的一系列的patch

发布网友

我来回答

1个回答

热心网友

下面举两个例子:

你现在有一个code base: small-src, 你的patch文件放在~/patch/0001-trival-patch.patch

cd small-src
git-am ~/patch/0001-trival-patch.patch

如果成功patch上去, 你就可以去喝杯茶了。

如果失败了, git 会提示错误, 比如:
error: patch failed: android/mediascanner.cpp:452
error: android/mediascanner.cpp: patch does not apply

这样你就需要先看看patch, 然后改改错误的这个文件,让这个patch能够patch上去。

你有一堆patch, 名字是上面提到的那一堆patch, 你把他们放在~/patch-set/目录下(路径随意)

cd opencore
git am ~/patch-set/*.patch

(这里git就会按照文件名的顺序一次am这些patch)
如果一切顺利, 你所有的patch都OK了, 你又Lucky了。

不过不顺利的时候十有*,如果git am中间遇到了patch,am就会停到打这个
patch的地方, 告诉你是哪个patch打不上去。

比如我现在有一个文件file,有两个patch.
file 的内容是
the text

more text

两个patch分别是:

0001-add-line.patch:
From 48869ccbced494e05738090afa5a54f2a261df0f Mon Sep 17 00:00:00 2001
From: zhangjiejing <zhangjiejing@zhangjiejing-desktop.(none)>
Date: Thu, 22 Apr 2010 13:04:34 +0800
Subject: [PATCH 1/2] add line

---
file | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/file b/file
index 067780e..685f0fa 1004
--- a/file
+++ b/file
@@ -3,3 +3,5 @@ file:
some text

more text
+
+add line
--
1.6.3.3

0002-change-line.patch:
From f756e1b3a87c216b7e0afea9d15badd033171578 Mon Sep 17 00:00:00 2001
From: zhangjiejing <zhangjiejing@zhangjiejing-desktop.(none)>
Date: Thu, 22 Apr 2010 13:05:19 +0800
Subject: [PATCH 2/2] change line

---
file | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/file b/file
index 685f0fa..7af7852 1004
--- a/file
+++ b/file
@@ -1,6 +1,6 @@
file:

-some text
+Change line text

more text

--
1.6.3.3

运行
git am *.patch

来merge这些patch, 报错, Patch failed at 0001 add line这样我们看0001这
个patch,原来patch需要的是some text, 而file里面是the text, 所以我们用编
辑器把这行改成some text,
vi file
git apply 0001-add-line.patch
git add file
git am --resolved

在解决完冲突以后, 比如用git add来让git知道你已经解决完冲突了。

如果你发现这个冲突是无法解决的, 要撤销整个am的东西。 可以运行git am –abort,

如果你想只是忽略这一个patch,可以运行git am –skip来跳过这个patch.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com