Patch and Diff

This post is basically a note to self because I find myself having to do a google search every time I want to do some diffing and merging of file trees.

If I want to create a patch to bring the source tree in www up to date with the source tree in www_new, I would do:

#diff -urp  www www2 > mypatch.patch

Note that this doesn’t include creating new files or deleting old ones (i.e. applying this patch will only modify files – not create or delete files).

The flags are:
-u : Unified format – not sure why this is necessary, but presumeably this is a preferred format of diff.
-r : Recursive so that it will merge files in subdirectories too.
-p : ??

Now to apply this patch we would:

#cd www
#patch -p1 < ../mypatch.patch

We entered the www directory because that is the directory we want to patch.

Flags:
-p1 : This means we will be stripping 1 level of the path from each file. This is because we made the patch from the parent directory so all of the files will be specified with paths beginning with www/ or www2/ . But our new context should only contain the portion within www.

comments powered by Disqus