Skip to content

Instantly share code, notes, and snippets.

@anandkkpr
Last active December 30, 2015 07:59
Show Gist options
  • Save anandkkpr/7799523 to your computer and use it in GitHub Desktop.
Save anandkkpr/7799523 to your computer and use it in GitHub Desktop.
A full and verbose description of how to create patches and interdiffs for submission to the Drupal issue queue.

Drupal Patch Strategy:

Patches

  1. make changes then make patch BEFORE COMMITTING CHANGES
  • $ git diff > [project-name]-[project-version].[description].[issue-number]-[comment-number].patch
  • doesn't work when adding or deleting files
  1. you've made changes that INCLUDE adding/deleting files, BUT NOT COMMITTED
  • $ git [add|rm] ...
  • $ git diff --staged > [project-name]-[project-version].[description].[issue-number]-[comment-number].patch
  1. you've made your changes AND YOU'VE COMMITTED the new changes AND there's ONLY BEEN ONE COMMIT (from base state to new state)
  • get the commit-hash if you don't have it already
    • $ echo $(git log --format=%H -n1)
  • $ git show COMMIT_HASH > [project-name]-[project-version].[description].[issue-number]-[comment-number].patch
  1. you need to create a patch between two specific commits in the same branch (because you've made many commits between the base state and end state)
  • get the commit-hashes you're comparing
  • $ git show OLD_COMMIT_HASH..NEW_COMMIT_HASH > [project-name]-[project-version].[description].[issue-number]-[comment-number].patch
  1. if you've made your changes to a branch; i.e. you've cloned, checked out the branch/tag that needs to be patched and then created a branch based off the HEAD of that branch
  • $ git diff ORG_BRANCH_NAME > [project-name]-[project-version].[description].[issue-number]-[comment-number].patch

Interdiff

  1. checkout the branch that needs patching (and has a pre-existing patch) (has an issue logged against it)
  • $ git clone GIT_URL --branch 8.x
  1. create a new branch based off of the HEAD of the one you checked out
  • $ git checkout -b ISSUEID-COMMENTID
  1. apply the old patch and commit it
  • $ git apply --index old_patch.patch && git commit -m "old patch"
  1. create a new branch to make your changes to
  • $ git checkout -b new_patch
  1. hackity hack
  2. commit the changes you've just made as many times as you need to... work until you're satisfied
  • $ git commit -m "new patch"
  1. generate the new patch file to submit; this will include all the previous changes that were submitted PLUS those you've made too
  • $ git diff 8.x > patch.patch
  1. generate the interdiff, you'll be running the diff off of the original branch you made in step 2. (BEFORE applying the pre-existing patch)
  • $ git diff ISSUEID-COMMENTID > interdiff.txt

Credits: Big, big thanks to @mparker17!!! :o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment