10

I have found an issue on drupal.org that I would like to submit an solution for. How can I create a patch using git so that I can submit it as a possible fix?

13

Every Drupal.org project has a tab title 'Version control', click on it and it will take you to a page with Git instructions, including a section titled 'Creating a patch'.

See here for an example: http://drupal.org/project/wysiwyg_fields/git-instructions

Code below is copied from the D.o. instructions.

git checkout -b [description]-[issue-number]

Make your changes. Note the change in syntax for issue-related commit messages. See the Commit messages page for details.

git add -A
git commit -m "Issue #[issue number] by [comma-separated usernames]: [Short summary of the change]."

Roll the patch.

git status
git fetch origin
git rebase origin/6.x-1.x
git format-patch origin/6.x-1.x --stdout > [description]-[issue-number]-[comment-number].patch
0

If you use PhpStorm or IntelliJ you can do the following:

  • Make sure your branch is up-to-date (commit everything)
  • Make the changes (fix the bug)
  • Go to VCS > Create patch

    Go to VCS > Create patch

  • Follow the steps and save where you prefer it.

    Follow the steps and save where you prefer it

0

I wouldn't overcomplicate things. In the end all you really need is a dev version of the module, init an empty Git repo in it, clean the working tree (commit everything, it's just locally), make your changes and then run the following command.

$ git diff > [short_description]-[issue-number]-[comment-number].patch

In a steb-by-step that maybe boils down to the following.

  1. Have a local Drupal running you can mess around with.
  2. Download a dev version of the module into your local Drupal's contrib modules folder.
  3. Now cd into the module's directory and git init, then git add . and git commit -m "Clean tree" to have a clean state to start from.
  4. Do your code changes, and use the local Drupal to check if everything's working and in the end run the git diff command from above.
  5. Upload the patch on drupal.org and set the issue to "Needs review".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.