quilt

使用例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# zh @ li in ~/li/tmp/hello [15:08:57]
$ ls
main.c

# zh @ li in ~/li/tmp/hello [15:08:58]
$ cat main.c
#include <stdio.h>
int main(int argv,char **argc) {
printf("Hello world\n");
return 0;
}

# zh @ li in ~/li/tmp/hello [15:09:04]
$ quilt new 0000-add_patched_first_line.patch # 创建一个patch
Patch patches/0000-add_patched_first_line.patch is now on top

# zh @ li in ~/li/tmp/hello [15:09:05]
$ tree
.
├── main.c
└── patches
└── series

1 directory, 2 files

# zh @ li in ~/li/tmp/hello [15:09:16]
$ quilt add main.c # 添加追踪文件
File main.c added to patch patches/0000-add_patched_first_line.patch

# zh @ li in ~/li/tmp/hello [15:09:18]
$ quilt edit main.c # 修改代码
File main.c is already in patch patches/0000-add_patched_first_line.patch

# zh @ li in ~/li/tmp/hello [15:09:52]
$ quilt diff # 查看代码改动内容
Index: hello/main.c
===================================================================
--- hello.orig/main.c
+++ hello/main.c
@@ -1,5 +1,6 @@
#include <stdio.h>
int main(int argv,char **argc) {
printf("Hello world\n");
+ printf("I am the first patched line\n");
return 0;
}

# zh @ li in ~/li/tmp/hello [15:10:03]
$ quilt refresh -pab # 把代码改动保存到patch文件
Refreshed patch patches/0000-add_patched_first_line.patch

# zh @ li in ~/li/tmp/hello [15:10:08]
$ tree
.
├── main.c
└── patches
├── 0000-add_patched_first_line.patch
└── series

1 directory, 3 files

# zh @ li in ~/li/tmp/hello [15:11:18]
$ quilt new 0001-add_patched_second_line.patch # 创建第2个patch(建议先用quilt push -a应用所有已存在的patch,然后再执行这个)
Patch patches/0001-add_patched_second_line.patch is now on top

# zh @ li in ~/li/tmp/hello [15:11:49]
$ quilt edit main.c
File main.c added to patch patches/0001-add_patched_second_line.patch

# zh @ li in ~/li/tmp/hello [15:11:56]
$ quilt diff
Index: hello/main.c
===================================================================
--- hello.orig/main.c
+++ hello/main.c
@@ -2,5 +2,6 @@
int main(int argv,char **argc) {
printf("Hello world\n");
printf("I am the first patched line\n");
+ printf("I am the second patched line\n");
return 0;
}

# zh @ li in ~/li/tmp/hello [15:12:07]
$ quilt refresh -pab
Refreshed patch patches/0001-add_patched_second_line.patch

# zh @ li in ~/li/tmp/hello [15:12:09]
$ tree
.
├── main.c
└── patches
├── 0000-add_patched_first_line.patch
├── 0001-add_patched_second_line.patch
└── series

1 directory, 4 files

# zh @ li in ~/li/tmp/hello [15:12:15]
$ quilt series # 查看全部patch
patches/0000-add_patched_first_line.patch
patches/0001-add_patched_second_line.patch

使用说明

quilt配置~/.quiltrc或者/etc/quilt.quiltrc,可以打开/usr/bin/quilt来看看

1
2
3
4
5
6
7
8
cat > ~/.quiltrc <<EOF
QUILT_DIFF_ARGS="--no-timestamps --no-index -p ab --color=auto"
QUILT_REFRESH_ARGS="--no-timestamps --no-index -p ab"
QUILT_SERIES_ARGS="--color=auto"
QUILT_PATCH_OPTS="--unified"
QUILT_DIFF_OPTS="-p"
EDITOR="vim"
EOF

前面几个都是对脚本里面使用diff,patch这些工具时,所使用的参数进行配置,EDITOR这项配置为自己习惯的编辑器

补丁名字以数字开头,然后通过-符号链接一个简短的描述,其中数字的大小就是最终打补丁的顺序

quilt files:查看被追踪的文件

quilt edit main.c:添加追踪并编辑,也可以quilt add main.c之后直接用其他编辑器编辑

quilt top:查看最近的补丁(最后一个)(初始为空)

quilt push:应用补丁(压栈)

1
2
3
quilt push -a #应用所有
quilt push 010-xxx.patch #应用从000->010所有的补丁
quilt push #应用单个补丁

quilt pop:取消应用(弹栈)(回滚)

1
2
3
quilt pop -a  #取消所有
quilt pop 002-yyy.patch #取消到指定指定补丁处(当前->002)
quilt pop #取消单个

quilt edit main.c:修改,开发

quilt diff:查看修改(当前补丁)

quilt refresh:保存为patch

quilt files:查看当前补丁中已修改文件