我如何告诉Git使用不同于gitignore的gitignore文件? [英] How can I tell Git to use a different gitignore file than ".gitignore"?

查看:89
本文介绍了我如何告诉Git使用不同于gitignore的gitignore文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 - git-dir 来告诉Git Git存储库的位置。我可以通过 - work-tree 来告诉Git工作树在哪里。如何告诉Git gitignore文件在哪里?

I can tell Git where the Git repository is with --git-dir. I can tell Git where the working tree is with --work-tree. How do I tell Git where the gitignore file is?

Q。我为什么要做这样的事情?

Q. Why would I want to do such a thing?

A。对于一些工作树,我有两个不同的Git存储库。一个位于 .git 的标准位置。这个库用于普通的版本控制。另一个存储库位于 .git.sync 中。此库用于在计算机之间进行定期自动同步。也就是说,这是我自己使用Git实现的小型Dropbox克隆和一个定期运行的小脚本。

A. For some working trees I have two different Git repositories. One is in the standard location of .git. This repository I use for normal version control. The other respository is in .git.sync. This repository I use for periodic automatic syncing between computers. I.e., it's my own little Dropbox clone implemented with Git and a little script that runs periodically.

理想情况下,我可以告诉Git使用 .gitignore.sync 用于 .git.sync 存储库,而不是让Git使用相同的 .gitignore 它用于普通版本控制。

Ideally, I would be able to tell Git to use .gitignore.sync for the .git.sync repository, rather than having Git use the very same .gitignore that it uses for normal version control.

Q。为什么我不使用Dropbox?

Q. Why don't I just use Dropbox?

A。它不会同步符号链接。 Bad Dropbox!

A. It doesn't sync symlinks. Bad Dropbox!

推荐答案

您可以使用 core.excludesfile 新的忽略文件。默认情况下,这只会影响当前的存储库;如果您想更改默认值,您可以使用 - global 选项。

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"

编辑1

AFAIK, .gitignore 不能禁用。它优先于 .git / info / excludes core.excludesfile 。我能想到的唯一方法是使用过滤器进行一些攻击。 这个答案很好地解释了过滤器的使用。

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.

这篇关于我如何告诉Git使用不同于gitignore的gitignore文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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