一. 配置文件的存储位置
Git相关的配置文件有三个
1. /etc/gitconfig:包含了适用于系统所有用户和所有项目的值。
2.~/.gitconfig:只适用于当前登录用户的配置。
3. 位于git项目目录中的.git/config:适用于特定git项目的配置。
对于同一配置项,三个配置文件的优先级是1<2<3
二. 一些有用的配置项
1. 设置别名
[alias] 为git命令配置别名
例:
当你有了上述配置后,使用git st等同于使用git stauts
甚至有人丧心病狂的 设置 git lg 这种快捷方式:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
这样 git lg ,实际执行的是“
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
”,效果还是不错的。
2. 输出颜色
[color] 设置git输出着色
例:
设置color.ui
为true来打开所有的默认终端着色。
对比一下,无此配置时
加入配置后
3. core.filemode 让git忽略对文件权限的修改
4.使用vimdiff呈现Git diff差异
使用时只需将用到git diff的地方换为git d就可以了。
三. 用git config操作配置文件
1. 列出当前配置项
git config [–system|–global|–local] -l
使用system, golbal, local时,分别列出对应一部分中的1,2,3三个文件之一的配置项。
如果不加上述三个选项,则会按一部分中所说的优先级合并所有配置项并输出。
2.添加配置项
git config [–local|–global|–system] section.key value
例:
3.删除配置项
git config [–local|–global|–system] –unset section.key