0

I need to add a giant directory tree to git. Some of its sub-directories are already in git repos. How can I ignore these directories?

The tree has thousands of directories, dozens of them already have their own repo. I can, for example, write a script to scan the tree and add those directories to .gitignore. I'm just trying to find out if there is a gitish way to ignore such directories during initial git add run.

jackhab
  • 17,128
  • 37
  • 99
  • 136
  • Git doesn't track, nor ignore, directories. Instead it looks at the paths of files. If you want a directory ignored, put it in the `.gitignore` file. – evolutionxbox Dec 07 '21 at 11:19
  • Does that help? https://stackoverflow.com/questions/1274057/how-can-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitign – Max Dec 07 '21 at 11:20
  • may git-submodules can help here: https://git-scm.com/book/en/v2/Git-Tools-Submodules – caramba Dec 07 '21 at 11:20
  • Does this answer your question? [How can I make Git "forget" about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-can-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitign) – evolutionxbox Dec 07 '21 at 11:21
  • @evolutionxbox The tree has thousands of directories, dozens of them already have their own repo. I can, for example, write a script to scan the tree and add those directories to .gitignore. I'm just trying to find out if there is a gitish way to ignore such directories during initial `git add` run. – jackhab Dec 07 '21 at 11:40
  • 1
    Git is *supposed* to ignore these by default. There is a bug in some versions of Git that sometimes doesn't, but in general, you don't have to do anything. – torek Dec 07 '21 at 12:52
  • Does this answer your question? [Nested Git repositories?](https://stackoverflow.com/questions/1871282/nested-git-repositories) – Inigo Dec 07 '21 at 13:39
  • @torek Nope, the directory was added with a hint recommending me to remove it and add as a submodule. – jackhab Dec 07 '21 at 13:53
  • 1
    Sure: that's the bug. It is not supposed to do that. You can fix things up post-add with `git ls-files --stage | grep ^160000 | cut -f2 > /tmp/list-of-submodules` - check the list and then `git rm -f $(cat /tmp/list-of-submodules)`. – torek Dec 07 '21 at 14:10
  • (You can also then add the list of submodules to `.gitignore` if/as desired.) It looks like the bug has been around for quite a while at this point (maybe forever?), but it might get fixed in the next release. – torek Dec 07 '21 at 14:10

0 Answers0