How to create or apply a patch?

Often programmers that haven’t worked with patches before find it intimidating. Patches are actually very simple to deal with. Here is how.

Creating Patches


diff -u oldfile newfile > filename.patch

or

diff -urN /olddir /newdir > filename.patch

or

diff -urN -X excludes /olddir /newdir > filename.patch

diff options:
-u Output (default 2) lines of unified context.
-r Recursively compare any subdirectories found.
-N Treat absent files as empty.
-X FILE Exclude files that match any pattern in FILE.

Note: The -u options can be replaced with -c to create a context format diff file with a setting of two lines.

Applying Patches


gzip -cd patch.gz | patch -p0

or

bzip2 -dc patch.bz2 | patch -p0

or

patch -p0 < filename.patch

patch options:
-p NUM Strip NUM leading components from file names.

This entry was posted in AIX, Dedicated Servers, Hosting Support, Linux, Mac OS X, Managed Hosting, OpenBSD and tagged , . Bookmark the permalink.

NewPush has solutions to fit your business needs.  For more than a decade, our focus has been to take on the technical challenges that are the hardest and most time-consumming.  Our goal is to free up your resources to focus on the core activities of your business and to drive your business performance.  Please visit our main site at newpush.com for more information or call us at +1-303-423-4500.