Creating a patch

This page amends the Devmanual's patches article and Article description::describes how to create a patch for source code.

Using git
A source code patch for an existing package can easily be created using git.

Unpack the package to be patched using the command:

Step into the package directory which was created inside :

Initialize a git repository
If the unpacked directory is a git repository, skip the following initialization of the git repository.

Initialize the unpacked package sources as a git repository:

Add all the existing files to git and do a commit. Remember to write a commit message!

Make changes
Now make the necessary changes to the unpacked source code, one or more files may be changed. Of course, the required changes should probably be known in advance.

Here is an example of a command making changes to the source code:

Create diff using git
When changes are done, have output the diff, and  it into the patch file:

Nesting patches in the directory hierarchy
If the file(s) being patched are not unpacked into the root of the working directory,, but rather some sub-directory of the working directory, , then the patch must be modified to accommodate it.

Adjusting a malformed patch from TortoiseGit or Git for Windows
Patches generated by [//tortoisegit.org/docs/tortoisegit/tgit-dug-patch.html Tortoise Git] and Git for Windows are padded with additional information that  does not understand.

The individual generating the patch has to strip these additional lines to make a viable patch file.

External resources

 * How to write clean patches when not using git-format-patch.
 * base.eclass - Describes how ebuilds should use PATCHES=( "${FILESDIR}/mypatch.patch" "${FILESDIR}/patches_folder/" )