假设一个人A写了main.c程序之后,把代码发给另外一个人B,B写了程序之后,再把代码合入到自己的当中,但是A只想把B的差异部分合入到自己的代码当中,在这种情况之下可以通过diff命令生成差异文件,在合入到自己的代码当中。
代码结构:
A编写的test1/main.c
#include
int main()
{
printf("hello world\r
");
return 0;
}
B编写的test2/main.c
#include
int main()
{
printf("hello world\r
");
printf("hello zhuangzebin\r
");
return 0;
} diff 命令生成差异文件:diff -ruNa test1/main.c test2/main.c > diff.patch
diff.patch内容如下
--- test1/main.c 2022-07-16 11:03:09.743250327 +0800
+++ test2/main.c 2022-07-16 11:03:25.575527477 +0800
@@ -3,6 +3,7 @@
int main()
{
printf("hello world\r
");
+ printf("hello zhuangzebin\r
");
return 0;
-}
+}
使用如下命令即可把patch合入,合入之后,test1/main.c的内容跟test2/main.c的一样
| 留言与评论(共有 0 条评论) “” |