方法一命令行
在项目根目录打开 cmd 或者 powershell
# 设置当前项目(本地)提交名
git config --local user.name "你的名字"
# 设置当前项目(本地)邮箱
git config --local user.email "你的邮箱@公司.com"验证是否生效
# 查看当前项目配置(带 --local 只看本地)
git config --local user.name
git config --local user.email
# 对比全局配置
git config --global user.name关键区别
表格
Git 提交时优先使用 本地(local) 配置,覆盖全局。
方法二:直接改配置文件
在项目根目录下:
# 编辑 .git/config
vim .git/config添加用户配置:
[user]
name = 你的名字
email = 你的邮箱@公司.com快速检查当前项目用的哪个用户
git config --show-origin user.name
git config --show-origin user.emailfile:.git/config 张三 ← 本地配置生效
file:C:/Users/xxx/.gitconfig 李四 ← 全局配置被覆盖