I wanted to track some files ignored by a bunch of repos into a single repo.
Here's an example layout:
.
+-- .git
+-- .idea
|-- .gitignore
|-- proj1
| +-- .git
| |-- .gitignore
| |-- foo
| | |-- foo.iml
| |-- bar.c
| |-- proj1.iml
|-- proj2
+-- .git
|-- .gitignore
+-- bar
|-- foo.c
|-- proj2.iml
I want:
Any solution?
The title of the question and the detailed description seem to ask slightly different questions...
With regards to the title of the question: to exclude nested .gitignore files, but not the root .gitignore itself, add the following line to your root .gitignore file:
*/**/.gitignore
(this will only ignore those .gitignore files that are nested at least one folder level deep)
Alternatively, if you only want to ignore .gitignore files in direct child folders, but still want to include all .gitignore files in indirect (i.e., 2nd level, 3rd level,...) sub-folders use:
*/.gitignore
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:
projx/.gitignore
.gitignore
filesThe 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With