git的config学习
转自:https://www.cnblogs.com/fireporsche/p/9359130.html
https://www.panyanbin.com/article/ff4e1f85.html
1.三种类别
- 仓库级别 local 【优先级最高】
- 用户级别 global【优先级次之】
- 系统级别 system【优先级最低】
系统级别的配置优先度最低,其配置值可被用户级配置和本地级配置的值覆盖。一般我们很少会使用系统级的配置。
local本地级别优先级别最高,如果全局级别或系统级别的配置里出现了同一配置项,则以本地级别配置内容为准。
2.操作
2.1 文件
git 仓库级别对应的配置文件是当前仓库下的.git/config, 这个查看命令需要在一个仓储下才能进行,否则会报错,其他两个不用。
yproj % git config --local --list core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true core.precomposeunicode=true remote.origin.url=git@deMacBook-Pro-2.local:/Users/git/myproj/myproj.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master user.name=bg pull.rebase=false
git 用户级别对应的配置文件是用户宿主目录下的~/.gitconfig,可通过命令git config --global -l查看用户配置,
~ % cat .gitconfig [safe] directory = /opt/homebrew/Library/Taps/homebrew/homebrew-core directory = /opt/homebrew/Library/Taps/homebrew/homebrew-cask
git config --system -l 查看系统配置,
~ % git config --system -l
credential.helper=osxkeychain
2.2 编辑命令
git config --local -e //编辑仓库级别配置文件 git config --global -e //编辑用户级别配置文件 git config --system -e //编辑系统级别配置文件
3.配置项操作
添加:
git config [--local|--global|--system] --add section.key value // (默认是添加在local配置中)
add后面的section,key,value一项都不能少,否则添加失败。
获取:
获取某一项配置时若不指定级别,则会从本地级开始一级一级往上查找直到配置不存在。
git config [--local|--global|--system] --get section.key //(默认是获取local配置中内容)
删除:
git config [--local|--global|--system] --unset section.key
查询时git config --list,如果不指定级别,那么从上到下是系统级、用户级、仓储级。
例如指定要提交的邮箱,
git config --global user.email "YOUR_EMAIL" #查看设置的邮箱 git config --global user.email