Monday, July 23, 2007

Using patch (as in .patch files) in WinXP

I had to apply a large set of patch files (and I mean .patch files) to a project today using a Windows XP machine. It was a lot more painful than I thought it would be so I am recording it here in case it helps anyone else avoid the pain.

You should have all your patch files in a directory (I am assuming one called patches but use anything you like, just remember to tweak the commands). You will need the patch program for windows installed (which proved to be fairly hard to find) and on your Path.

How to apply a directory full of patches with a single command in windows XP.
  1. Open a command line (Start ->Run... -> cmd) and go to the directory where you are applying the patches (should have a patches directory here also)
  2. Run the following command to test your patch syntax:
    for %f in (patches\*.patch) do type %f patch -p0 --dry-run
  3. If you got no errors then just remove the --dry-run from the end and run it again to actually apply the patches, for example:
    for %f in (patches\*.patch) do type %f patch -p0

You would not think that would have taken hours to figure out would you?

For the unix folks out there, here is the command (though I suspect most everyone knows this one already):
for patch in patches/*.patch ; do patch --dry-run -p0 < $patch ; done


You might want to go ahead and get the core GnuWin32 utilities if you want to run more unix type commands in winXP.

1 comment:

India said...

when i run my patch using your syntax it's showing error ->>

The system cannot find the file specified.
Error occurred while processing: patch.
The system cannot find the file specified.
Error occurred while processing: -p0.
The system cannot find the file specified.
Error occurred while processing: --dry-run.