patch简单使用

如何生成patch?

cary@cary:~$ cat a.txt 
aaaa
bbbb
cccc

cary@cary:~$ cat b.txt 
bbbb
cary@cary:~$ diff a.txt b.txt 
1d0
< aaaa
3,4d1
< cccc
< 
cary@cary:~$ diff -u a.txt b.txt 
--- a.txt	2023-03-29 11:07:23.441150413 +0800
+++ b.txt	2023-03-29 11:05:18.301147231 +0800
@@ -1,4 +1 @@
-aaaa
 bbbb
-cccc
-

生成patch
cary@cary:~$ diff -u b.txt a.txt
--- b.txt	2023-03-29 11:05:18.301147231 +0800
+++ a.txt	2023-03-29 11:07:23.441150413 +0800
@@ -1 +1,4 @@
+aaaa
 bbbb
+cccc
+
cary@cary:~$ diff -u b.txt a.txt > for_b.patch
cary@cary:~$ cat b.txt 
bbbb

打patch
cary@cary:~$ patch b.txt < for_b.patch 
patching file b.txt
cary@cary:~$ cat b.txt 
aaaa
bbbb
cccc

cary@cary:~$ diff a.txt b.txt 

如何撤销patch?

cary@cary:~$ patch -RE < for_b.patch 
patching file b.txt
cary@cary:~$ cat b.txt 
bbbb
cary@cary:~$ 

你可能感兴趣的:(linux,运维,服务器)