How To Create And Apply Patches
Patch … patch everything!
Sometimes you have to change a small (or not so small) piece of third-party code and you do not want to go through all the hassle of creating a GIT fork or wait for a merge request to be approved. Who knows, there may not even be a GIT repository. That’s what patches are for.
A patch is, by definition, a software update consisting of code, that replaces or enhances already existing code. It can be applied manually or automatically while deploying for example.
Patches are supposed to be small, usually, a few lines of code, and are supposed to fix some of the most common problems:
- fixing a bug
- adding a feature
- fixing a security vulnerability
And they look like this:
As you can see the file structure isn’t that complicated. Let me go through all the lines:
- The first line tells you which file gets patched. It contains some basic information like the file name and the date it was created.