当前位置:网站首页>How to use diff and patch to update the source code
How to use diff and patch to update the source code
2022-07-04 10:31:00 【Big bear loves to work】
About updating the source code diff
And patch
command
Reference material :
①《 Master Linux》p17,p279–p280
②《 happy Linux Command line 》http://billie66.github.io/TLCL/ p291–p295
③《 Bird brother Linux Private dishes , Basics 3 edition 》p366–p368
diff
command
It is mainly used to compare the differences between files or directories , coordination
patch
Command can realize the change between different program source code versions . A common use case isdiff
The program creates adiff file
orpatch Patch file
, thenpatch
Use this file to update the source codediff Comparison commands have different output styles , Here is a record of the most commonly used unified pattern style , I.e. use
-u
Options- Suppose there are two different files
file1.txt
andfile2.txt
, As shown below :
- Suppose there are two different files
call diff Command to compare , The output style is unified
diff -u file1.txt file2.txt # The output is as follows :
- The first two lines are the beginning of the file name and timestamp , The first file uses
---
Make a mark , For the second file+++
Make a mark - In the third line
@@ -1,4 +1,4 @@
It describes that the range of differences in the first file is 1 Go to the first place 4 That's ok , The range of differences in the second document is 1 Go to the first place 4 That's ok ,-
It means the first file ,+
Represents the second file - The string after the third line is the text line itself , Start with three characters , Represents different meanings
Space
Indicates that both files contain line changes ;-
Indicates that when updating from one file to the second file, you need to delete and change lines ;+
Indicates that the line change needs to be added when updating from the first file to the second file
- Be careful : The patch file has included all updates / Modify strategy , So when updating, you can update as long as you can find the file
- The first two lines are the beginning of the file name and timestamp , The first file uses
in addition :
diff
It can work in any text file , Source code 、 Configuration files, etcUse diff Command to generate difference file or patch file
diff -Naur old_file new_file > diff_file # among old_file and new_file It can be either a file or a directory -N Indicates if it is a comparison directory , If document A Only appear in a directory , The preset is displayed as Only in..... -u Indicates using unified mode output , That is, the mode described above -r Indicates recursive comparison of subdirectories -a Means to compare text files line by line
for example :
diff -Naur file1.txt file2.txt > file.patch
Then we can use
patch
Command andfile.patch
Update the patch filepatch
command# to update patch -pN < patch_file # Restore patch -R -pN < patch_file -p Said to ignore N Layer Directory ( This place is a little difficult to understand , I'll say later ) -R Means to restore the new file to the old version
Then, above : to update
file1.txt
Tofile2.txt
# Type first to include file1.txt and file2.txt Under the directory of , Then execute the order patch < file.patch # We don't need to specify to update / Patched target file , because diff file /file.patch The file name has been included in the title line of the file
Or update with the following command :
-p
Parameters are mainly used in directory related places , Suppose there is a patch file with the beginning shown below :situation 1: If you are currently in
src
Under the table of contents , You can directly execute the following commands to update :patch -p0 < file.patch or patch < file.patch
situation 2: If the beginning of the patch is different from the current environment , You can use
-p
Appropriately ignore several levels of directoriesThat is, if your current directory is
package-3.45
, There issrc
Catalog , For the patch file above , You need to ignore the first level directorypatch -p1 < file.patch # among file.patch You can also use the absolute path to locate the file
If it is after the source code is updated , You can recompile and build 、 Installed
make clean main # Clean up the target file first , And then build make install # install
边栏推荐
- Uniapp--- initial use of websocket (long link implementation)
- /*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
- DCL statement of MySQL Foundation
- Delayed message center design
- [200 opencv routines] 218 Multi line italic text watermark
- Rhsca day 11 operation
- Snake (C language)
- leetcode842. Split the array into Fibonacci sequences
- 2. Data type
- What is an excellent architect in my heart?
猜你喜欢
Rhcsa learning practice
A little feeling
Knapsack problem and 0-1 knapsack problem
What is an excellent architect in my heart?
Jianzhi offer 04 (implemented in C language)
Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
For programmers, if it hurts the most...
Servlet基本原理与常见API方法的应用
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
随机推荐
RHCE day 3
【Day1】 deep-learning-basics
Dynamic memory management
Development guidance document of CMDB
Rhcsa operation
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
Latex learning insertion number - list of filled dots, bars, numbers
Knapsack problem and 0-1 knapsack problem
2021-08-10 character pointer
Evolution from monomer architecture to microservice architecture
Vanishing numbers
Uniapp--- initial use of websocket (long link implementation)
Remove linked list elements
How to teach yourself to learn programming
How do microservices aggregate API documents? This wave of show~
Rhcsa day 10 operation
Latex insert picture, insert formula
Sword finger offer 31 Stack push in and pop-up sequence
Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
What is an excellent architect in my heart?