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


当前回答

正如@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.

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

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

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

.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电脑上使用TortoiseGit,你可以使用:

Settings / Git / Config / Edit global .gitconfig

打开全局文件。gitignore。

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

msysgit的路径如下:

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

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