当其配置文件为“ $ XDG_CONFIG_HOME / git / config”时,如何设置Git配置选项? [英] How to set a Git config option when its config file is "$XDG_CONFIG_HOME/git/config"?

查看:427
本文介绍了当其配置文件为“ $ XDG_CONFIG_HOME / git / config”时,如何设置Git配置选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Fedora Linux版本20上的Git版本1.9.3中,我正在查询用户名,例如:

With Git, version 1.9.3 on Fedora Linux, version 20, I am querying for example the user's name like so:

git config user.name
# Foo Bar

但是当我尝试更改它时像这样:

But when I try to change it like so:

git config user.name 'Bar Foo'

我收到以下错误:

# error: could not lock config file .git/config: No such file or directory

规范( http://standards.freedesktop.org/basedir-spec/基于ir-spec-latest.html )和git-config(1)联机帮助页的文件部分,我将Git配置文件放置在 $ XDG_CONFIG_HOME / git / config 下。 code>。

In accordance to the "XDG Base Directory Specification" (http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and the "FILES" section of the git-config(1) manpage I placed my Git config file under "$XDG_CONFIG_HOME/git/config".

请注意,变量 XDG_CONFIG_HOME 设置为 $ HOME / .config GIT_CONFIG 变量在我的环境中未设置。

Please note that the "XDG_CONFIG_HOME variable is set to "$HOME/.config" and the GIT_CONFIG variable is unset in my environment.

我知道git-config(1)联机帮助页的 FILES部分指出:如果$ XDG_CONFIG_HOME未设置或为空,将使用$ HOME / .config / git / config。

I am aware that the "FILES" section of the git-config(1) manpage states: "If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used."

但是Git应该忽略 $ XDG_CONFIG_HOME / git / config 文件,即在阅读写作时。

But then Git should ignore the "$XDG_CONFIG_HOME/git/config" file consistently, i.e. while reading and writing.

我错过了什么吗?

推荐答案

您正在尝试在本地设置它(在 .git / config 中),而不是全局的(在主目录的XDG配置中)。

You're trying to set it locally (in .git/config) rather than globally (in the XDG config in your home directory).

发生此错误是因为您实际上不在存储库中。有点虚假的错误消息,但我可以重复一遍:

The error occurs because you're not actually in a repository. It's a bit of a bogus error message but I can repeat it:

$ cd /someplace/with/no/repo; git config user.name boo
error: could not lock config file .git/config: No such file or directory

在评论中已经提到的Biffen ,您需要添加-global

作为 VonC注释,从git版本2.8开始,误导性错误消息已更改为明智的内容。

As VonC notes, the misleading error message is changed to something sensible as of git version 2.8.

这篇关于当其配置文件为“ $ XDG_CONFIG_HOME / git / config”时,如何设置Git配置选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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