Last updated 25 February 2016.
git apply is working normally, you get no output at all:
$ git apply example.patch [nothing returned]
If you want to see what's going on behind the scenes, you can use the
-v (verbose) flag:
$ git apply -v example.patch Checking patch includes/common.inc... Applied patch includes/common.inc cleanly.
However, if running git apply from within your own local git working copy, it's possible that even with the
-v (verbose) flag, git apply will do nothing, and give no output. If this happens, please check your location in the directory tree -
git apply may work from another location.
Patches to contributed modules and themes often indicate that a project's directory is also the root of the repository directory tree. On the first line of the patch you will see something like:
diff --git a/includes/common.inc b/includes/common.inc
Here the directory structure does not include the Drupal root. In this situation, initialize a new repository in the project directory to get the patch to apply:
An alternative to
git apply is to use the
$ patch -p1 < example.patch
Here is other output the
git apply command can generate, and what it means.
Patch does not apply
$ git apply example.patch error: patch failed: includes/common.inc:626 error: includes/common.inc: patch does not apply
Git couldn't apply the changes in the patch because it wasn't able to find the line(s) of code in question; they must have been changed or removed by another commit. Try these things:
- Make sure the patch hasn't already been applied. Look for it in
git logor simply examine the code to see if the change(s) are already present. If they are, you're done. If they aren't or if only some of them are, try something else:
patch -p1 < filename.patch. Whereas
git applyaltogether rejects a patch with any errors,
patch -p1works hunk by hunk, applying as many individual changes as it can. It backs up each file as
filename.ext.origbefore modifying it and saves rejected hunks in
filename.ext.rej. Discard the
.origfiles and manually apply the changes left in the
.rej. This is an easy strategy for small patches. For more sweeping changes, you might want to consider an alternative:
- Re-roll the patch with Git. Read a detailed tutorial at Re-roll patches to apply cleanly to the latest version of Drupal.