mediatribe.net -- Drupal and Web Development

Notice: this post was last updated 4 years 40 weeks ago 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!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.