问题
进入新公司用的是上一个开发在使用的电脑,git 提交时显示的他的用户名和邮箱所以想改下。
概述:
git 可以设置系统的配置文件(用户名和邮箱),也可以设置全局的配置文件(用户名和邮箱),以及为仓库单独设置配置文件(用户名邮箱)。「我目前公司使用的电脑里面的项目就是使用仓库单独设置的,开始我修改了全局的,但在提交后发现还是没有变,很是奇怪,最后发现还可以为仓库单独设置。」
查看用户名和邮箱
git config --[system][global][local] user.name
git config --[system][global][local] user.email
//这里以查看 system 为例
git config --system user.name
修改用户名和邮箱
git config --[system][global][local] user.name "your name"
git config --[system][global][local] user.email "your email"
这三者的区别和使用
这三者的配置文件的权重不同,local > global > system。在值发生冲突时,比如 local 定义了 user.name ,global 也定义了 user.name 。优先使用权重大的 local 中设置的值。
git 配置的其他操作
查看配置文件
git config --[system][global][local] -[list][l]
//-list 可以简写为 -l
编辑配置文件
git config --[system][global][local] -[edit][e]
//-edit 可以简写为 -e
添加一个配置项
git config --[system][global][local] --add section.key value
//例子
git config --local --add my.name qinlei
获取一个配置项
git config --[system][global][local] --get section.key
//以获取上面的 my.name 为例
git config --local --get my.name
![](https://img.haomeiwen.com/i2235135/dab99c07c8022d35.jpg)
网友评论