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


当前回答

卸载Msysgit,安装Cygwin + Git。然后是global '。C:\cygwin(64)\home\[userName]\。gitconfig。

现在你不必担心可能被其他程序使用的环境变量。例如,我的环境变量将我指向工作windows域环境中的一个映射驱动器。我不希望我的全局。gitconfig位于我的“home”映射驱动器上。我也不知道其他可能依赖于windows环境变量的应用程序会发生什么。由于某种原因,操作部门可能需要将该环境变量设置为映射的驱动器。

此外,你不必担心Mysysgit覆盖你的'配置文件'配置设置,如果你指定一个特定的路径全局'。Gitconfig ',使用这个方法。

一般来说,节省自己,在窗口中使用cygwin bash shell会更快乐

其他回答

正如@MatrixFrog在他们的评论中指出的,如果目标是编辑配置,你可能想要运行:

git config --global --edit

这个命令将在选择的编辑器中打开配置文件(在本例中是——global文件),并等待文件关闭(就像git rebase -i期间一样)。

我认为这句话很重要:

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.

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。

如果你在windows电脑上使用TortoiseGit,你可以使用:

Settings / Git / Config / Edit global .gitconfig

打开全局文件。gitignore。

但是如果你在域中使用你的Windows (7) PC,你的配置文件目录可能是一个网络共享(挂载为驱动器)。在这种情况下,TortoiseGit(至少:1.6.5.0)将您指向错误的目录(在c:…)。有关更多信息,请参阅已关闭的TortoiseGit issue 922。或者使用%HOMEDRIVE%%HOMEPATH%打开包含.gitignore文件的目录。

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