Bläul.de>

Reverting patches

In the aftermath of a Git problem at work, I wanted to revert changes in PHP source code files. I wanted to re-commit my changes, so I need to change files directly in the checkout first. I'm working under Windows.

Here's what I did:

  1. Get patch string: Luckily, Tortoise Git offers windows such as Sync, Log and many other offer a context menu item 'Show changes as unified diff'
  2. Get a bash window. I ususally right-click in Explorer and use 'Git Bash Here'.
  3. Get the patch utility to listen: typing patch -R -p 1 followed by Enter means: Wait on stdin for the patch string, ignore the first path segment (which is a informationless a/ and b/ in all repos and all files). My patch.exe comes from Cygwin, whose bin folder is on my path variable.
  4. Revers-Apply the patch: Now paste the whole unified diff from step 1. Press Ctrl + D to tell patch.exe to start working

To speed up pasting to the MingW32 (the Git Bash Here window), you can enable the Quick Edit mode from the Properties menu item. Then it will paste with a right mouse click, like in PuTTY.