git apply patch exclude 2 files

6.9k Views Asked by At

How do you git apply patch but exclude 2 files? For 1 file or file pattern you could do --exclude flag. But what if I have 2 different files a.rb and b.rb I need to exclude but I have c.rb, d.rb, e.rb also in the patch which needs to be applied.

2

There are 2 best solutions below

1
Suyash More On

This could help

git apply -v mypatch.patch --exclude={file1.txt, file2.json}
0
cglacet On

You can exclude several <path> patterns using several --exclude flags:

git apply 2024_update.patch --exclude=a.rb --exclude=b.rb

Notice that if you are using the --directory flag, you need to exclude the path rewrite destination file not the original file path, for example:

git apply 2024_update.patch --directory='package/'\
  --exclude=package/a.rb\
  --exclude=package/b.rb

If you need to exclude a whole subdirectory dir/ you can use:

git apply 2024_update.patch --exclude="dir/*"

Similarly to files, you can exclude several directories and you should also use the destination path package/dir/* in this example.