Apply patch to specified file, completely ignoring the path/filename stored in the patch file

patch

I need to apply a patch to a file in a complicated directory and symlink scenario. No matter what I try, I can't figure out how to massage the patch arguments so that it would find the desired file. Is there a way to completely circumvent the problem and just EXPLICITLY TELL patch to which file it should apply the patch, ignoring the path/filename in the .patch file?

Best Answer

If the patch only contains changes to a single file, you should be able to tell patch to apply those changes to a file of your choice by specifying it before the patch name:

patch myfile withthis.patch

will apply withthis.patch to myfile, ignoring the file name in the patch.

Quoting the man page:

The names of the files to be patched are usually taken from the patch file, but if there's just one file to be patched it can be specified on the command line as originalfile.

Related Question