Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply patch, exclude a specific folder

I have a patch file for some software (Magento) and want to apply it to my current project.

The patch file contains also references to files in the var/packages folder which I do not want (I deleted this folder in my installation).

When applying this patch file (patch -p1 < the.patch), I get lots of warnings like:

The next patch would delete the file var/package/Foo_Bar.1.7.0.0.xml,
which does not exist!  Assume -R? [n] ^C

Is there any way to tell the patch command to just ignore patches for this folder?

like image 994
Alex Avatar asked Sep 17 '25 14:09

Alex


2 Answers

You can use the “filterdiff” utility – http://man.cx/filterdiff – from http://packages.debian.org/patchutils to do that.

Otherwise, just pressing Enter a lot will also help ;-)

like image 185
mirabilos Avatar answered Sep 21 '25 04:09

mirabilos


You can use filterdiff from the patchutils package.

-x *PATTERN*, --exclude=*PATTERN*

Exclude files matching PATTERN. All other lines in the input are displayed.

So for your example

filterdiff -p1 -x 'var/packages/*' < the.patch | patch -p1

Alternatively you can manually edit the patch to remove the unwanted files, but this make take some time if it's very large.

like image 29
OrangeDog Avatar answered Sep 21 '25 06:09

OrangeDog