当前位置:网站首页>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
patchCommand can realize the change between different program source code versions . A common use case isdiffThe program creates adiff fileorpatch Patch file, thenpatchUse 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
-uOptions- Suppose there are two different files
file1.txtandfile2.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
SpaceIndicates 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 :
diffIt 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 linefor example :
diff -Naur file1.txt file2.txt > file.patchThen we can use
patchCommand andfile.patchUpdate the patch filepatchcommand# 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 versionThen, above : to update
file1.txtTofile2.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 fileOr update with the following command :
-pParameters 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
srcUnder the table of contents , You can directly execute the following commands to update :patch -p0 < file.patch or patch < file.patchsituation 2: If the beginning of the patch is different from the current environment , You can use
-pAppropriately ignore several levels of directories
That is, if your current directory is
package-3.45, There issrcCatalog , 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 fileIf 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
边栏推荐
- AUTOSAR from getting started to mastering 100 lectures (106) - SOA in domain controllers
- Debug:==42==ERROR: AddressSanitizer: heap-buffer-overflow on address
- Huge number multiplication (C language)
- From programmers to large-scale distributed architects, where are you (2)
- PHP programming language (1) - operators
- Exercise 7-3 store the numbers in the array in reverse order (20 points)
- Hlk-w801wifi connection
- Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
- Recursion and divide and conquer strategy
- Introduction to extensible system architecture
猜你喜欢

The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago

RHCE - day one

今日睡眠质量记录78分

转载:等比数列的求和公式,及其推导过程

Linked list operation can never change without its roots

Rhcsa day 9

Two way process republication + routing policy

Dichotomy search (C language)

uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示

MongoDB数据日期显示相差8小时 原因和解决方案
随机推荐
Dynamic memory management
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
Talk about scalability
C language structure to realize simple address book
Pod management
What is an excellent architect in my heart?
Native div has editing ability
Work order management system OTRs
入职中国平安三周年的一些总结
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.
system design
Exercise 7-3 store the numbers in the array in reverse order (20 points)
Reasons and solutions for the 8-hour difference in mongodb data date display
leetcode1-3
BGP advanced experiment
OSPF summary
Realsense d435 d435i d415 depth camera obtains RGB map, left and right infrared camera map, depth map and IMU data under ROS
Exercise 8-10 output student grades (20 points)
Whether a person is reliable or not, closed loop is very important
/*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/