一、概述
Git
的默认配置信息保存在~/.gitconfig
文件下,初始化的时候为空,根据需要添加。
二、配置用户信息
用户信息就相当于QQ或是微信里的用户名一样,标志用户的身份。
需要配置的是name
和email
:
git config --global user.name "maqian"
git config --global user.email maqian@dyxmq.cn
注意--global
选项,如果不带--global
选项,配置就只对当前的项目有效,配置文件位于当前项目目录下的.git/config
文件中。
需要初始化仓库后才能使用,此时如果没有在当前目录创建仓库,将会报错:
fatal: not in a git directory
三、其他配置
1.系统环境默认编辑器是nano
,不太适合个人习惯,指定默认文本编辑器vim
:
git config --global core.editor vim #也可以是emas或是其他
2.差异分析工具,git diff
时用到的,默认就是vimdiff
git config --global merge.tool vimdiff
3.修改颜色配置
git config --global color.ui true
四、查看配置
配置设置好之后,可以直接打开配置文件查看配置:
cat ~/.gitconfig
结果如下:
也可以使用命令查看配置:
git config --list
如果指定了当前当前项目配置,会把~/.gitconfig
和./.git/config
中的配置都显示出来,当前项目下的配置会在下面,优先级高。
ma@pc:/data/git_data/proj$ git config --list
user.name=maqian
user.email=maqian@dyxmq.cn
color.ui=true
core.editor=vim
merge.tool=vimdiff
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
此处评论已关闭