git configuration

git的配置文件结构

git的配置文件由section名和变量名组成

[user]

  name = abc

  emial = example.com

[]里面的user就是section名,section只能由字母,数字,-和.组成,并且不区分大小写;name和email是变量名,变量名只能是数字,字母和-组成,并且也不区分大小写。

当我们使用git config user.name "abc"来进行设置时,user.name就是由section名和变量名组合而成,由.分割开来。

git配置文件的subsection

1)在git的配置文件中,一个section可以由subsection,定义一个subsection有两种形式: [section "subsection"]和[section.subsection],区别是前者的subsection名区分大小写,而后者的subsection名不区分大小写。除了newline之外,任何字符都可以作为subsection名

2)定义了section后可以定义subsection,但是定义subsection时不是必须要定义section

git配置文件的类型

git的配置文件有3类,优先级从小到大依次为:

1) .git/config 这个配置文件定义的变量作用域是整个repository,使用git config --file操作这个文件,这也是git config命令默认操作的配置文件

2) ~/.gitconfig 这个配置文件定义的变量作用域是user,使用git config --global操作这个文件

3)/etc/gitconfig 这个配置文件定义的变量作用域是system,使用git config --system操作这个文件

git配置文件变量的定义,删除,查看

//配置文件变量的定义,注意变量名和值之间没有等号,而是用空格分隔
git config --global user.name "lucy"

//配置文件变量的删除
git config --global --unset user.name

//配置文件变量的查看,这里不是仅列出.git/config下的变量,而是列出全部配置文件下的变量
//不同配置文件中的同名变量都会被列举出来
git config -l

定义别名

git config命令的另一个作用就是定义别名:

//注意别名的值用引号包围,并且别名和值之间没有等号,而是用空格分隔
git config --global alias.show-graph "log --graph --abbrev-commit --pretty=oneline"
原文地址:https://www.cnblogs.com/chaoguo1234/p/5323083.html