赞
踩
话说
各位读者盆友,下午好!这篇博客发表之前,应该是对Git有一定的了解,了解到什么程度呢?
eg: 环境搭建、Git基本工作原理、clone代码、pull push代码、处理冲突、新建与切换分支、Merge代码……
笔者会陆续详细或者简略表达一个命令或者一串命令,有什么意义呢?好玩,搞清楚究竟是怎么回事,如此而已。
目录
一、git config什么时候用到?
二、哪些地方会跟git config有关?3个作用域指定的配置文件到底在哪?如果配置冲突,优先级呢?
三、总结
难度系数:★☆☆☆☆
建议用时:30min
一、git config什么时候用到?
下载Git后,要初始化Git,指定用户名和邮箱,才有权限clone代码。
二、哪些地方会跟git config有关?3个作用域指定的配置文件到底在哪?如果配置冲突,优先级呢?
git config -e [–global]
git config -e [–system]
git config -e [–local或者–repository]
-e, –edit
Opens an editor to modify the specified config file; either –system, –global, or repository (default).
以上三者有何区别?我们help一下
git config --help
--global
For writing options: write to global ~/.gitconfig file rather
than the repository .git/config, write to $XDG_CONFIG_HOME/
git/config file if this file exists and the ~/.gitconfig file
doesn't.
--system
For writing options: write to system-wide
$(prefix)/etc/gitconfig rather than the repository .git/config.
For reading options: read only from system-wide
$(prefix)/etc/gitconfig rather than from all available
files.
--local
For writing options: write to the repository .git/config file.
This is the default behavior.

看3张图就明白了:
git config -e 不指定作用域,默认编辑哪个呢?默认编辑本地
等同于:
git config -e --local 或 git config -e --repository
这个路径在本地,也就是你clone项目主目录第一层的.git/config文件
git config -e --global
全局配置在电脑家目录下面的~/.gitconfig文件里。
git config -e --system
系统配置文件在:/usr/local/git/etc/gitconfig里面
好,以上三个总结完毕。
说道这里,那么git config –list 又是怎么回事呢?
原来,git config –list就是
git config git config -e –lcoal git config -e –repository
git config -e –global
git config -e –system
的整合,你会发现git config –list整体分为三部分做展示
所以修改user.name和user.email就有多种方式,最简洁的是:
法一:
git config --global user.name "your userName"
git config --global user.email "your email"
法二:
当然也可以直接编辑:
git config -e --global
有没有想过,如果三种配置里面都设置了某个参数,那么最后生效的是哪种呢?它们之前的优先级为(由高到低):git config > git config –global > git config –system。
也就是作用域范围越广的优先级越低,相信这个不难理解。(摘抄,博客来源:https://www.daixiaorui.com/read/240.html)
三、总结
了解得越多,也就越熟悉,越有掌控感。
笔者很喜欢Git,觉得Git设计特别好,所以很喜欢研究它。虽然只是一款工具,觉得持续花费精力还是很值得的。
好了,再会! 后面还有一系列Git干货。期待吧~ .
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。