我可以在 .gitignore 文件中包含其他 .gitignore 文件吗? (就像类 C 语言中的 #include 一样)

2024-02-19

我有一些文件,例如vim.gitignore, SVN.gitignore and CVS.gitignore(散布在我的硬盘上)。

我可以简单地将这些 gitignore 文件包含在.gitignore文件在新的 Git 项目中吗?

Edit:我已经有一个全局忽略文件。
我只想忽略不同类型项目中的不同文件,这可能吗?


你可以:

  • Have a template repo with:
    • those xxx.gitignore里面的文件:
    • a .gitignore文件与“xxx-gitignore-xxx“ 其中(换句话说,带有content你可以轻松识别
    • a .gitattribute过滤器驱动程序 https://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs/2316728#2316728

(对于每个新的存储库,您可以克隆它并可以从已有的文件开始。
然后你删除遥控器'origin',或者将其替换为您想要推送到的任何远程存储库)

smudge content filter
(image shown in "Customizing Git - Git Attributes https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion", from "Pro Git book http://git-scm.com/book/en/v2/")

在您的存储库的任何结帐时,过滤器驱动程序将通过smudge script:

  • 认识到content of the .gitignore file
  • 检查是否xxx.gitignore内容尚不存在(通过查找只有这些文件具有的特定字符串)
  • 如果它们的内容不存在,它将附加这些内容xxx.gitignore files
  • 如果内容已经是最新的,则不会修改.gitignore.

请注意,有一个可识别的内容是这里的关键,因为过滤器驱动程序脚本没有它过滤的文件的名称/路径 https://stackoverflow.com/questions/2059326/git-equivalent-of-subversions-url-keyword-expansion/2059393#2059393.

它有点复杂,但似乎是实现您想要的“包含”功能的唯一方法。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我可以在 .gitignore 文件中包含其他 .gitignore 文件吗? (就像类 C 语言中的 #include 一样) 的相关文章

随机推荐