git 我应该在哪里放置我的全局“gitattributes”文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28026767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:49:13  来源:igfitidea点击:

Where should I place my global 'gitattributes' file?

gitunixpathgitattributes

提问by orome

I gather there is (despite the lack of documentation) a wayto set Git attributesglobally; but I'm not clear where to place the necessary gitattributesfile. The instructionssay they belong in

我认为(尽管缺乏文档)有一种全局设置Git 属性的方法;但我不清楚在哪里放置必要的gitattributes文件。该说明称,他们属于在

$(prefix)/etc/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 ~/.gitattributeswork?

但在哪里$(prefix)?特别是,OS X 在哪里(使用 Git /usr/local/git/bin/git)?或者(或另外)会~/.gitattributes起作用吗?

回答by jub0bs

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 globalsetting affect all repositories for onespecific user (the active one). In contrast, a system-widesetting affects all repositories for allusers of a machine.

您的问题的术语有些含糊不清。在 Git 上下文中,“全局”通常意味着“用户级别”;换句话说,全局设置会影响一个特定用户(活动用户)的所有存储库。相比之下,系统范围的设置会影响机器所有用户的所有存储库。

Repository-level gitattributes

存储库级 gitattributes

(I'm only mentioning this for completeness.)

(我只是为了完整性才提到这一点。)

According to the relevant section of the Pro Git book,

根据Pro Git book相关部分

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/attributesfile.

如果您只想影响单个存储库(即,将属性分配给特定于该存储库的一个用户工作流的$GIT_DIR/info/attributes文件),则应将属性放置在文件中。

$GIT_DIRwould typically expand to <path-to-repo-root-directory>/.git.

$GIT_DIR通常会扩展到<path-to-repo-root-directory>/.git.

Global (user-level) gitattributes

全局(用户级)gitattributes

According to the relevant section of the Pro Git book,

根据Pro Git book相关部分

Attributes that should affect all repositories for a single user should be placed in a file specified by the core.attributesfileconfiguration option [...]. Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOMEis either not set or empty, $HOME/.config/git/attributesis used instead.

应该影响单个用户的所有存储库的属性应该放在由core.attributesfile配置选项 [...]指定的文件中。其默认值为$XDG_CONFIG_HOME/git/attributes。如果$XDG_CONFIG_HOME未设置或为空,$HOME/.config/git/attributes则改为使用。

You can also run the following command,

您也可以运行以下命令,

git config --global core.attributesfile <path>

to point Git to a custom path <path>for your global gitattributes file, e.g. ~/.gitattributes.

将 Git 指向<path>全局 gitattributes 文件的自定义路径,例如~/.gitattributes.

System-wide gitattributes

系统范围的 git 属性

According to the relevant section of the Pro Git book,

根据Pro Git book相关部分

Attributes for all users on a system should be placed in the $(prefix)/etc/gitattributesfile.

系统上所有用户的属性都应该放在$(prefix)/etc/gitattributes文件中。

which naturally begs the question:

这自然引出了一个问题:

[...] But where is $(prefix)?

[...] 但是在哪里$(prefix)

See What is $(prefix) on $(prefix)/etc/gitconfig?for an answer. Unless you've assigned prefixa custom, non-empty value, $(prefix)expands to nothing by default; therefore, your system-wide gitattributesfile should reside in /etc/.

请参阅$(prefix)/etc/gitconfig 上的 $(prefix) 是什么?一个答案。除非您分配prefix了自定义的非空值,否则$(prefix)默认情况下不会扩展;因此,您的系统范围的gitattributes文件应该位于/etc/.