Friday, June 10, 2011

Create and apply patch

The diff program can be used to compare two files and to make patches. A typical
example might be

diff -ruN file.old file.new > file.diff

If you want to apply the patch to one file, modify the diff file first few lines
as
--- a/frameworks/base/core/java/android/webkit/WebView.java 2011-05-31 16:41
:46.985618991 -0400
+++ b/frameworks/base/core/java/android/webkit/WebView.java 2011-06-10 14:09
:28.513675152 -0400


This command will create a diff (recursively if directories are used) that shows

the changes, or "delta", between the two files.


To apply the patch created above, we can invoke

patch --dry-run -p1 -i file.diff.

patch -p1 -i file.diff.


The -p tells patch how much it should strip from the paths for the file names in

the patch. -p0 means to strip nothing, or leave the path intact.



For example, supposing the file name in the patch file was

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and not specifying -p at all just gives you blurfl.c.

No comments:

Post a Comment