Can I include other .gitignore file in a .gitignore file? (like #include in c-like languages)

前端 未结 3 1927
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 10:09

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

Can I simply include th

相关标签:
3条回答
  • 2020-12-05 10:42

    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)


    (image shown in "Customizing Git - Git Attributes", from "Pro Git book")

    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.

    0 讨论(0)
  • 2020-12-05 10:51

    The closes you will get is the global ignore file:

    git config --global core.excludesfile ~/.gitignore
    

    which is of course like having a .gitignore in the repo, but applicable to all repos on your system ( and not propagated to external clones.)

    0 讨论(0)
  • 2020-12-05 10:55

    I run the a project that hosts the largest amount of gitignore templates and it's extremely easy to use.

    • You can use the web to generate a template at https://gitignore.io
    • You can install gitignore via command line to type

      gi cvs,vim,svn
      

      output: https://www.gitignore.io/api/cvs,vim,svn

    • You can also update your existing templates using this url: https://www.gitignore.io/?templates=cvs,vim,svn

    • And finally, you can contribute to the list of templates which merges @github/gitignore and over 100 other community templates to create the largest repository of templates at: https://github.com/dvcs/gitignore

    This doesn't allow anyone to include sub-templates, but it does generate one large template from individual git templates.

    0 讨论(0)
提交回复
热议问题