Patch generated by the diff command, hit Command Patch by Patch

Recently met git format-patch and git am circumstances does not work with git format-patch to play patch with git am not a direct hit, each time conflict, the cause has not been found, I had to find other ways, in the process found that can generate a patch with the diff command, hit the patch with the patch command.

1. Generate patches for a single file

1 $ diff -up linux-2.6.28.8/net/sunrpc/svc.orig.c linux-2.6.28.8/net/sunrpc/svc.c > patch
This command will produce output similar to the following, you redirect it to a file, this file is the patch.
1 diff -up linux-2.6.28.8/net/sunrpc/svc.orig.c 2009-03-17 08:50:04.000000000 +0800
2 +++ linux-2.6.28.8/net/sunrpc/svc.c 2009-03-30 19:18:41.859375000 +0800
3 @@ -1050,11 +1050,11 @@ svc_process(struct svc_rqst *rqstp)
Detailed parameters:
-u show differences before and after the row lines (context), the default is 3 rows before and after, so that, in Patch with more information.
c -p information display function code appears.

2. Generate patches for multiple files

1 $ diff -uprN linux-2.6.28.8.orig/net/sunrpc/ linux-2.6.28.8/net/sunrpc/ > patch
This command compares the differences in all the source linux-2.6.28.8.orig / net / sunrpc / and linux-2.6.28.8 / net / sunrpc / two directories.
Detailed parameters:
Comparative -r recursively a directory and all of its subdirectories (i.e., the entire tree).
-N If a file is missing, it is treated as an empty file to compare. If you do not use this option when the diff found the old code or new code missing files, missing files simply tips. If you use this option, will the new file as a new print out the new part.

3. Patching

Patch generated path information includes the name of the directory diff when generating the patch, but others may be other directory name, so when the patch, must fight to enter the code directory, and told the patch tool, please ignore the patch a first level directory path (parameter -p1).
1 $ patch -p1 < patch1.diff
diff command must be performed on an entire Linux source directory of the root directory.

Example 4

To generate a modified kernel patch, and then use the patch have not been modified to generate a kernel patch
Wherein, the directory linux-2.6.31.3 kernel is not modified, the directory linux-2.6.31.3_1 is modified kernel
1 $ diff -uprN linux-2.6.31.3 linux-2.6.31.3_1/ > mypatch
2 $ cd linux-2.6.31.3
3 $ patch -p1 < mypatch

 

Notes :

1. When playing patch, parameter -p1, is 1 instead of l. Why ignore the first-level directory, because the same tree structure under the project, but the project is not necessarily the same name, so playing patch when you can avoid this problem by p1. This particular execution path can be determined by looking at the patch of the patch content.

2. Parameter -p1 1 1 directory level representatives ignored, if the parameter is ignored -p2 directory level 2, and so on. Example 4 Take, for example, is directly behind the diff -upRn with two parts catalog file is modified, so playing patch parameters -p1 can. If the directory folder in front of two same path, then the parameters need to be changed -p3

 

Reference links: generating patch and hit the patch under Linux  https://www.cnblogs.com/aaronLinux/p/5860552.html

Guess you like

Origin www.cnblogs.com/ArsenalfanInECNU/p/12486435.html