How to Create and Apply Patches

10th October 2010

To begin with, a download a fresh copy of Drupal 6.19 and created a copy of the original file. Within the duplicate file, I made the same changes to the function that I did in earlier code, and saved the changes. Now, within my Terminal, I can navigate to Drupal's root directory and create the patch.

diff -rup modules/user/ modules/user/ > /Users/oliver/Desktop/different_messages_for_blocked_users.patch

This command compares the differences between the two files, and creates the specified patch file.

To apply the patch to my Drupal installation, I go back to Terminal and run the following code:

patch -p0 < /Users/oliver/Desktop/different_messages_for_blocked_users.patch

If, for some reason, I need to reverse the patch, I can run this code:

patch -p0 -R < /Users/oliver/Desktop/different_messages_for_blocked_users.patch

And that's it!

There is also a Git patch creation workflow, which is described at Thanks to Randy Fay for making me aware of this, and suggesting a slight change to my original patch creation command.

About the Author

Picture of Oliver

Oliver Davies is a Web Developer, System Administrator and Drupal specialist based in the UK. He is a Senior Developer at Microserve and also provides freelance consultancy services for Drupal websites, PHP applications and Linux servers.

Drupal Association Individual Member
Acquia Certified Developer - Drupal 8 Exam Badge
Acquia Certified Back End Specialist - Drupal 8 Exam Badge


  • Currently have limited part-time capacity
  • Currently no spare full-time capacity.