我应该在哪里放置我的全球'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
但是 $(前缀)
是哪里?特别是,OS X在哪里(Git位于 / usr / local / git / bin / git
)?或者(或者另外)将会〜/ .gitattributes
work ?
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. In contrast, a system-wide setting affects all repositories for all users of a machine.
(我只是提到完整性。)
(I'm only mentioning this for completeness.)
根据 Pro Git书籍的相关部分, $ b
According to the relevant section of the Pro Git book,
如果您希望仅影响单个存储库(即,将属性分配给特定于该存储库的一个用户工作流的文件),则属性应放置在
$ 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
通常会展开为<全局(用户级别)gitattributes $ b $ / git
。
$GIT_DIR
would typically expand to <path-to-repo-root-directory>/.git
.
根据 Pro Git书籍的相关部分, p>
According to the relevant section of the Pro Git book,
应影响单个用户的所有存储库的属性应放置在
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书籍的相关部分,
系统中所有用户的属性应放置在
$(前缀)/ etc / gitattributes
文件中。 / b>
Attributes for all users on a system should be placed in the
$(prefix)/etc/gitattributes
file.
这自然会引起问题:
which naturally begs the question:
[...]但是,
$(前缀)
?
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屋!