当前位置:网站首页>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
边栏推荐
- Delayed message center design
- leetcode1-3
- Network disk installation
- uniapp---初步使用websocket(长链接实现)
- Recursive method to achieve full permutation (C language)
- A little feeling
- Es entry series - 6 document relevance and sorting
- On binary tree (C language)
- Basic data types of MySQL
- Knapsack problem and 0-1 knapsack problem
猜你喜欢

【Day1】 deep-learning-basics

【Day2】 convolutional-neural-networks

Some summaries of the third anniversary of joining Ping An in China

Jianzhi offer 04 (implemented in C language)

Today's sleep quality record 78 points

IPv6 comprehensive experiment

Use the data to tell you where is the most difficult province for the college entrance examination!

Basic principle of servlet and application of common API methods

Introduction to extensible system architecture

对于程序员来说,伤害力度最大的话。。。
随机推荐
【Day2】 convolutional-neural-networks
Basic data types of MySQL
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
Native div has editing ability
Hlk-w801wifi connection
Legion is a network penetration tool
What is an excellent architect in my heart?
按键精灵跑商学习-商品数量、价格提醒、判断背包
Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
RHCE day 3
Exercise 8-10 output student grades (20 points)
[untitled]
Rhcsa day 10 operation
Vs201 solution to failure to open source file HPP (or link library file)
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
MongoDB数据日期显示相差8小时 原因和解决方案
Velodyne configuration command
Collection of practical string functions
Dos:disk operating system, including core startup program and command program