Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring a directory chain in git?

I need to ignore the following.

In paths like /a/b/c/d/e/f/g, I need to ignore /d/e/f/g. I also need to be able to ignore every place /d/e/f/g appears beneath a. I tried d/e/f/g, but that did not work. Thoughts?

like image 986
Stefan Kendall Avatar asked Jan 22 '23 16:01

Stefan Kendall


2 Answers

Interesting requirement. I'm curious what your use case actually is.

The way you should do something like this is a separate .gitignore in the parent directory of each sub-tree you need to exclude (git reads all the .gitignore files on its way down the tree).

If you really want a single .gitignore file... Well, I haven't tried this, but going by the gitignore doc, it's mostly a typical shell glob, so what might work is something like:

a/*/d/e/f/g
a/*/*/d/e/f/g
a/*/*/*/d/e/f/g

... repeating with an ever-increasing number of asterisks out to the deepest you expect it to reasonably go.

I imagine there will be a performance penalty here, but I don't know how serious. Probably not noticeable for most repos on any system built in the last 5-10 years.

like image 67
Nicholas Knight Avatar answered Jan 27 '23 05:01

Nicholas Knight


Try:

**/d/e/f/g

or:

a/**/d/f/g
like image 24
Jeet Avatar answered Jan 27 '23 07:01

Jeet