当使用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上
当使用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
其他回答
我的全局.gitconfig也有一个问题 这是为了案例有人也有这种奇怪的情况
git说:
致命:读取配置文件时发生未知错误
现在我修好了。问题是这个文件夹中的第二个.gitconfig:
c: \ \用户myUser配置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.
源
在*nixes上,它在~/.gitconfig中。你家里有相应的文件吗?
在Windows上,你可以输入git bash
notepad ~/.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
全局位置是在Windows MsysGit上使用HOMEDRIVE和HOMEPATH环境变量派生的,除非您已经定义了HOME环境变量。在'profile'脚本中详细描述。
在我的公司环境中,HOMEDRIVE是H:,然后映射到一个网络URL \\share\$。然后,所有的文件都被映射为“我的文件”,这不是其他人所期望的。URL重映射的驱动器可能存在进一步的问题。我甚至无法调整HOMEDRIVE或HOMEPATH变量。
在我的情况下,我已经定义了一个个人HOME环境变量,并将其指向D:\git\GitHOME,并将所有这些git文件(没有和扩展名)复制到GitHOME目录以安全保存。
windows环境变量可以通过“我的电脑”属性对话框中的“高级”选项卡设置。