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. Of course for doing so, needs to be installed.

Step 1: Unpack the questionable package using the command:

Step 2: Step into the package directory which was created inside :

In case the unpacked turns out to be a git directory, steps 3 and 4 can be skipped. If not, don't skip.

Step 3: Initialize the unpacked package sources as a git repository:

Step 4: Add all the existing files to git and do a commit:

Step 5: Do the necessary changes. Change one file or even more. Of course, the needed changes should be known.

Step 6: When changes are done, let git show the diff and tee it into the patch file:

TortoiseGit and 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.

Nesting
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.

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/" )