Creating and testing SVN patches using GitHub

Creating patch

A patch is a small piece of code that can be applied to fix a bug or add a new feature.

We will be creating an SVN patch from github, as we have setup WordPress development from GitHub

Step 1: Create a new feature branch from the master

  • Creating a branch is required in case the patch has changes in multiple files, it will come in handy for code review. You can create a pull request and share the link in your ticket. But all changes still need to be sent by creating a patch and changes will be committed through SVN
git checkout master -b some-feature/123

Step 2: Commit changes

  • Now, make the code changes you need to make and commit them (you can do several commits; it doesn’t matter):
// edit files

git commit -am "fixed the bug"

//edit more files

git commit -am "fixed edge case"

Step 3: Generate the patch

  • You can generate an svn-compatible patch directly from git as follow
git diff master --no-prefix > ~/Downloads/123.diff

The –no-prefix flag is added so the patch does not show any source or destination prefix

Testing the patch

In case you want to test a patch created by another download the .diff file from the ticket, use the following command

patch -p0 < ~/downloads/3124.diff

Once the patch is tested you can stash the changes by GitHub and pull the master for the latest changes, rebuild WordPress..on to the next ticket