I'm looking for a way to ignore files in git that have a certain path in their file. These are XML files that are all stored together, but some reference folders that are in .gitignore. I want to exclude the XML files that reference these folders.
Is this possible purely with .gitignore? I can imagine other ways to achieve this, like force keeping these files with a script, but that would not be favorable.
No, Git doesn't allow you to ignore files based on their contents. That would involve reading every file in your working tree to determine whether it had a particular string, and in many cases, you can have a large number of large generated files, so such an operation would be extremely expensive. One of the goals of .gitignore
is to improve performance by not considering files which aren't interesting.
You'll need to adopt another solution, such as putting those files in a single folder or naming them with a certain convention so that you can ignore them with a path-based pattern.