The trick is: a nested repository whole content is ignored by a parent repository.
In the OP's question, no *.iml
file would be tracked by the root-level repository, because of the .git
subfolder in proj1
and proj2
.
But, assuming that proj1/2 content was actually tracked by the parent repository (git subtree, git subrepo), the .gitignore
patterns application rules are clear:
Patterns read from a .gitignore
file in the same directory as the path, or in any parent directory (up to the top-level of the working tree), with patterns in the higher level files being overridden by those in lower level files down to the directory containing the file.
So:
I only want git to recognize the rules of the root .gitignore
.
That would means a git wrapper script which would:
- delete the
projx/.gitignore
- add everything
- restore the deleted
.gitignore
files
The OP adds in the comments:
Can you setup git to automatically run a "wrapper script"?
Yes: you just define an alias for git
(even on Windows, with doskey
), which calls your own script.
If I can automatically run a wrappper script on commit that renames the .gitignore
b4 commit, it would solve this issue I am having.
You would need a pre-commit hook which would first modify the index by registering in it empty blob for the nested .gitignore
(meaning they are not removed, just emptied). Example here.
A post-commit hook can restore the content of those .gitignore
.