mediatribe.net -- Drupal et développement web

Notice: this post was last updated Il y a 4 years 51 weeks so it might be outdated. Please be cautious before implementing any of suggestions herein.

Creating and applying a Drupal patch with binary files

I am normally in the habit of creating my patches with the commands "git diff 123456 abcdef > patch.patch" (where 123456 and abcdef are commits); and applying the patch with "patch -p1 < patch.patch".

This works fine unless you have binary files. For example, for this issue I needed to include a new .gz file in my patch, and the above technique was causing a fail.

To create and apply patches with binary files, the following technique works to create a patch:

git diff --full-index --binary 123456 abcdef > patch.patch

And to apply the above patch, use

git apply -p1 < patch.patch

Please note that in D8 this

Please note that in D8 this won't work most of the time since the root .gitattributes enforces a text diff. You can edit the .gitattribute file temporarily and diff only the core directory as a workaround.

Thanks for the tip!

Thanks for the tip!