Many times in the project, you need to generate a patch file or patch the file to your project. This 2 minute guide will help you how to generate patch using diff command and patch the file using patch command.
Generating a Patch:
The Patch file can be created using the below command:
diff -rupN original_folder_name/ new_folder_name/ > mychanges.patch
Applying a Patch:
The patch file can be applied to your source code using below command:
You need to go to the folder of source code and run:
patch -p1 < kernel.patch
For patching a single file:
patch < changes.patch
The two-minute guide for patching and generating is finished.
If you have more time you can look below:
patch -p: What does -pnum means?
This will 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.
You can also use --strip=num instead of -pnum
diff -rupN: what does -rupN means?
-r stands for recursively comparing the subdirectories.
-u stands for unified ouput format.
-p shows which C function has the change.
-N tells diff command that if file is found only in one directory, treat it as present but empty in other directory.
If you still have more time, check the man pages of diff and patch:
man patch
man diff
Related Posts