当使用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

其他回答

我在Windows 8.1上使用SmartGit和msysgit,并注意到gitconfig文件可以有三个不同的位置:

%USERPROFILE%\.gitconfig
C:\Program Files (x86)\Git\etc\gitconfig
C:\Program Files (x86)\SmartGitHg\git\etc\gitconfig

但是使用的是来自%USERPROFILE%\.gitconfig的。

在*nixes上,它在~/.gitconfig中。你家里有相应的文件吗?

在Windows上,你可以输入git bash

notepad ~/.gitconfig

msysgit的路径如下:

Windows XP -C:\Documents and Settings\<user_name>\.gitconfig

Windows Vista+ C:\用户\<用户名>\.gitconfig

只是完全同意@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

我把Git安装在:C:\Users\_myuserfolder_\AppData\Local\Programs\Git