我可以在.gitignore文件中包含其他.gitignore文件吗? (就像类似c语言的#include) [英] Can I include other .gitignore file in a .gitignore file? (like #include in c-like languages)
问题描述
我有一些文件,比如 vim.gitignore
, SVN.gitignore
和 CVS。
我可以简单地将这些gitignore文件包含在 .gitignore / code>文件在一个新的Git项目中?
编辑:我已经有一个全局忽略文件。 $ b我只想忽略不同类型的项目中的不同文件,这可能吗? >
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屋!