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.
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.
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.
$ 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!
Tweet
thanks!