git config --global 在哪里写入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2114111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does git config --global get written to?
提问by Ian Vaughan
When using git config --global
to set things up, to which file will it write?
当使用git config --global
来处理事情,将会写入哪个文件?
Example:
例子:
git config --global core.editor "blah"
I can't find it at these places:
我在这些地方找不到它:
C:\Program Files\Git\etc\gitconfig
C:\myapp\.git\config
I have not set an ENV?
我没有设置ENV?
My Git version: 1.6.5.1.1367.gcd48 – on Windows 7
我的 Git 版本:1.6.5.1.1367.gcd48 – 在 Windows 7 上
回答by VonC
Update 2016: with git 2.8 (March 2016), you can simply use:
2016 年更新:使用 git 2.8(2016 年 3 月),您可以简单地使用:
git config --list --show-origin
And with Git 2.26 (Q1 2020), you can add a --show-scope
option
使用 Git 2.26(2020 年第一季度),您可以添加一个--show-scope
选项
git config --list --show-origin --show-scope
You will see which config is set where.
See "Where do the settings in my Git configuration come from?"
您将看到在何处设置了哪个配置。
请参阅“我的 Git 配置中的设置从何而来?”
As Steven Vascellaropoints out in the comments,
正如Steven Vascellaro在评论中指出的那样,
it will work with non-standard install locations. (i.e. Git Portable)
它将适用于非标准安装位置。(即Git 便携版)
(like the latest PortableGit-2.14.2-64-bit.7z.exe
, which can be uncompressed anywhere you want)
(比如最新的PortableGit-2.14.2-64-bit.7z.exe
,可以在任何你想要的地方解压缩)
Original answer (2010)
原始答案 (2010)
From the docs:
从文档:
--global
For writing options: write to global
~/.gitconfig
file rather than the repository.git/config
.
- 全球的
对于写入选项:写入全局
~/.gitconfig
文件而不是存储库.git/config
。
Since you're using Git for Windows, it may not be clear what location this corresponds to. But if you look at etc/profile (in C:\Program Files\Git
), you'll see:
由于您使用的是Git for Windows,因此可能不清楚这对应于哪个位置。但是如果你查看 etc/profile (in C:\Program Files\Git
),你会看到:
HOME="$HOMEDRIVE$HOMEPATH"
Meaning:
意义:
C:\Users\MyLogin
(on Windows 7)
(在 Windows 7 上)
That means the file is in C:\Users\MyLogin\.gitconfig
for Git in Windows 7.
这意味着该文件C:\Users\MyLogin\.gitconfig
适用于 Windows 7中的 Git。
回答by MAD
I was also looking for the global .gitconfig
on my Windows machine and found this neat trick using git.
我也在.gitconfig
我的 Windows 机器上寻找全局变量,并使用 git 找到了这个巧妙的技巧。
Do a: git config --global -e
and then, if you are lucky, you will get a text editor loaded with your global .gitconfig
file. Simply lookup the folder from there (or try a save as...), et voilà! :-)
做一个:git config --global -e
然后,如果你幸运的话,你会得到一个加载了全局.gitconfig
文件的文本编辑器。只需从那里查找文件夹(或尝试另存为...),等等!:-)
回答by Ben
On *nixes, it's in ~/.gitconfig
. Is there a corresponding file in your home?
在 *nixes 上,它在~/.gitconfig
. 你家有对应的文件吗?
On Windows you can type in git bash
在 Windows 上你可以输入 git bash
notepad ~/.gitconfig
回答by hash
The paths for msysgit are:
msysgit 的路径是:
Windows XP-C:\Documents and Settings\<user_name>\.gitconfig
视窗 XP-C:\Documents and Settings\<user_name>\.gitconfig
Windows Vista+C:\Users\<user_name>\.gitconfig
Windows Vista+C:\Users\<user_name>\.gitconfig
回答by Philip Oakley
The global location is derived, on Windows MsysGit, using the HOMEDRIVE and HOMEPATH environment variables, unless you have defined a HOME environment variable. The is detailed in the 'profile' script.
除非您定义了 HOME 环境变量,否则全局位置是在 Windows MsysGit 上使用 HOMEDRIVE 和 HOMEPATH 环境变量派生的。'profile' 脚本中有详细说明。
In my corporate environment the HOMEDRIVE is H:, which is then mapped to a network URL \\share\$. The whole lot is then mapped to be "My Documents", which isn't where others would expect. There may have been some further problems with the drive to URL remapping. I don't even get to adjust the HOMEDRIVE or HOMEPATH variables anyway.
在我的公司环境中,HOMEDRIVE 是 H:,然后映射到网络 URL \\share\$。然后将整个批次映射到“我的文档”,这不是其他人所期望的。URL 重新映射的驱动器可能存在一些进一步的问题。无论如何,我什至无法调整 HOMEDRIVE 或 HOMEPATH 变量。
In my case I have defined a personal HOME environment variable and pointed it to D:\git\GitHOME and copied all those GIT files (which are without and extension) to the GitHOME directory for safe keeping.
在我的例子中,我定义了一个个人 HOME 环境变量并将其指向 D:\git\GitHOME 并将所有这些 GIT 文件(没有和扩展名)复制到 GitHOME 目录以安全保存。
The windows environment variables can be set via the Advanced tab in the My Computer properties dialog.
可以通过“我的电脑”属性对话框中的“高级”选项卡设置 Windows 环境变量。
回答by DanielaWaranie
If you are using TortoiseGit on a windows PC you can use:
如果您在 Windows PC 上使用 TortoiseGit,您可以使用:
Settings / Git / Config / Edit global .gitconfig
to open the global .gitignore file.
打开全局 .gitignore 文件。
But if you use your Windows (7) PC in a domain your profile dir is may be a network share (mounted as a drive). In this case TortoiseGit (at least:1.6.5.0) is pointing you to the wrong dir (on c:...). See the closed TortoiseGit issue 922for more information. Or using %HOMEDRIVE%%HOMEPATH% to open the dir that contains the .gitignore file.
但是,如果您在域中使用 Windows (7) PC,您的配置文件目录可能是网络共享(安装为驱动器)。在这种情况下,TortoiseGit(至少:1.6.5.0)将您指向错误的目录(在 c:... 上)。有关更多信息,请参阅已关闭的 TortoiseGit问题 922。或者使用 %HOMEDRIVE%%HOMEPATH% 打开包含 .gitignore 文件的目录。
回答by Benny Neugebauer
I am using SmartGitwith msysgit on Windows 8.1 and noticed that there can be three different locations for the gitconfig
file:
我在 Windows 8.1 上将SmartGit与 msysgit 一起使用,并注意到该gitconfig
文件可能有三个不同的位置:
%USERPROFILE%\.gitconfig
C:\Program Files (x86)\Git\etc\gitconfig
C:\Program Files (x86)\SmartGitHg\git\etc\gitconfig
But the one that is used is the one from %USERPROFILE%\.gitconfig
.
但是使用的是来自%USERPROFILE%\.gitconfig
.
回答by samstav
It might be useful to note (for *nix platforms): some types of global git configuration/information are stored in /usr/share/git-core/
, such as git autocompletion scripts and the following (default) hooks:
注意(对于 *nix 平台)可能有用:某些类型的全局 git 配置/信息存储在 中/usr/share/git-core/
,例如 git 自动完成脚本和以下(默认)钩子:
- applypatch-msg
- post-update
- pre-commit
- prepare-commit-msg
- commit-msg
- pre-applypatch
- pre-rebase
- update
- applypatch-msg
- 更新后
- 预提交
- 准备提交消息
- 提交消息
- 预应用补丁
- 预变基
- 更新
Each of these can contain their own set of commands to execute, at the time described by their respective filenames.
每一个都可以包含自己的一组要执行的命令,时间由它们各自的文件名描述。
回答by Cameron McKenzie
When is the global .gitconfig file created?
什么时候创建全局 .gitconfig 文件?
First off, git doesn't automatically create the global config file (.gitconfig) during its installation. The file is not created until it is written to for the first time. If you have never set a system variable, it will not be on your file system.I'm guessing that might be the source of the problem.
首先,git 在安装过程中不会自动创建全局配置文件 (.gitconfig)。在第一次写入文件之前,不会创建该文件。如果您从未设置过系统变量,它就不会出现在您的文件系统中。我猜这可能是问题的根源。
One way to ask Git to create it is to request an edit. Doing so will force the file's creation.
要求 Git 创建它的一种方法是请求编辑。这样做将强制创建文件。
git config --global --edit
git 配置 --global --edit
If you monitor the user's home folder when you issue this command, you will see the .gitconfig file magically appear.
如果您在发出此命令时监视用户的主文件夹,您将看到 .gitconfig 文件神奇地出现。
Where is git configuration stored?
git 配置存储在哪里?
Here's a quick rundown of the the name and location of the configuration files associated with the three Git scopes, namely system, globaland local:
以下是与三个 Git 作用域(即system、global和local )关联的配置文件的名称和位置的简要概述:
- System Git configuration: File named gitconfiglocated in -git-install-location-/ming<32>/etc
- Global Git configuraiton: File named .gitconfiglocated in the user's home folder (C:\Users\git user)
- Local Git configuration: File named configin the .git folderof the local repo
- 系统 Git 配置:名为gitconfig 的文件位于-git-install-location-/ming<32>/etc
- 全局 Git 配置:名为.gitconfig 的文件位于用户的主文件夹(C:\Users\git user)
- 本地 Git 配置:本地 repo的.git 文件夹中名为config的文件
Of course, seeing is believing, so here's an image showing each file and each location. I pulled the image from an article I wrote on the topic.
当然,眼见为实,所以这里有一张图片显示了每个文件和每个位置。我从我写的关于该主题的文章中提取了图像。
Windows Git configuration file locations (TheServerSide.com)
回答by Mane
I had also a problem with my global .gitconfig
This is for the case someone also has this strange
我的全局也有问题.gitconfig
这是因为有人也有这种奇怪的情况
git said:
git 说:
fatal: unknown error occured while reading the configuration files
致命:读取配置文件时发生未知错误
Now I fixed it. The problem was a second .gitconfig
in this folder:
现在我修好了。问题出.gitconfig
在此文件夹中的第二个:
c:\Users\myUser.config\git\config
c:\Users\myUser.config\git\config
I don't know where it came from... But now everything works like a charme again.
我不知道它是从哪里来的......但现在一切都像魅力一样。