fowlball1010
fowlball1010

Reputation: 383

Parent gitignore to ignore any subdirectory gitignore files

Is there a way through a .gitignore file (or some way through git version control) to ignore the effects of .gitignore files in subdirectories? The particular use case is that I'm copying open source folders into my git repo, and those open source folders have their own .gitignore files that I would like to ignore. I don't want to go through the process of manually deleting them because any time I bring the latest source folder over I'd have to remember/automate/etc. removing those files. Rather, I'd like to be able to have a folder structure like below:

file1.c
.gitignore
module1/
  src1.c
  .gitignore
  ...
module2/
  src2.c
  .gitignore
  ...

Where the root .gitignore is applied, but all .gitignore's in the module folders are ignored. It's not a problem if they're committed to source control. But the goal is to ignore the impacts of the contents of those .gitignore files in the overall directory.

Upvotes: 0

Views: 216

Answers (1)

torek
torek

Reputation: 489508

You cannot do this through .gitignore files, because they have a hierarchy / priority system where the "inner" .gitignore overrides any instructions from the "outer" .gitignore. Hence even if you add outer .gitignore negations:

!inner/foo

to try to stop inner/.gitignore from listing inner/foo, it doesn't do it.

You can, however, do this through .git/info/excludes, as it has higher priority than any .gitignore. The .git/info/excludes file is never committed so you'll have to store the data elsewhere (e.g., in a file that is committed) and then copy it into place in each clone you make.

I don't know your real ultimate goal, but this smells like an XY problem.

Upvotes: 1

Related Questions