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

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


您可以使用:

git config --list

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

Use:

git config --list --show-origin

查看该设置的定义位置(全局、用户、回购等)


git config --list

只有一条路要走。我通常只打开.gitconfig。


最短的,

git config -l

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


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


Git2.6(2015年9月/10月)将添加选项--name以简化Git-config-l的输出:

参见Jeff King(peff)的提交a92330d、提交f225987、提交9f1429d(2015年8月20日)。见SZEDER Gábor(SZEDER)提交的提交ebca2d4(2015年8月20日)和提交905f203、提交578625f(2015年7月10日)。(于2015年8月31日由Junio C Hamano--gitster--在commit fc9dfda中合并)

config:添加“--name only”选项以仅列出变量名称“git-config”只能显示值或名称值对,因此如果shell脚本需要设置配置变量的名称,它必须运行“git-config-list”或“--getregexp”并解析输出以将配置变量名称与其值分开。然而,这种解析无法处理多行值。虽然“git-config”可以为换行安全解析生成以null结尾的输出,但在这种情况下没有用,因为shell无法处理null字符。甚至我们自己的bash完成脚本也存在这些问题。通过介绍来帮助完成脚本和shell脚本“--name only”选项用于修改“--list”的输出,以及“--getregexp”只列出配置变量的名称,因此它们不会必须执行容易出错的后处理以分离变量名从他们的价值观。


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

vi/vim/nano .git/config

确保您在Gitinit文件夹中。

如果您想使用--global-config

vi/vim/nano .gitconfig

在/home/userName上

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


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

综上所述:

git config -l  # List Git configuration settings (same as --list)
git config -e  # Opens Git configuration in the default editor (same as --edit)

如果没有参数,它将与local.git/config交互。使用--global,它与~/.gitconfig交互。通过--system,它与$(前缀)/etc/gitconfig交互。

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


如果您只想列出Git配置的一部分,例如别名、核心、远程等,那么只需通过grep发送结果即可。类似于:

git config --global -l | grep core

如何编辑全局Git配置?

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


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

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

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

要查看,git-config--list--system(可能需要sudo)要设置,git-config--system color.ui true要编辑系统配置文件,请使用git-config-edit--system

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

要查看,git-config--list--global要设置,git-config--全局user.name xyz要编辑全局配置文件,请使用git-config--edit--global

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

要查看,git-config--list--local要设置,git-config--local-core.ignorecase true(--local可选)要编辑存储库配置文件,请使用git-config--edit--local(--local可选)

如何查看所有设置?

运行git-config--list,显示系统、全局和(如果在存储库中)本地配置运行git-config--list--show origin,同时显示每个配置项的源文件

如何读取特定配置?

例如,运行git-config user.name获取user.name。您还可以指定选项--system、--global、--local以在特定级别读取该值。


参考:1.6入门-首次安装Git


要查找所有配置,只需编写以下命令:

git config --list

在本地,我运行此命令。

Md Masud@DESKTOP-3HTSDV8 MINGW64 ~
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
user.email=infomasud@gmail.com
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f

git-config有一点很重要:

gitconfig有--local、--global和--system级别以及相应的文件。

因此,您可以使用git-config-local、git-config-global和git-config-system。

默认情况下,如果未传递任何配置选项,git-config将写入本地级别。本地配置值存储在存储库的.git目录中的文件中:.git/config

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

系统级配置应用于整个机器。这包括操作系统上的所有用户和所有存储库。系统级配置文件位于系统根路径之外的gitconfig文件中$(前缀)/etc/gitconfig。在Windows上,此文件可以在C:\ProgramData\Git\config中找到。

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

或者可以使用git-config--global--list。

这正是你需要的。


从Git 2.26.0开始,您可以使用--show scope选项:

git config --list --show-scope

示例输出:

system  rebase.autosquash=true
system  credential.helper=helper-selector
global  core.editor='code.cmd' --wait -n
global  merge.tool=kdiff3
local   core.symlinks=false
local   core.ignorecase=true

它可以与

--本地用于项目配置,--全局用于用户配置,--系统用于所有用户的配置--显示原点以显示配置文件的确切位置


在Windows中,要编辑全局配置,请从gitbash运行(但不从常规命令提示符运行)

notepad ~/.gitconfig

文件的位置列在https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Where-system-global-and-local-Windows-Git-config-files-are-saved


要列出全局Git配置:

git-config--list--全局

要列出本地git配置:

git-config--list--本地