Last updated February 14, 2015.

You can use a patch program to apply a patch, but you don't need to. Doing it manually is perfectly ok for smaller patches, and gives you a better idea of what's going on in your code.

As said in the main article, don't patch your live site directly! Instead, patch your test site, test it, then upload the changes.


The given patch could begin with something like this,

diff --git a/modules/system/ b/modules/system/
index fb0664a..193c475 100644
--- a/modules/system/
+++ b/modules/system/

This tells you which file you need to edit: modules/system/

@@ -911,12 +911,6 @@
  * Array sorting callback; sorts modules or themes by their name.
function system_sort_themes($a, $b) {
-  if ($a->is_default) {
-    return -1;
-  }
-  if ($b->is_default) {
-    return 1;
-  }
+ // added a comment
   return strcasecmp($a->info['name'], $b->info['name']);

Here is the first snippet that you need to change.
911,12 is the line number and number of lines of the snippet before the patch is applied.
911,6 is the line number and number of lines of the snippet after the patch is applied.
  • Lines beginning with "-" are deleted.
  • Lines beginning with "+" are added (without the "+", of course).
  • Lines beginning with nothing remain as they are. Their only purpose is to give you an idea where you are in the code.

Please note: If you want to be able to revert the patch with an automated tool at a later time, you should be careful that you don't insert additional linebreaks or comments.

On the other hand, you might want to mark the modifications with comments, to find them later on.

Finding modified code

If your code is checked out from git, you can use git to view the modifications.

Otherwise, you can download a clean copy of Drupal + contributed modules into a separate folder, and use a diff tool like WinMerge to compare at windows the clean download with your modified code. You can find same alternatives for WinMerge for linux in linuxalt and alternativeto, and for Mac here.


amysragbag’s picture

I am completely new to looking at code, so I'm still a little puzzled.

@@ -618,10 +618,6 @@ function _system_is_incompatible(&$incom

So this says to delete line 618 and replace it with something. What do you replace it with? What do the ,10 and ,6 mean?

What does it mean when the lines in the patch look like:

Where can I find more detailed instructions to read?


kidconcept’s picture

If you are new to looking at code, applying a patch manually is more work than you need to take on. I imagine you are likely to do more harm than good. There is an excellent beginners guide to patching written up here:

eorr’s picture

These numbers are just pre-patch and post-patch line numbers. The minus and plus signs mean pre-patch and post-patch respectively. They don't have anything to do with deleting or adding lines, as they do outside of the @@ symbols.

The first number, -618,10, is the initial line number before the patch is applied. So the code referenced just after the 2nd @@ would start on line #618. 10 refers to the number of lines in the section prior to patching.

The 2nd number, +618,6 is the initial line number after the patch is applied. So in this case, function_system_is_incompatible would start on line 618 after the patch is applied. There would be only 6 lines of code in this section after patched as opposed to the original 10. As more functions are changed in a single patch, the gap between the pre-patch line # and the post-patch line # gets bigger.

donquixote’s picture

added an explanation in the article.

purplekitty’s picture

Thank you for these clear instructions with example! I successfully applied a patch manually for the first time!

Kebz’s picture

YAY!! My first time applying a patch... LOL

I've been a drupalgrammer for over a decade and I change/edit codes and themes quite frequently.... but I've never had to apply a patch.
I'm providing a "before & after" sample below to hopefully help others to understand it better. This worked for me and I now have a "green" status report... yay!!

This sample below is for the CURRENCY / TOKEN (in reference to this link > which I will post inside there too.

BEFORE: starting @ line 33, with 10 lines of code (re: -33,10)
starting @ line 33, remove the following code that equals to 10 lines total

33 'type' => 'text',
34 );
35 $tokens['currency']['sign'] = array(
36 'name' => t('Sign'),
37 'type' => 'text',
38 );
39 $tokens['currency']['title'] = array(
40 'name' => t('Name'),
41 'type' => 'text',
42 );

AFTER: starting @ line 33, with 12 lines of code (re: +33,12)
starting @ line 33, paste the following code that equals to 12 lines total

33 'type' => 'text',
34 );
35 $tokens['currency']['sign'] = array(
36 'description' => t('The sign of the currency.'),
37 'name' => t('Sign'),
38 'type' => 'text',
39 );
40 $tokens['currency']['title'] = array(
41 'description' => t('The name of the currency.'),
42 'name' => t('Name'),
43 'type' => 'text',
44 );

The actual patch file ( reads as follows: (Be sure to remove the "+" sign before saving and uploading back up into the server.... and ALWAYS make a copy FIRST before making any changes to any files you tinker with. :) )

diff --git a/currency/ b/currency/
index 4587a87..0ac2964 100644
--- a/currency/
+++ b/currency/
@@ -33,10 +33,12 @@ function currency_token_info() {
'type' => 'text',
$tokens['currency']['sign'] = array(
+ 'description' => t('The sign of the currency.'),
'name' => t('Sign'),
'type' => 'text',
$tokens['currency']['title'] = array(
+ 'description' => t('The name of the currency.'),
'name' => t('Name'),
'type' => 'text',


corry’s picture

thank you kebz.Worked perfectly

dfish17’s picture

Yikes, I just tried to apply a patch manually and am getting the following error. I tried to do a full restore of home directory and database and am still getting the error. I'm thinking I had an extra line break in there, but it's still giving me the error after restoring.

Parse error: syntax error, unexpected end of file in /home/karenl12/public_html/sites/all/modules/field_collection/field_collection.module on line 1510