Creating a patch

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

Creating a patch
A source code patch for an existing package can easily be created using git (see article for installation instructions).

Unpack the package to be patched using the command:

Step into the package directory which was created inside :


 * Initialize a git repository&#58;:In case the unpacked turns out to be a git directory, skipp 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!

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:

When changes are done, have git output the diff, and tee 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/" )