如何显示我的全局 Git 配置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12254076/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:31:20  来源:igfitidea点击:

How do I show my global Git configuration?

git

提问by wullxz

I'd like to show all configured Git sections.

我想显示所有配置的 Git 部分。

I only found git config --get core.editor, and I'd like to output everything that's configured globally, not only the configured default editor.

我只找到了git config --get core.editor,我想输出全局配置的所有内容,而不仅仅是配置的默认编辑器。

回答by Cameron Skinner

You can use:

您可以使用:

git config --list

or look at your ~/.gitconfigfile. The local configuration will be in your repository's .git/configfile.

或查看您的~/.gitconfig文件。本地配置将在您的存储库.git/config文件中。

Use:

用:

git config --list --show-origin

to see where that setting is defined (global, user, repo, etc...)

查看该设置的定义位置(全局、用户、存储库等...)

回答by linquize

The shortest,

最短的,

git config -l

shows all inherited values from: system, global and local

显示所有继承的值:系统、全局和本地

回答by kgf3JfUtW

How do I edit my globalGit configuration?

如何编辑我的全局Git 配置?

Short answer: git config --edit --global

简短的回答: git config --edit --global



To understand Git configuration, you should know that:

要了解 Git 配置,您应该知道:

Git configuration variables can be stored at three different levels. Each level overrides values at the previous level.

Git 配置变量可以存储在三个不同的级别。每个级别都会覆盖上一级别的值。

1. System level (applied to every user on the system and all their repositories)

1.系统级别(适用于系统上的每个用户及其所有存储库)

  • to view, git config --list --system(may need sudo)
  • to set, git config --system color.ui true
  • to edit system config file, git config --edit --system
  • 查看,git config --list --system(可能需要sudo
  • 设置, git config --system color.ui true
  • 编辑系统配置文件, git config --edit --system

2. Global level (values specific personally to you, the user).

2. 全局级别(特定于您个人的值,用户)。

  • to view, git config --list --global
  • to set, git config --global user.name xyz
  • to edit global config file, git config --edit --global
  • 查看, git config --list --global
  • 设置, git config --global user.name xyz
  • 编辑全局配置文件, git config --edit --global

3. Repository level (specific to that single repository)

3. 存储库级别(特定于单个存储库)

  • to view, git config --list --local
  • to set, git config --local core.ignorecase true(--localoptional)
  • to edit repository config file, git config --edit --local(--localoptional)
  • 查看, git config --list --local
  • 设置,git config --local core.ignorecase true--local可选)
  • 编辑存储库配置文件,git config --edit --local--local可选)

How do I view allsettings?

如何查看所有设置?

  • Run git config --list, showing system, global, and (if inside a repository) localconfigs
  • Run git config --list --show-origin, also shows the origin file of each config item
  • 运行git config --list,显示systemglobal和(如果在存储库中)本地配置
  • 运行git config --list --show-origin,还显示每个配置项的源文件

How do I read one particular configuration?

我如何阅读一个特定的配置?

  • Run git config user.nameto get user.name, for example.
  • You may also specify options --system, --global, --localto read that value at a particular level.
  • 例如,运行git config user.name以获取user.name
  • 您还可以指定 options --system, --global,--local以在特定级别读取该值。


Reference: 1.6 Getting Started - First-Time Git Setup

参考:1.6 入门 - 首​​次 Git 设置

回答by Rook

git config --list

is one way to go. I usually just open up .gitconfigthough.

是一种方法。我通常只是打开.gitconfig

回答by leondepeon

You can also call git config -eto open the configuration file in your editor directly. The Git configuration file is much more readable that the -loutput, so I always tend to use the -eflag.

您也可以git config -e直接在编辑器中调用以打开配置文件。Git 配置文件比-l输出更具可读性,所以我总是倾向于使用-e标志。

So to summarise:

所以总结一下:

git config -l  # List Git configuration settings (same as --list)
git config -e  # Opens Git configuration in the default editor (same as --edit)
  • Without parameters it interacts with the local .git/config.
  • With --globalit interacts with ~/.gitconfig.
  • And with --systemit interacts with $(prefix)/etc/gitconfig.
  • 没有参数,它与本地交互.git/config
  • --global它交互~/.gitconfig
  • 并与之--system交互$(prefix)/etc/gitconfig

(I couldn't really find what $(prefix)means, but it seems to default to $HOME.)

(我真的找不到什么$(prefix)意思,但它似乎默认为$HOME。)

回答by Ankit K Gupta

You can also use cat ~/.gitconfig.

您也可以使用cat ~/.gitconfig.

回答by VonC

Git 2.6 (Sept/Oct 2015) will add the option --name-onlyto simplify the output of a git config -l:

Git 2.6(2015 年 9 月/10 月)将添加选项--name-only以简化 a 的输出git config -l

See commit a92330d, commit f225987, commit 9f1429d(20 Aug 2015) by Jeff King (peff).
See commit ebca2d4(20 Aug 2015), and commit 905f203, commit 578625f(10 Aug 2015) by SZEDER Gábor (szeder).
(Merged by Junio C Hamano -- gitster--in commit fc9dfda, 31 Aug 2015)

请参阅Jeff King ( ) 的commit a92330dcommit f225987commit 9f1429d(2015 年 8 月 20 日。 参见SZEDER Gábor ( ) 的commit ebca2d4(20 Aug 2015)、commit 905f203commit 578625f(10 Aug 2015 )(由Junio C Hamano合并-- --fc9dfda 提交中,2015 年 8 月 31 日)peff
szeder
gitster

config: add '--name-only' option to list only variable names

'git config' can only show values or name-value pairs, so if a shell script needs the names of set config variables it has to run 'git config --list' or '--get-regexp' and parse the output to separate config variable names from their values.
However, such a parsing can't cope with multi-line values.

Though 'git config' can produce null-terminated output for newline-safe parsing, that's of no use in such a case, because shells can't cope with null characters.

Even our own bash completion script suffers from these issues.

Help the completion script, and shell scripts in general, by introducing the '--name-only' option to modify the output of '--list' and '--get-regexp' to list only the names of config variables, so they don't have to perform error-prone post processing to separate variable names from their values anymore.

config: 添加 ' --name-only' 选项以仅列出变量名称

' git config' 只能显示值或名称-值对,因此如果 shell 脚本需要设置配置变量的名称,它必须运行 ' git config --list' 或 ' --get-regexp' 并解析输出以将配置变量名称与其值分开。
但是,这样的解析无法处理多行值。

尽管 ' git config' 可以为换行安全解析生成以空字符结尾的输出,但在这种情况下这没有用,因为 shell 无法处理空字符。

甚至我们自己的 bash 完成脚本也会遇到这些问题。

通过引入“ --name-only”选项来修改“ --list”和“ --get-regexp”的输出以仅列出配置变量的名称,从而帮助完成脚本和一般的shell脚本,因此它们不必执行容易出错的后期处理不再将变量名与其值分开。

回答by prosti

One important thing about git config:

一件重要的事情git config

git confighas --local, --globaland --systemlevels and corresponding files.

git config--local,--global--system级别和相应的文件。

So you may use git config --local, git config --globaland git config --system.

所以你可以使用git config --local,git config --globalgit config --system

By default, git configwill write to a locallevel if no configuration option is passed. Local configuration values are stored in a file that can be found in the repository's .git directory: .git/config

默认情况下,如果没有传递配置选项,git config将写入本地级别。本地配置值存储在可以在存储库的 .git 目录中找到的文件中:.git/config

Global level configuration is user-specific, meaning it is applied to an operating system user. Global configuration values are stored in a file that is located in a user's home directory. ~/.gitconfigon Unix systems and C:\Users\<username>\.gitconfigon Windows.

全局级别配置是特定于用户的,这意味着它适用于操作系统用户。全局配置值存储在位于用户主目录中的文件中。~/.gitconfig在 Unix 系统和C:\Users\<username>\.gitconfigWindows 上。

System-level configuration is applied across an entire machine. This covers all users on an operating system and all repositories. The system level configuration file lives in a gitconfigfile off the system root path. $(prefix)/etc/gitconfig on Linux systems. On Windows this file can be found in C:\ProgramData\Git\config.

系统级配置应用于整个机器。这涵盖了操作系统和所有存储库上的所有用户。系统级配置文件位于gitconfig系统根路径之外的文件中。$(prefix)/etc/gitconfig 在 Linux 系统上。在 Windows 上,可以在C:\ProgramData\Git\config.

So your option is to find that global .gitconfigfile and edit it.

因此,您的选择是找到该全局.gitconfig文件并对其进行编辑。

Or you can use git config --global --list.

或者你可以使用git config --global --list.

This is exactly the line what you need.

这正是您需要的线路。

Enter image description here

在此处输入图片说明

回答by dleal

If you just want to list one part of the Git configuration, such as alias, core, remote, etc., you could just pipe the result through grep. Something like:

如果您只想列出 Git 配置的一部分,例如aliascoreremote等,您可以通过 grep 管道传输结果。就像是:

git config --global -l | grep core

回答by Daniel Perník

On Linux-based systems you can view/edit a configuration file by

在基于 Linux 的系统上,您可以通过以下方式查看/编辑配置文件

vi/vim/nano .git/config

Make sure you are inside the Git init folder.

确保您位于 Git init 文件夹中。

If you want to work with --global config, it's

如果你想和--global config它一起工作,那就是

vi/vim/nano .gitconfig

on /home/userName

在 /home/userName

This should help with editing: https://help.github.com/categories/setup/

这应该有助于编辑:https: //help.github.com/categories/setup/