当使用git config——global来设置时,它会写入哪个文件?

例子:

git config --global core.editor "blah"

我在这些地方都找不到:

C:\Program Files\Git\etc\gitconfig

C:\myapp\.git\config

我没有设置ENV?

我的Git版本:1.6.5.1.1367。gcd48 - 在Windows 7上


当前回答

.gitconfig文件位置

macOS测试OK

全球

# global config
$ cd ~/.gitconfig

# view global config
$ git config --global -l

当地的

# local config
$ cd .git/config

# view local config
$ git config -l


也许对你有好处:Vim或VSCode编辑git配置


# open config with Vim

# global config
$ vim ~/.gitconfig

# local config
$ vim .git/config


# open config with VSCode

# global config
$ code ~/.gitconfig

# local config
$ code .git/config

其他回答

只是完全同意@cameron-mckenzie在本页上的回答,上面关于何时创建全局的.gitconfig文件?(这显然适用于所有操作系统)。他的其余回答涉及Win7系统。

在Win10系统中也是如此,只有当你想要设置user.name & user时,才会第一次创建.gitconfig全局文件。通过Windows命令提示符电子邮件系统变量。设置完成后,.gitconfig文件将在%USERPROFILE% dir中创建。

下面的命令适用于Win和MacOS

因此,让我们假设.gitconfig文件已经存在。你可以通过Command-prompt/ git - bash/Terminal知道它的位置:

git config --global --list --show-origin

我的全局.gitconfig也有一个问题 这是为了案例有人也有这种奇怪的情况

git说:

致命:读取配置文件时发生未知错误

现在我修好了。问题是这个文件夹中的第二个.gitconfig:

c: \ \用户myUser配置git \配置。

我不知道它从何而来……但现在一切又像魔法一样管用了。

.gitconfig文件位置

macOS测试OK

全球

# global config
$ cd ~/.gitconfig

# view global config
$ git config --global -l

当地的

# local config
$ cd .git/config

# view local config
$ git config -l


也许对你有好处:Vim或VSCode编辑git配置


# open config with Vim

# global config
$ vim ~/.gitconfig

# local config
$ vim .git/config


# open config with VSCode

# global config
$ code ~/.gitconfig

# local config
$ code .git/config

我正在运行Windows 7,并按照GitHub上的说明(一两年前)使用git作为安装。我认为这是一个相当常见的用例。上面的答案对我没有帮助,在经历了很多挫折后,我最终在以下目录中找到了我的“真正的”gitconfig文件;

C:\Users\Bill\AppData\Local\GitHub\PortableGit_054f2e797ebafd44a30203088cd 3D58663C627EF\etc

显然要替换用户名,PortableGit_后面的后缀是唯一的GUID或类似的。

2016年更新:使用git 2.8(2016年3月),你可以简单地使用:

git config --list --show-origin

在Git 2.26 (Q1 2020)中,你可以添加——show-scope选项

git config --list --show-origin --show-scope

您将看到在哪里设置了哪个配置。 参见“我的Git配置中的设置来自哪里?”

正如史蒂夫西亚克在评论中指出的那样,

它将适用于非标准安装位置。(即Git Portable)

(比如最新的PortableGit-2.14.2-64-bit.7z.exe,你可以在任何地方解压)


原答案(2010)

从文档中可以看出:

——全球 对于写入选项:write to global ~/。Gitconfig文件,而不是仓库的。git/config。

由于您使用的是面向Windows的Git,因此可能不清楚它对应的位置是什么。但是如果你查看etc/profile(在C:\Program Files\ Git中),你会看到:

HOME="$HOMEDRIVE$HOMEPATH"

意义:

C:\Users\MyLogin

(适用于windows7)

这意味着文件在c:\ users \ mylogin \。gitconfig用于Windows 7下的Git。