Git修改和配置用户名和邮箱

 

git在push/push to时需要使用到user.name和user.email,切记一定要现配置好
查看user.name/user.email

git config user.name
git config user.email

查看所有配置信息
git config --list
配置user.name/user.email

git config user.name "newName"
git config user.email "newEmail"

加上--global可以全局修改,否则仅在本git-repo生效。
配置全局user.name/user.email

git config --global user.name "your user name"
git config --global user.email "your user email"

这里需要注意的是,该命令只能用于初次配置user.name/email,如果不小心配置错误,或者重复配置,不可以通过重复执行以上命令来修改user.name/email,否则可能或报错说无法重复配置,或者导致一个key配置了多个value。
修改user.name/user.email
如果想要修改已经配置过的user.name或email,有两种方式,一种是通过git bash来修改;一种是直接修改.gitconfig文件。

1. git bash

git config --global --replace-all user.name "your user name"
git config --global --replace-all user.email"your user email"

2. 修改.gitconfig文件


该文件是隐藏文件,位于C:Users{user}.gitconfig,直接修改里边的name或者email,如果有重复的name或email,可以将其删掉,只剩下一个就好。
修改完,通过git bash输入git config –list可以查看是否修改成功了。
修改最近一次commit的user.name/user.email

git commit --amend --author="userName <userEmail>"

注意不能缺少< >
此指令仅能更新最近的一次commit的用户名邮箱

原文地址:https://www.cnblogs.com/onesea/p/13201661.html