Windows – How to apply a diff patch on Windows

diff()gnupatchwindows

There are plenty of programs out there that can create a diff patch, but I'm having a heck of a time trying to apply one. I'm trying to distribute a patch, and I got a question from a user about how to apply it. So I tried to figure it out on my own and found out that I have no clue, and most of the tools I can find are command-line. (I can handle a command line, but a lot of people would be lost without a nice, friendly GUI. So those are no good for this purpose.)

I tried using TortoiseSVN. I have the patch I'd like to apply. I right-click on the patch, and there's an option under the TortoiseSVN submenu that says "Apply patch." All it does is pull up an empty window.

So I tried hitting Open. It has two options: merge and apply unified diff. (The patch is in unified diff format, luckily.) But the apply option just plain doesn't work: It asks for the patch and a folder. Somehow it forgot to ask for the file to apply the patch to! So TortoiseSVN just plain doesn't work. Is there a Windows GUI-based utility that will take a patch and a file and apply it properly?

EDIT: Looking at the replies so far, it seems that Tortoise will only do it right if it's a file that's already versioned. That's not the case here. I need to be able to apply a patch to a file that did not come out of an SVN repository. I just tried using Tortoise, because I happen to know that SVN uses diffs and has to know how to both create them and apply them.

Best Answer

Apply Patch

With TortoiseMerge:

  1. Find and open an existing SVN repo directory
  2. Create a new directory named "merges", if it does not exist already
  3. Copy the file onto which you want to apply the .patch file
  4. ADD and COMMIT to the svn repository before you continue to the next step
  5. Right click on merges and choose Apply patch...
  6. Double click the file from list
  7. The patched file with diff is displayed on the right pane
  8. Click on that pane and hit Save or export with File->Save As...

Alternative screeny if you Open from TortoiseMerge. In the screeny below, directory refers to the "merges" directory mentioned at step 2 above: Screeny

Screenshot of WinMerge GUI: Screeny