How can I tell Git to use a different gitignore file than “.gitignore”?

白昼怎懂夜的黑 提交于 2019-12-01 20:27:17
Srikanth Venugopalan

You can use core.excludesfile to specify the new ignore file. By default this will only affect the current repository; you can use the --global option if you want to change the default value.

git config core.excludesfile ".new_gitignore"

Edit 1

AFAIK, .gitignore cannot be disabled. And it takes precedence over .git/info/excludes and core.excludesfile. The only way I can think of is having some hacks using filters. This answer explains the use of filters well.

Each repository has an info/exclude file - there should be one in .git/info/exclude and in .git.sync/info/exclude. Populate those exclude files just as you would .gitignore.

".gitignore" seems to be hard-coded as a per-directory exclude file in git in most commands, taking precedence over all other ignore files.

However, I created a small patch for Git to overcome this limitation: https://gist.github.com/rev22/9954517

It adds the following configuration option:

core.ignoreperdir: Specify an alternative to '.gitignore' as a per-directory exclude-file. If this is not set, the default '.gitignore' is used. If this is empty, no per-directory exclude file is used.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!