background:
Using the patch for embedded developers, the maintenance or development of more convenient.
Production Patch:
diff - compare files line by line.
Format: diff old parameter file / folder New old / new folder (note the order in the old and new folders)
diff has many parameters, but mainly with the following parameters in the production patch.
- N will nonexistent files as empty - A all files as text files - U in a consolidated way to display the contents of different files -r way to compare all subdirectories recursively
// compare Test1 Test2 update on the version and output
diff - Naru Test1 Test2 // compare Test1 Test2 update on the version and output to a file diff.patch diff -Naru Test1 Test2> diff.patch
$ cat a.c
12345
67890
abcdefg
hijklmn
opq
rst
$ cat b.c
12345
67908
abcdefg
ABCDEFG
hijklmn
oq
Look at the operation, as long as it is equivalent to the redirection file made into a file:
$ The diff AC BC - Naur --- AC 2019 - 12 is - 26 is 22 is : 47 : 23.826403400 + 0800 +++ BC 2019 - 12 is - 26 is 22 is : 47 : 21.287250500 + 0800 @@ - . 1 , . 6 + . 1 , . 6 @@ 12345 - 67890 // - delete this line on behalf of + 67 908 // + increase this line; first - after + equivalent is equal to the change 67908 67890 abcdefg + ABCDEFG // + increase this line hijklmn - OPQ // - representatives remove this line - RST // - delete this line on behalf of + OQ // + increase this line
As long as it is equivalent to the redirection file made into patches:
diff -Naru a.c b.c > diff.patch
Patch:
patch - apply a diff file to an original file
format:
patch parameters < patch - b backup of the original file, patch, copies or renames the original file to back up - R Undo Patch -p (num) represents a negligible num trails
For files patched
You can directly use the following command:
patch -b < diff.patch
Effect: enables content into ac and bc exactly the same, to keep a suffix .orig but the same content before the content and ac file.
For patches directory
Use -pN (N represents a number) patch specified directory path from the first few levels.
kernel_a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c kernel_b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c The top row is assumed that the first patch If you use -p0, to / from start directory, which is to start from kernel_a directory; If you use -p1, started from the drivers directory, that is, from the kernel / beginning drivers directory, ignoring differences in the kernel file in the current directory; And so on.
To the root of the differences between the two directories, enter the following command, let the patch start from the root of the difference changes
patch -bp0 < diff.patch
You can use -x to exclude specified path
Undo Patch:
patch - apply a diff file to an original file
format
patch -R [Other parameters] <patch
-R revoke fight patch
diff - compare files line by line.
Format: diff old parameter file / folder New old / new folder (note the order in the old and new folders)
diff has many parameters, but mainly with the following parameters in the production patch.
- N will nonexistent files as empty - A all files as text files - U in a consolidated way to display the contents of different files -r way to compare all subdirectories recursively
// compare Test1 Test2 update on the version and output
diff - Naru Test1 Test2 // compare Test1 Test2 update on the version and output to a file diff.patch diff -Naru Test1 Test2> diff.patch
$ cat a.c
12345
67890
abcdefg
hijklmn
opq
rst
$ cat b.c
12345
67908
abcdefg
ABCDEFG
hijklmn
oq
Look at the operation, as long as it is equivalent to the redirection file made into a file:
$ The diff AC BC - Naur --- AC 2019 - 12 is - 26 is 22 is : 47 : 23.826403400 + 0800 +++ BC 2019 - 12 is - 26 is 22 is : 47 : 21.287250500 + 0800 @@ - . 1 , . 6 + . 1 , . 6 @@ 12345 - 67890 // - delete this line on behalf of + 67 908 // + increase this line; first - after + equivalent is equal to the change 67908 67890 abcdefg + ABCDEFG // + increase this line hijklmn - OPQ // - representatives remove this line - RST // - delete this line on behalf of + OQ // + increase this line
As long as it is equivalent to the redirection file made into patches:
diff -Naru a.c b.c > diff.patch
Patch:
patch - apply a diff file to an original file
format:
patch parameters < patch - b backup of the original file, patch, copies or renames the original file to back up - R Undo Patch -p (num) represents a negligible num trails
For files patched
You can directly use the following command:
patch -b < diff.patch
Effect: enables content into ac and bc exactly the same, to keep a suffix .orig but the same content before the content and ac file.
For patches directory
Use -pN (N represents a number) patch specified directory path from the first few levels.
kernel_a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c kernel_b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c The top row is assumed that the first patch If you use -p0, to / from start directory, which is to start from kernel_a directory; If you use -p1, started from the drivers directory, that is, from the kernel / beginning drivers directory, ignoring differences in the kernel file in the current directory; And so on.
To the root of the differences between the two directories, enter the following command, let the patch start from the root of the difference changes
patch -bp0 < diff.patch
You can use -x to exclude specified path
Undo Patch:
patch - apply a diff file to an original file
format
patch -R [Other parameters] <patch
-R revoke fight patch