4

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.

rubyprince
  • 17,559
  • 11
  • 64
  • 104
  • 2
    You seemed to have pointed it out yourself. Why not use a file pattern with `--exclude`? Something like: `git apply patch --exclude=[cde]\.rb`. – miqh Oct 09 '19 at 23:32
  • @miqh My files are complex than that. It will be more like `xqwxwqxwq.rb`, `kiloili.rb`, `errere.rb`. I am not familiar with patterns. – rubyprince Oct 09 '19 at 23:40
  • 3
    Note you can specify `--exclude` multiple times to avoid having to come up with a pattern that covers all file paths you'd like to include. That is: `git apply patch --exclude=donotwantthisfile.rb --exclude=nordoiwantthisfile.rb`. Conversely, if you want to flip the problem around, you can also use `--include` multiple times. – miqh Oct 10 '19 at 00:01
  • 2
    Unless this has to be automated, I'd fire up a text editor over the patch and remove what I don't want. – Kaz Oct 10 '19 at 01:18
  • @Kaz Ah, you mean editing the patch file, that is also a good option. Didnt realize patch file was just a text file. – rubyprince Oct 10 '19 at 03:12
  • @miqh, would you please add example, how to exclude whole dir or dirs? Thank you! – Dom Oct 09 '22 at 11:18

0 Answers0