Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate patches and make patches in Linux system

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

How to generate patches and make patches in Linux system? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Generate patches: create hello.c and hello_new.c files as shown below.

➜diff ls hello.c hello_new.c hello_test.c hi.patch➜ diff cat hello.c # include "stdio.h" int main (int argc, char * * argv) {printf ("Hello World");} ➜diff cat hello_new.c # include "stdio.h" int main (int argc, char * * argv) {printf ("Hello World\ n"); return 0 } use the diff-uN command to generate patch ➜diff diff-uN hello_new.c hello.c > hi.patch➜ diff cat hi.patch-hello_new.c 2018-07-17 1658 hello.c 23.679704122 + 0800 + hello.c 2018-07-17 16V 57V 59.190677641 + 0800 @ @-1 include 6 + 1 @ @ # include "stdio.h" int main (int argc, char * * argv) {- printf ("Hello World\ n");-return 0 + printf ("Hello World");} so far, the patch has been created.

After that, we patch the hello.c file using the patch command.

➜diff patch-p0 shows that the patch has been successfully applied and the .orig source file has been generated. The-backup-if-mismatch option does not need to generate the orig file. ➜diff patch-p0-- no-backup-if-mismatchdiff and patch commands introduce: 1, diff-NAME diff- find differences between two filesSYNOPSIS diff [options] from-file to-file- simply, the function of diff is to compare the differences between the two files, and then record it, that is, the so-called diff patch. Syntax format: diff [option] source file (folder) destination file (folder), is to patch the source file (folder) so that it becomes the destination file (folder), the term is "upgrade". Here are the three most commonly used options:-r is a recursive option, and when set, diff compares all the corresponding files in the source code directories of the two different versions, including subdirectory files. The-N option ensures that the patch file will correctly handle situations where files have been created or deleted. The-u option creates a patch file in a uniform format, which is more compact than the default format. 2. Patch-NAME patch- apply a diff file to an originalSYNOPSIS patch [options] [originalfile [patchfile]] but usually just patch- pnum-to put it simply, patch uses patches made by diff to convert source files (folders) and destination files (folders). This means that you can have source files (folders)-> destination files (folders) or destination files (folders)-> source files (folders). Here are some of the most commonly used options:-pnum or-strip=num Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was/u/howard/src/blurfl/blurfl.csetting-p0 gives the entire file name unmodified,-p1 givesu/howard/src/blurfl/blurfl.cwithout the leading slash,-p4 givesblurfl/blurfl.cand not specifying-pat all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the-d option. You can use the man diff and man patch commands to view the specific instructions. At this point, the methods of generating patches and patches in the Linux system are shared. You are welcome to leave a message in the comments area. The above is the Linux system-related content shared by Liangxu tutorial Network for all friends. If you want to know more about Linux, remember to follow the official account "good Linux", or scan the QR code below to follow, more practical information is waiting for you! What are the versions of Linux? the versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

On the Linux system how to generate patches and patch questions to share here, I hope the above content can be of some help to you, if you still have a lot of doubts to solve, you can follow the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report