Applying a Patch Manually; Making a Drupal patch with Git (also covers applying) HowTo: How to apply a patch to a contributed module - Beginner's version (Windows) Apply Patches on Windows (more methods) Apply patches on Mac OS; How to apply patches for Drupal modules and files. This lesson takes a look at applying a patch from Drupal.org to your local copy of a module or Drupal core using Git. Afterwards we'll look at how you can create your own patches, using git diff and git format-patch, in order to contribute code back to Drupal or any of the module's on Drupal.org.
I'm trying to apply a patch that includes binary files with git apply
but only the files are added. I tried running git apply failing.patch -v
and it prints something like:
- Applying a patch manually. You could use a patch program to apply a patch, but you do not need to. Doing it manually is perfectly okay, and might give you a better idea of what is going on in your code. Smaller patches are easier to do than large ones, and yet, if you are careful, you can manually apply a patch regardless of the size of the patch.
- How to Patch Drupal Modules. Apply a Patch. If this is the case you may find it quicker to edit the files manually. Test a Patch.
Skipped patch 'file.txt'.
Checking patch file.bin...
Applied patch file.bin cleanly.
How can I find out what's the reason of the skip? As the current message is not very enlightening.
Iulian OnofreiIulian Onofrei3 Answers
I found out the problem by running patch -p1 < failing.patch
which printed:
can't find file to patch at input line 5
and reminded me that I was not in the root directory.
I can't understand why no one had asked this before and why is the verbose message not verbose.
Also, not even the official documentation mentions skipping and possible causes.
Iulian OnofreiIulian OnofreiSuffering this issue whilst attempting to port changes across projects. git apply
seems to ignore any directory names on the patch file paths, also it refuses to apply if the Index line does not match a file hash in the target repository. I had better success using these options (of which --no-index
seems to be undocumented):
Drupal 8 Patch
Got the same issue. In my case the source of error was .git
folder in some of parent directories of the patch target. The solution was to move patch target outside that parent directory.