git配置——全局写到哪里?

时间:2021-10-15 08:06:09

When using git config --global to set things up, to which file will it write?

当使用git配置——全局设置时,它会写入哪个文件?

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上。

13 个解决方案

#1


809  

Update 2016: with git 2.8 (March 2016), you can simply use:

更新2016:使用git 2.8(2016年3月),您可以简单使用:

git config --list --show-origin

You will see which config is set where.
See "Where do the settings in my Git configuration come from?"

您将看到哪个配置设置在哪里。请参见“我的Git配置中的设置来自哪里?”

As Steven Vascellaro points 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.

写选项:写到global ~/。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用于Windows,所以可能不清楚这对应于什么位置。但如果你看看等/配置文件(在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\.文件在Windows 7中的Git。

#2


92  

I was also looking for the global .gitconfig on my Windows machine and found this neat trick using git.

我还在我的Windows机器上寻找全局的。gitconfig,并发现了使用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配置——全局-e,如果你幸运的话,你会得到一个文本编辑器,它装载了你的全局.gitconfig文件。简单地从那里查找文件夹(或者尝试一个save as…),等一下!:-)

#3


66  

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

#4


39  

The paths for msysgit are:

msysgit的路径是:

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

Windows XP -C:\文档和设置\ \.gitconfig。

Windows Vista+ C:\Users\<user_name>\.gitconfig

< user_name > Windows Vista + C:\Users\ \ .gitconfig

#5


31  

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.

在Windows MsysGit上,使用HOMEDRIVE和主页环境变量来获取全局位置,除非您已经定义了一个家庭环境变量。在“概要”脚本中有详细说明。

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或主页变量。

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.

在我的例子中,我定义了一个个人家庭环境变量,并将其指向D:\git\GitHOME,并将所有这些git文件(没有和扩展)复制到GitHOME目录中,以确保安全。

The windows environment variables can be set via the Advanced tab in the My Computer properties dialog.

windows环境变量可以通过My Computer properties对话框中的Advanced选项卡设置。

#6


11  

If you are using TortoiseGit on a windows PC you can use:

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

Settings / Git / Config / Edit global .gitconfig

to open the global .gitignore file.

打开global .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 922 for more information. Or using %HOMEDRIVE%%HOMEPATH% to open the dir that contains the .gitignore file.

但是如果你在一个领域使用你的Windows(7)个人电脑,你的档案目录可能是一个网络共享(安装作为驱动器)。在本例中,TortoiseGit(至少:1.6.5.0)指向错误的dir(在c:…)。查看关闭的TortoiseGit问题922获得更多信息。或者使用%HOMEDRIVE%主页%打开包含.gitignore文件的目录。

#7


8  

I am using SmartGit with msysgit on Windows 8.1 and noticed that there are three different locations for the gitconfig file:

我在Windows 8.1上使用SmartGit和msysgit,注意到gitconfig文件有三个不同的位置:

C:\Users\name\.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 "C:\Users\name\.gitconfig".

但是使用的是来自“C:\Users\。gitconfig”的那个。

#8


6  

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
  • applypatch-msg
  • post-update
  • 后更新
  • pre-commit
  • 未雨绸缪
  • prepare-commit-msg
  • prepare-commit-msg
  • commit-msg
  • commit-msg
  • pre-applypatch
  • pre-applypatch
  • pre-rebase
  • pre-rebase
  • update
  • 更新

Each of these can contain their own set of commands to execute, at the time described by their respective filenames.

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

#9


3  

I had also a problem with my global .gitconfig This is for the case someone also has this strange

我的global .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 \配置

I don't know where it came from... But now everything works like a charme again.

我不知道它是从哪里来的……但是现在,一切都又像一个charme。

#10


2  

I am running Windows 7 and using git as setup by following the instructions on GitHub (a year or two back). A rather common use-case I would have thought. None of the answers above helped me, and after much frustration I eventually found my 'real' gitconfig file in the following directory;

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

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

C:\Users\Bill\AppData\Local\GitHub\ PortableGit_054f2e797ebafd44a30203088cd 3 d58663c627ef \等等

Obviously substitute your user name and presumably the suffix after PortableGit_ is a unique GUID or similar.

显然,在PortableGit_之后替换您的用户名和后缀是唯一的GUID或类似的。

#11


1  

Uninstall Msysgit and install Cygwin + Git. Then global '.gitconfig' will be here: C:\cygwin(64)\home\[userName]\.gitconfig .

卸载Msysgit并安装Cygwin + Git。那么全球”。gitconfig将会在这里:C:\cygwin(64)\home\[用户名]\。gitconfig。

Now you don't have to worry about an environment variable which may be used by other programs. For example, my environment variable pointed me to a mapped drive in my work windows domain environment. I dont want my global .gitconfig sitting on my "home" mapped drive. I also don't know what might happen to other applications that might rely on that windows environment variable. Operations division might need that environment variable set to the mapped drive for a reason.

现在您不必担心其他程序可能使用的环境变量。例如,我的环境变量将我指向工作windows域环境中的映射驱动器。我不想让我的global .gitconfig坐在我的“home”映射驱动器上。我也不知道其他可能依赖windows环境变量的应用程序会发生什么。操作部门可能需要将环境变量设置为映射驱动器。

Also you don't have to worry about Mysysgit overwriting your 'profile' configuration settings if you specify a specific path to global '.gitconfig', using this method.

另外,如果您指定了一个特定的全局路径,您不必担心Mysysgit覆盖了您的“概要”配置设置。gitconfig’,使用这种方法。

In general, save yourself and use cygwin bash shell in windows and be happier

一般来说,在windows中保存自己并使用cygwin bash shell,这样会更快乐。

#12


1  

You can find the it using the following command

您可以使用以下命令找到它。

git config --list --show-origin

git配置——全局写到哪里?

#13


0  

I had a similar issue; the problem was that the .gitconfig file was located in

我有一个类似的问题;问题是,.gitconfig文件位于。

C:\Users\MyLogin\.gitconfig\

(on Windows 7)

(在Windows 7)

In other words, the file was located in C:\Users\MyLogin\.gitconfig\.gitconfig, instead of on C:\Users\MyLogin\.gitconfig (which is where Git was looking for the files).

换句话说,该文件位于c:usersmylogin. gitconfig。C:\Users\MyLogin\. gitconfig,而不是gitconfig(这是Git寻找文件的地方)。

#1


809  

Update 2016: with git 2.8 (March 2016), you can simply use:

更新2016:使用git 2.8(2016年3月),您可以简单使用:

git config --list --show-origin

You will see which config is set where.
See "Where do the settings in my Git configuration come from?"

您将看到哪个配置设置在哪里。请参见“我的Git配置中的设置来自哪里?”

As Steven Vascellaro points 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.

写选项:写到global ~/。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用于Windows,所以可能不清楚这对应于什么位置。但如果你看看等/配置文件(在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\.文件在Windows 7中的Git。

#2


92  

I was also looking for the global .gitconfig on my Windows machine and found this neat trick using git.

我还在我的Windows机器上寻找全局的。gitconfig,并发现了使用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配置——全局-e,如果你幸运的话,你会得到一个文本编辑器,它装载了你的全局.gitconfig文件。简单地从那里查找文件夹(或者尝试一个save as…),等一下!:-)

#3


66  

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

#4


39  

The paths for msysgit are:

msysgit的路径是:

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

Windows XP -C:\文档和设置\ \.gitconfig。

Windows Vista+ C:\Users\<user_name>\.gitconfig

< user_name > Windows Vista + C:\Users\ \ .gitconfig

#5


31  

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.

在Windows MsysGit上,使用HOMEDRIVE和主页环境变量来获取全局位置,除非您已经定义了一个家庭环境变量。在“概要”脚本中有详细说明。

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或主页变量。

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.

在我的例子中,我定义了一个个人家庭环境变量,并将其指向D:\git\GitHOME,并将所有这些git文件(没有和扩展)复制到GitHOME目录中,以确保安全。

The windows environment variables can be set via the Advanced tab in the My Computer properties dialog.

windows环境变量可以通过My Computer properties对话框中的Advanced选项卡设置。

#6


11  

If you are using TortoiseGit on a windows PC you can use:

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

Settings / Git / Config / Edit global .gitconfig

to open the global .gitignore file.

打开global .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 922 for more information. Or using %HOMEDRIVE%%HOMEPATH% to open the dir that contains the .gitignore file.

但是如果你在一个领域使用你的Windows(7)个人电脑,你的档案目录可能是一个网络共享(安装作为驱动器)。在本例中,TortoiseGit(至少:1.6.5.0)指向错误的dir(在c:…)。查看关闭的TortoiseGit问题922获得更多信息。或者使用%HOMEDRIVE%主页%打开包含.gitignore文件的目录。

#7


8  

I am using SmartGit with msysgit on Windows 8.1 and noticed that there are three different locations for the gitconfig file:

我在Windows 8.1上使用SmartGit和msysgit,注意到gitconfig文件有三个不同的位置:

C:\Users\name\.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 "C:\Users\name\.gitconfig".

但是使用的是来自“C:\Users\。gitconfig”的那个。

#8


6  

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
  • applypatch-msg
  • post-update
  • 后更新
  • pre-commit
  • 未雨绸缪
  • prepare-commit-msg
  • prepare-commit-msg
  • commit-msg
  • commit-msg
  • pre-applypatch
  • pre-applypatch
  • pre-rebase
  • pre-rebase
  • update
  • 更新

Each of these can contain their own set of commands to execute, at the time described by their respective filenames.

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

#9


3  

I had also a problem with my global .gitconfig This is for the case someone also has this strange

我的global .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 \配置

I don't know where it came from... But now everything works like a charme again.

我不知道它是从哪里来的……但是现在,一切都又像一个charme。

#10


2  

I am running Windows 7 and using git as setup by following the instructions on GitHub (a year or two back). A rather common use-case I would have thought. None of the answers above helped me, and after much frustration I eventually found my 'real' gitconfig file in the following directory;

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

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

C:\Users\Bill\AppData\Local\GitHub\ PortableGit_054f2e797ebafd44a30203088cd 3 d58663c627ef \等等

Obviously substitute your user name and presumably the suffix after PortableGit_ is a unique GUID or similar.

显然,在PortableGit_之后替换您的用户名和后缀是唯一的GUID或类似的。

#11


1  

Uninstall Msysgit and install Cygwin + Git. Then global '.gitconfig' will be here: C:\cygwin(64)\home\[userName]\.gitconfig .

卸载Msysgit并安装Cygwin + Git。那么全球”。gitconfig将会在这里:C:\cygwin(64)\home\[用户名]\。gitconfig。

Now you don't have to worry about an environment variable which may be used by other programs. For example, my environment variable pointed me to a mapped drive in my work windows domain environment. I dont want my global .gitconfig sitting on my "home" mapped drive. I also don't know what might happen to other applications that might rely on that windows environment variable. Operations division might need that environment variable set to the mapped drive for a reason.

现在您不必担心其他程序可能使用的环境变量。例如,我的环境变量将我指向工作windows域环境中的映射驱动器。我不想让我的global .gitconfig坐在我的“home”映射驱动器上。我也不知道其他可能依赖windows环境变量的应用程序会发生什么。操作部门可能需要将环境变量设置为映射驱动器。

Also you don't have to worry about Mysysgit overwriting your 'profile' configuration settings if you specify a specific path to global '.gitconfig', using this method.

另外,如果您指定了一个特定的全局路径,您不必担心Mysysgit覆盖了您的“概要”配置设置。gitconfig’,使用这种方法。

In general, save yourself and use cygwin bash shell in windows and be happier

一般来说,在windows中保存自己并使用cygwin bash shell,这样会更快乐。

#12


1  

You can find the it using the following command

您可以使用以下命令找到它。

git config --list --show-origin

git配置——全局写到哪里?

#13


0  

I had a similar issue; the problem was that the .gitconfig file was located in

我有一个类似的问题;问题是,.gitconfig文件位于。

C:\Users\MyLogin\.gitconfig\

(on Windows 7)

(在Windows 7)

In other words, the file was located in C:\Users\MyLogin\.gitconfig\.gitconfig, instead of on C:\Users\MyLogin\.gitconfig (which is where Git was looking for the files).

换句话说,该文件位于c:usersmylogin. gitconfig。C:\Users\MyLogin\. gitconfig,而不是gitconfig(这是Git寻找文件的地方)。