6

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?

2
  • I'm not sure if there's a way to do with with patch options, but can you just edit the patch file instead? – Sparhawk Feb 1 '19 at 8:46
  • Last resort. This is an automated build scenario where the patch is downloaded from the web, so I would have to either script the editing (cp, sed, patch, rm), or... patch the patch, which is silly. – Szczepan Hołyszewski Feb 1 '19 at 9:04
11

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.

1

If the patch applies to only one file you could simply, put a symlink in that location pointing at the file you want it to be applied to. (assuming that the reason you need it applied else-ware is because that file does not exist) Then just apply the patch.

Even if it pointed at multiple files, it could be done this way, with more time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.