当前位置:网站首页>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
边栏推荐
- Network disk installation
- C language - stack
- Two way process republication + routing policy
- Reasons and solutions for the 8-hour difference in mongodb data date display
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- Hlk-w801wifi connection
- Pod management
- PHP code audit 3 - system reload vulnerability
- Velodyne configuration command
- Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
猜你喜欢
【Day1】 deep-learning-basics
Recursion and divide and conquer strategy
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
[200 opencv routines] 218 Multi line italic text watermark
Tables in the thesis of latex learning
Online troubleshooting
RHCE - day one
OSPF summary
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
随机推荐
From programmers to large-scale distributed architects, where are you (I)
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Exercise 7-4 find out the elements that are not common to two arrays (20 points)
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
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.
【Day2】 convolutional-neural-networks
BGP ---- border gateway routing protocol ----- basic experiment
Legion is a network penetration tool
/*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*/
Basic principle of servlet and application of common API methods
From programmers to large-scale distributed architects, where are you (2)
A little feeling
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
Rhcsa - day 13
Four characteristics and isolation levels of database transactions
Architecture introduction
Linked list operation can never change without its roots
Static comprehensive experiment ---hcip1
Reprint: summation formula of proportional series and its derivation process
For programmers, if it hurts the most...