Actually, it's patch < the_patch
or cat the_patch | patch
.
You may need to use the -p<n>
option which is used to strip off segments of the pathnames stored in the patch. For example, if the patch was created from one level above the source tree (like you were diffing one tree against another) and you want to apply the patch from within the source tree, you would need -p
.
Another useful option is --dry-run
. That will act like it's applying the patch, but won't modify any files. It's a good thing to use to test if you have the -p
option correct and to see if the
patch will apply cleanly.
What I normally do is change to the root of the source tree and then run cat <file> | patch -p1 --dry-run
. If I get errors about files not being found, I'll switch to -p0
. Once either of those works, I remove the --dry-run
and do it for real.