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操作配置文件