我应该在哪里放置我的全局“gitattributes"文件? [英] Where should I place my global 'gitattributes' file?
问题描述
我认为有(尽管缺乏文档)一种方法来设置Git 属性 全局;但我不清楚在哪里放置必要的 gitattributes
文件.说明表明它们属于
I gather there is (despite the lack of documentation) a way to set Git attributes globally; but I'm not clear where to place the necessary gitattributes
file. The instructions say they belong in
$(prefix)/etc/gitattributes
但是$(prefix)
在哪里?特别是,OS X 在哪里(在 /usr/local/git/bin/git
中使用 Git)?或者(或另外)将 ~/.gitattributes
工作?
But where is $(prefix)
? In particular, where would it be for OS X (with Git in /usr/local/git/bin/git
)? Alternately (or in addition) would ~/.gitattributes
work?
推荐答案
全局与系统范围设置
您问题的术语有些含糊不清.在 Git 上下文中,全局"通常意味着用户级别";换句话说,全局设置会影响一个特定用户(活动用户)的所有存储库.相比之下,系统范围设置会影响机器的所有用户的所有存储库.
Global vs. system-wide settings
There is some ambiguity in your question's terminology. In a Git context, "global" usually means "user-level"; in other words, a global setting affect all repositories for one specific user (the active one). In contrast, a system-wide setting affects all repositories for all users of a machine.
(我只是为了完整性才提到这一点.)
(I'm only mentioning this for completeness.)
根据 Pro Git 书籍的相关部分,
如果您只想影响单个存储库(即,为特定于该存储库的一个用户工作流程的文件分配属性),则应将属性放置在 $GIT_DIR/info/attributes代码>文件.
If you wish to affect only a single repository (i.e., to assign attributes to files that are particular to one user’s workflow for that repository), then attributes should be placed in the
$GIT_DIR/info/attributes
file.
$GIT_DIR
通常会扩展为
.
根据 Pro Git 书籍的相关部分,
应影响单个用户的所有存储库的属性应放置在由 core.attributesfile
配置选项 [...] 指定的文件中.它的默认值是 $XDG_CONFIG_HOME/git/attributes
.如果 $XDG_CONFIG_HOME
未设置或为空,则使用 $HOME/.config/git/attributes
代替.
Attributes that should affect all repositories for a single user should be placed in a file specified by the
core.attributesfile
configuration option [...]. Its default value is$XDG_CONFIG_HOME/git/attributes
. If$XDG_CONFIG_HOME
is either not set or empty,$HOME/.config/git/attributes
is used instead.
您也可以运行以下命令,
You can also run the following command,
git config --global core.attributesfile <path>
将 Git 指向全局 gitattributes 文件的自定义路径
,例如~/.gitattributes
.
to point Git to a custom path <path>
for your global gitattributes file, e.g. ~/.gitattributes
.
根据 Pro Git 书籍的相关部分,
系统上所有用户的属性应该放在 $(prefix)/etc/gitattributes
文件中.
Attributes for all users on a system should be placed in the
$(prefix)/etc/gitattributes
file.
这自然引出了一个问题:
which naturally begs the question:
[...] 但是 $(prefix)
在哪里?
[...] But where is
$(prefix)
?
见$(prefix)/etc/上的$(prefix)是什么gitconfig? 的答案.除非你给 prefix
分配了一个自定义的、非空的值,否则 $(prefix)
默认扩展为空;因此,您的系统范围的 gitattributes
文件应该位于 /etc/
中.
See What is $(prefix) on $(prefix)/etc/gitconfig? for an answer. Unless you've assigned prefix
a custom, non-empty value, $(prefix)
expands to nothing by default; therefore, your system-wide gitattributes
file should reside in /etc/
.
这篇关于我应该在哪里放置我的全局“gitattributes"文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!