Overview #

This article will walk you through creating, applying, and reverting a patch using the command line.

What You Will Need Before Starting #

Top ↑

Creating A Patch #

During beta testing, you may run across a bug that you are able to fix. Before you submit the Trac ticket, however, you should create a patch with the proposed fix so you can attach it to the ticket.

Open the folder where you have WordPress installed via SVN, and find the file you need to change. Open the file in your favorite plain-text editor. Make the changes necessary to fix the bug, then save the file.

Next you will create the patch file, which records the differences between your version of the files and those from WordPress trunk. Patches should be created from the root directory of your WordPress SVN install.

To do so, ensure that you are in the root directory created by your SVN checkout (wordpress-svn), then run the following command, where 00000 is replaced with the ticket number from Trac:

$ svn diff > 00000.patch

Top ↑

Applying A Patch #

Part of the troubleshooting/testing process involves downloading and applying patches to your local WordPress trunk install from a Trac ticket that you are involved in.

To download a patch, click on the handy download icon next to the patch’s name in trac:

Download a Patch from Trac Ticket Screen

On a Mac, this will save it to your default downloads folder, from where you can move it to your chosen wordpress-svn directory. On a Windows machine, this will prompt you to save it in your chosen location, which should be the aforementioned directory.

You can also download a patch via command line. Make sure that you are in the wordpress-svn directory, then download the patch into the patches folder.

$ curl -O https://core.trac.wordpress.org/raw-attachment/ticket/00000/00000.patch

Note: If you download the patch this way, make sure that it is coming from the raw-attachment directory on the Trac server. You can get this URL by clicking on the patch in Trac, then grabbing the URL linked to by Original Format at the bottom of the page.

You will need to apply the patch from the wordpress-svn directory, where you have downloaded the patch file. Use the following command to apply the patch:

$ patch -p0 < 00000.patch

Now, the wordpress-svn code has been patched with the file you downloaded, giving you the version of the code that the developer who submitted that patch was working with.

Note: If the patch fails to apply cleanly, you will need to leave a note on the Trac ticket that the patch needs to be refreshed, and add the needs-refresh keyword to the ticket.

Top ↑

Reverting A Patch #

When you have finished testing, it is best to revert your SVN install back to the latest version of trunk, removing all applied patches and any changes you have made. You will use the following command to revert all patches/changes:

$ svn revert -R *

Top ↑

Next Steps #