忽略具有 .git 子目录的目录?

ignore directory which has .git subdirectory?

如果有自己的 .git 目录,我想忽略目录。

project-root
  - sub-project1 (with `.git`)
  - sub-project2 (with `.git`)
  - other files

我如何告诉(.gitignore) 忽略所有具有自己的 .git 的目录,例如 sub-project1/2?

您需要一个脚本:

  • 找到一个 .git 子文件夹
  • 获取他们的父文件夹 (dirname)
  • 将其添加到 .gitignore(如果尚未存在)
  • 将其从索引中删除(以防父存储库已将其记录为 gitlink entry