Create and Apply a Patch to a Drupal Module
Category:
From a terminal...
Patching a Single File
Navigate to your module's directory that contains the changes you have made:
cd /var/www/my-website/sites/all/modules/custom/my_module
Create the patch file by running a diff on your OTHER module file and comparing it to your updated module file:
diff -ruN /var/www/my-OTHER-website/sites/all/modules/custom/my_module/my_module.module my_module.module > my_module.module.patch
Copy the patch file to the same directory as the file that needs to be patched:
cp my_module.module.patch /var/www/my-OTHER-website/sites/all/modules/custom/my_module
Navigate to the the directory where you just copied the patch file:
cd /var/www/my-OTHER-website/sites/all/modules/custom/my_module
Apply the patch and create a backup of the original:
patch -b my_module.module my_module.module.patch
If the patch is applied successfully and all looks well, you can remove both .patch files and .orig file:
rm my_module.module.patch rm my_module.orig rm /var/www/my-website/sites/all/modules/custom/my_module/my_module.module.patch
Patching a Multiple Files in a Directory
# go to home directory, e.g. /home/tyler cd ~ # create the patch file diff -ruN /home/tyler/original_directory/ /home/tyler/updated_directory/ > tyler.patch # apply the patch patch -p0 -i tyler.patch
Now venture forth to create and apply patches to save us from praise the robots, thanks.