使用git作patch有以下几种
1.自己修改了一些代码,或者加了一些文件,然后做patch,方法如下:
(1)修改了代码
- [root@btg core]# vim system/core/rootdir/init.rc
-
[root@btg core]# vim rootdir/init.rc
-
[root@btg core]# git diff
-
diff --git a/rootdir/init.rc b/rootdir/init.rc
-
index 09920ab..c59661a 100755
-
--- a/rootdir/init.rc
-
+++ b/rootdir/init.rc
-
@@ -279,7 +279,7 @@ on boot
-
chown system system /sys/devices/platform/msm_sdcc.3/polling
-
chown system system /sys/devices/platform/msm_sdcc.4/polling
-
chown system system /sys/devices/platform/msm_hsusb/gadget/wakeup
-
-
-
+ chmod 777 /dev/ilitek_ctrl
-
# Define TCP buffer sizes for various networks
-
# ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
-
setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208
-
[root@btg core]#
上面是作通用的patch,接下来是做当前树的patch
- [root@btg core]# git commit -am "test message"
-
[LiuQi 58673fd] test message
-
1 files changed, 1 insertions(+), 1 deletions(-)
-
[root@btg core]# git format-patch -s -1
-
0001-test-message.patch
-
[root@btg core]# cat 0001-test-message.patch
-
From 58673fd548211ce90c5b8fee7fc429f29d27ebab Mon Sep 17 00:00:00 2001
-
From: LiuQi <lingjiujianke@gmail.com>
-
Date: Thu, 21 Apr 2011 15:21:55 +0800
-
Subject: [PATCH] test message
-
-
Change-Id: I033602c176d9825e7bcd0bd0ec2d736f9c29b396
-
-
Signed-off-by: LiuQi <lingjiujianke@gmail.com>
-
---
-
rootdir/init.rc | 2 +-
-
1 files changed, 1 insertions(+), 1 deletions(-)
-
-
diff --git a/rootdir/init.rc b/rootdir/init.rc
-
index 09920ab..c59661a 100755
-
--- a/rootdir/init.rc
-
+++ b/rootdir/init.rc
-
@@ -279,7 +279,7 @@ on boot
-
chown system system /sys/devices/platform/msm_sdcc.3/polling
-
chown system system /sys/devices/platform/msm_sdcc.4/polling
-
chown system system /sys/devices/platform/msm_hsusb/gadget/wakeup
-
-
-
+ chmod 777 /dev/ilitek_ctrl
-
# Define TCP buffer sizes for various networks
-
# ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
-
setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208
-
--
-
1.7.3.1
-
-
[root@btg core]#
这样,对一个文件的修改的patch就做完了
(2)文件添加的patch
首先添加一个文件,然后再commit
- [root@btg core]# touch testfile.c
-
[root@btg core]# vim testfile.c
-
[root@btg core]# cat testfile.c
-
#include <stdio.h>
-
-
void test(void)
-
{
-
return;
-
}
-
-
[root@btg core]# git add testfile.c
-
[root@btg core]# git commit -am "add testfile.c"
-
[LiuQi e4cf940] add testfile.c
-
1 files changed, 7 insertions(+), 0 deletions(-)
-
create mode 100644 testfile.c
-
[root@btg core]#
然后再生成patch
- [root@btg core]# git format-patch -s -1
-
0001-add-testfile.c.patch
-
[root@btg core]# cat 0001-add-testfile.c.patch
-
From e4cf940d60d9d62f57b5f0f3a489e31040e7ede8 Mon Sep 17 00:00:00 2001
-
From: LiuQi <lingjiujianke@gmail.com>
-
Date: Thu, 21 Apr 2011 15:29:18 +0800
-
Subject: [PATCH] add testfile.c
-
-
Change-Id: Ifa1f291e782b0a1c77889cb48ba943aeef6cd57f
-
-
Signed-off-by: LiuQi <lingjiujianke@gmail.com>
-
---
-
testfile.c | 7 +++++++
-
1 files changed, 7 insertions(+), 0 deletions(-)
-
create mode 100644 testfile.c
-
-
diff --git a/testfile.c b/testfile.c
-
new file mode 100644
-
index 0000000..0c49400
-
--- /dev/null
-
+++ b/testfile.c
-
@@ -0,0 +1,7 @@
-
+#include <stdio.h>
-
+
-
+void test(void)
-
+{
-
+ return;
-
+}
-
+
-
--
-
1.7.3.1
-
-
[root@btg core]#
这样,添加一个文件后作的patch就生成出来了
2. 当从服务器clone下来了最新的代码,然后想知道中间的某一部分的代码的patch,
可以使用如下方法获得修改的内容,并生成patch
这样,就把所有的patch都给列出来了,可以根据需要去进行选择
3.在不同的版本的间做patch
- [root@btg linux-2.6]# git tag -l
-
v2.6.11
-
v2.6.11-tree
-
.....
-
v2.6.37-rc6
-
v2.6.37-rc7
-
v2.6.37-rc8
-
v2.6.38
-
v2.6.38-rc1
-
v2.6.38-rc2
-
v2.6.38-rc3
-
v2.6.38-rc4
-
v2.6.38-rc5
-
v2.6.38-rc6
-
v2.6.38-rc7
-
v2.6.38-rc8
-
v2.6.39-rc1
-
v2.6.39-rc2
-
v2.6.39-rc3
-
v2.6.39-rc4
-
[root@btg linux-2.6]#
先列出来tag,然后再根据需要,进行patch生成,例如想知道2.6.38到2.6.39-rc2之间的ext2文件系统都做了什么
- [root@btg linux-2.6]# git diff v2.6.38 v2.6.38-rc2 fs/ext2/ > diff
-
[root@btg linux-2.6]# cat diff
-
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
-
index adb9185..2e1d834 100644
-
--- a/fs/ext2/namei.c
-
+++ b/fs/ext2/namei.c
-
@@ -344,6 +344,7 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
-
new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page);
-
if (!new_de)
-
goto out_dir;
-
+ inode_inc_link_count(old_inode);
-
ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
-
new_inode->i_ctime = CURRENT_TIME_SEC;
-
if (dir_de)
-
@@ -355,9 +356,12 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
-
if (new_dir->i_nlink >= EXT2_LINK_MAX)
-
goto out_dir;
-
}
-
+ inode_inc_link_count(old_inode);
-
err = ext2_add_link(new_dentry, old_inode);
-
- if (err)
-
+ if (err) {
-
+ inode_dec_link_count(old_inode);
-
goto out_dir;
-
+ }
-
if (dir_de)
-
inode_inc_link_count(new_dir);
-
}
-
@@ -365,11 +369,12 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
-
/*
-
* Like most other Unix systems, set the ctime for inodes on a
-
* rename.
-
+ * inode_dec_link_count() will mark the inode dirty.
-
*/
-
old_inode->i_ctime = CURRENT_TIME_SEC;
-
- mark_inode_dirty(old_inode);
-
-
ext2_delete_entry (old_de, old_page);
-
+ inode_dec_link_count(old_inode);
-
-
if (dir_de) {
-
if (old_dir != new_dir)
-
[root@btg linux-2.6]#
这样就搞定了,那个diff文件可以重新命个名,比如叫ext2_modify.patch
阅读(13720) | 评论(5) | 转发(2) |