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


当前回答

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

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

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

其他回答

可能需要注意的是(对于*nix平台):某些类型的全局git配置/信息存储在/usr/share/git-core/中,例如git自动完成脚本和以下(默认)钩子:

applypatch-msg 后更新 未雨绸缪 prepare-commit-msg commit-msg pre-applypatch pre-rebase 更新

它们中的每一个都可以在各自的文件名所描述的时间包含自己要执行的命令集。

Git帮助配置

文件部分有详细说明。

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

我认为这句话很重要:

Git for Windows supports four levels of configuration. At the lowest level is the machine specific configuration settings known as "portable" and lives a "%ProgramData%\Git\config". One priority level us the installation specific configuration settings known as "system", which live at "\mingw64\etc\gitconfig". Both of these configuration file, generally require elevated privileges to modify. Starting with the use specific values known as "global" configuration, which can be found at "%UserProfile%.gitconfig", we find the "user editable" configuration files. The highest priority configuration settings are in the "local" configuration, which can usually be found at ".git\config". It see the recommendation in the blog linked is to modify the "system" or "installation" specific configuration settings, which is fine but users should expect that other installations of Git would not absorb said settings. If you want machine wide settings, use the "portable" configuration file, otherwise choose the "global" or "local" configuration files. Hopefully, people find this information useful.

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