Articles, Expert to expert

How to create a patch for a Drupal module

By Wunderer

First, make sure your issue is not already reported by someone else in the issue queue for the module. Also, check out the latest dev version of the module, is the issue resolved there? If all statements above equal FALSE let’s make a patch:

  1. Start the terminal and download the module to your test environment with Drush.
    drush dl [module-name]
  2. Enter the directory and initialize an empty repository
    cd [module-name]
    git init
  3. Add the files to your repository
    git add *
  4. Commit the files to the repository
  5. git commit -m ‘Initial commit’
  6. Make your awesome changes to the file you want to change.
  7. Commit your changes to git
    git commit -m ‘Description what you’ve changed’
  8. Start Giggle, at the bottom right of the application window you will find a button named Details, click this then click on your initial commit and copy the SHA-tag (looks something like this: 325449643c76dbeade12033d8304f447e53742d9)
    Click on your next commit and copy the SHA-tag from that.
  9. Enter the terminal and execute the command: git diff –no-prefix [original-SHA] [patched-SHA] > my-patchfile.patch
  10. File an issue at the project page for the module you have patched and mark the issue as needs review. Make sure you select the correct version for the module. If available, post a screenshot of the problem and the solution.