patch — Apply a patch made by diff


patch [options]

Note that patch reads from standard input by default. This can be overridden with the -i command, but I never bother.


  • To apply a simple patch

    patch -p0 < simple.patch

  • To see what changes would be made by a patch without actually making the changes

    patch -p0 --dry-run < simple.patch

  • To remove 3 of the leading directory names in the patch

    patch -p3 < not-so-simple.patch

  • To reverse apply a bad patch

    patch -p0 -R < bad.patch