必须用命令行配置,vscode设置里改git.user.name无效;执行git config --global user.name "your real name"和git config --global user.email "you@company.com",再运行git config --global --list验证,并重启vscode或执行developer: reload window刷新缓存。

必须用命令行配,VSCode 设置里改 git.user.name 无效。 VSCode 的 Git 功能调用的是系统安装的 git 命令,它只读 .gitconfig 文件,不认编辑器里的设置项。你在 VSCode 设置里填了 git.user.name 和 git.user.email,提交时照样报错 *** Please tell me who you are。
怎么配全局账号(命令行实操)
打开 VSCode 内置终端(Ctrl+`),或系统终端,执行这两条:
git config --global user.name "Your Real Name"git config --global user.email "you@company.com"
注意:"Your Real Name" 不要带空格引号(Windows cmd 下可能需要),邮箱必须是你在 GitLab/GitHub 绑定的、能触发头像和权限匹配的那个邮箱。设完后运行 git config --global --list 确认输出里有这两项。
为什么改完 VSCode 还不认?
常见卡点不是命令没跑,而是 VSCode 没刷新 Git 配置缓存:
- VSCode 启动时会缓存一次 Git 配置,改完
.gitconfig后不重启,Source Control 面板仍显示旧信息 - 必须执行
Ctrl+Shift+P→ 输入Developer: Reload Window重载窗口,或直接关掉再开 - 别信“Git: Config”命令面板选项——它只是写进
settings.json,不影响真实提交
公司和个人项目混用,怎么避免邮箱串号?
全局配置只是兜底,真正起效的是项目级配置。如果你同时维护公司项目(用企业邮箱)和个人开源项目(用 Gmail),光设全局会全打错:
- 进公司项目根目录,运行:
git config --local user.email "you@corp.com" - 进个人项目根目录,运行:
git config --local user.name "Your Nickname"和git config --local user.email "you@gmail.com" - 检查
.git/config文件末尾是否新增了[user]区块,有就对了 - VSCode 提交时自动读这个,不用额外操作
如果项目太多,推荐用 includeIf 自动分流,但路径必须是绝对路径、结尾带 /,且 Git 版本 ≥ 2.13 —— 老版本 Windows 用户容易在这儿失败。
最容易被忽略的一点:改完邮箱后,历史 commit 不会自动更新。刚提交一两条就发现错了,用 git commit --amend --author="Name <email>"</email> 补救;已经 push 过,就得走 git push --force-with-lease,协作者正在拉取时强制推送会丢数据。











