inside the mind of a linux admin

Linux Protip: How to make a patch file

I’ve been doing Linux system administration for well over ten years, and I’ve used patch files often. I’ve never actually had the need to create one until today. To my surprise, I discovered how blatantly simple and easy it is. I’ve always assumed it was some sort of black magic involving unicorns and rainbows. Sure, there are more complex ways to do this but for most needs this will work for you.

Whats a patch?

A patch is the best and easiest way to submit changes back to an open source project. It’s a summary of changes you made to file or files formatted in a way that can easily be used by the excellent program, named, unsurprisingly, ‘patch’. Now because patch was written by the inestimable Larry Wall, patches can come in a wide range of shapes, sizes, and formats, and they will apply with a high degree of “do what I mean”-ness. However, there are some tips to produce high quality patches.

Creating a patch file

diff -Naur old new > patch_file

Yeah, seriously. That’s it.

Now you’ve got a working .patch file that you can use to apply the changes between ‘old’ and ‘new’ anytime, on any machine, anywhere. It automatically determines the difference and the lines that changed. After it builds the patch file, it must be applied to identical code it was built from.

This is very useful when you need to change working code uniformly.

Applying a patch file


The following usage is most commonly used method to apply a patch:

$ patch -p1 < {/path/to/patch/file}

To apply a patch, one could run the following command in a shell:
$ patch < /path/to/file

Patches can be undone, or reversed, with the '-R' option:
$ patch -R < /path/to/file

Above 3 are basic usage read the man page of patch command for more information and usage:
% man patch

Cheers!

Related Posts

synergy: How to enable crypto (encryption) and generate SSL certificate

The newer Linux versions of the popular mouse/keyboard sharing application “synergy” now has built in encryption. Here’s how to configure it: Just simply passing the –enable-crypto flag on your synergy server without having a proper SSL certificate will result in the inability to connect to clients and generate an error message similar to this in […]

Read More

Change Number Pad Delete (dot) key from a comma in Ubuntu Linux

I recently purchased a new keyboard and updated to the latest Ubuntu, I’m also an avid user of the number pad for quick input when dealing with spreadsheets or accounting. I found that my num pad’s delete key (“.”) was outputting a comma (“,”) instead. Pretty annoying? I agree, but this can be very easily […]

Read More

1 Comment

  • ein on Sunday, October 14, 2012

    thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.