我可以在.gitignore文件中包含其他.gitignore文件吗? (就像类似c语言的#include) [英] Can I include other .gitignore file in a .gitignore file? (like #include in c-like languages)

查看:108
本文介绍了我可以在.gitignore文件中包含其他.gitignore文件吗? (就像类似c语言的#include)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件,比如 vim.gitignore SVN.gitignore CVS。



我可以简单地将这些gitignore文件包含在 .gitignore / code>文件在一个新的Git项目中?



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


  • 有一个模板回购:


    • 其中的xxx.gitignore文件:

    • 一个带有 xxx-gitignore-xxx 的.gitignore文件(换言之,内容为 您可以轻松识别



      这有点复杂,但似乎是实现所需包含功能的唯一方法。


      I have some files like vim.gitignore, SVN.gitignore and CVS.gitignore (spread around on my hard disk).

      Can I simply include these gitignore files in a .gitignore file in a new Git project?

      Edit: I have a global ignore file already.
      I just want to ignore different files in different types of projects, is this possible?

      解决方案

      You could:

      • Have a template repo with:
        • those xxx.gitignore files in it:
        • a .gitignore file with "xxx-gitignore-xxx" in it (in other word, with a content you can easily identify
        • a .gitattribute filter driver

      (for each new repo, you clone it and can start with those files already there.
      Then you remove the remote 'origin' or replace it by whatever remote repo you want to push to)

      On any checkout of your repo, the filter driver will, through the smudge script:

      • recognize the content of the .gitignore file
      • check if the xxx.gitignore content isn't already there (by looking for a specific string which only those files have)
      • if their content isn't there, it will append the content of those xxx.gitignore files
      • if the content is already up-to-date, it wouldn't modify the .gitignore.

      Note that having a identifiable content is key here, since a filter driver script doesn't have the name/path of the file it filters.

      It is a bit convoluted, but seems to be the only way to implement the "include" feature you want.

      这篇关于我可以在.gitignore文件中包含其他.gitignore文件吗? (就像类似c语言的#include)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆