Thursday, October 19, 2017 08:54 am EDT

How to Patch a Drupal Module on Windows

Bri's picture

If you use Drupal on a regular basis, chances are that you will want to apply a patch to a module at some point in time. Perhaps somebody has posted a patch in the issue queue that sounds like it will address a problem you are having. Patching files on windows is simple. Just follow these steps.

1. You will need to download the patch software. You can download the Patch program at http://gnuwin32.sourceforge.net/packages/patch.htm

2. Run the setup file and install the program using all of the default settings.

3. Get a local copy of the file you wish to patch. Either pull down the file from your web server using an FTP client, or just download the module form the drupal project page.

4. Open up a windows command prompt by going to Start->Run and typing "cmd" and hitting enter.

5. Change directories to the GNU Patch program directory using the command prompt by typing the command "cd C:\Program Files\GnuWin32\bin" (no quotes)

6. Place the file that needs patching inside this same folder. For example, if you wish to patch the file views.module, place this file inside the folder at C:/Program Files/GnuWin32/bin

7. Using the command prompt, type the command "patch < NameOfThePatchFileYouDownloaded --binary" (no quotes). For example, if the patch file you have downloaded is named "edit_form.patch" you would give the command "patch < edit_form.patch --binary" but without the quotes. The --binary can be very important on a windows machine. On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given.

8. Once the file is patched you may upload it for testing.

Comments

Anonymous's picture

Great

Thanks Bro, you Rock

Anonymous's picture

Time waste

Time waste "Patch is not a command error"

Anonymous's picture

Finally

Thank you!

Anonymous's picture

Thanks a million

Thanks it worked with --binary

You saved my life!

Anonymous's picture

Thanks it easy patch with

Thanks it easy patch with this, but it ask what file to patch for this issue:
http://drupal.org/node/1179034

Could you point me how to patch this issue

Anonymous's picture

Thank You

You have no idea how helpful this was: thank you. I was beginning to think all hope was lost. (Downloaded all sorts: cywgin, UnxUtils, GNUWin32 and couldn't get anything to work because I found most of the documentation hard to follow. Yours was the easiest: thanks.

Anonymous's picture

very useful

that was very useful,, thanks ya man :)

Anonymous's picture

Thanks

Thank you very much for this very easy to follow article.

Anonymous's picture

Run cmd.exe as administrator

Be sure you run cmd.exe as an adminstrator to apply a patch successfully. Took me hours to figure this out -.-

Bri's picture

Good point

Good point, I had not thought of that cause i'm an administrator on all my installations. Thanks for the heads up.

Anonymous's picture

Thanks

Thank you very much for this article. it helped me patching the views module. on my site

electronics notes

Anonymous's picture

Great

great tutorial. you saved my day :)

Anonymous's picture

Thanks man! this article is

Thanks man! this article is very create and detailed.

Anonymous's picture

error message

Thanks - but I keep getting a balk. Specifically, the error message says "Perhaps you should have used the -p or --strip option?" Any help would be much appreciated - Keith

Anonymous's picture

I, too, am receiving the

I, too, am receiving the "perhaps you should have..." error message. How can I avoid that?