需配置 user.name 和 user.email,执行 git config --global user.name "your name" 与 git config --global user.email "you@example.com" 即可解决。

git commit 报 “Author identity unknown” 怎么办
直接原因是 user.name 和 user.email 都没设,Git 拒绝写入 commit 对象。这不是警告,是硬拦截,不配好就根本提交不了。
最简解决路径就是两条命令:
git config --global user.name "Your Name"git config --global user.email "you@example.com"
设完后执行 git commit --allow-empty -m "test" 验证是否真通过。别只看命令回显,要实际走一遍提交流程。
常见漏配点:
- 在 Git Bash 里配了,但 VS Code 终端启动的是 PowerShell —— 它可能读不到同一份
~/.gitconfig,尤其当设置了GIT_CONFIG_GLOBAL环境变量时 - Windows 上装了 GitHub Desktop 自带的 Git,PATH 里指向的是它,而你配置的是另一个 Git 的配置文件
- 复制命令时把
--global写成--gloabal(拼错)或用了中文引号
全局配置和当前仓库配置冲突了怎么办
Git 查配置的顺序是:.git/config(当前仓库)→ ~/.gitconfig(全局)→ /etc/gitconfig(系统)。后加载的覆盖先加载的,所以本地配置永远优先于全局。
比如你在公司项目根目录执行过:
git config user.name "Work Name"git config user.email "work@company.com"
那这个 repo 就会一直用工作信息,哪怕全局配的是个人邮箱。这本身是设计行为,不是 bug。
检查当前生效值,别猜:
- 查当前仓库实际用的:
git config user.name和git config user.email - 查全局设置来源:
git config --global --get-all user.email - 想看所有配置从哪来:
git config --list --show-origin(关键!能直接告诉你哪行值来自哪个文件)
邮箱填错导致 GitHub 显示 “ghost” 提交怎么补救
GitHub/GitLab 不校验邮箱真实性,只比对 commit 里的 user.email 字符串和你账户绑定的邮箱是否完全一致(包括空格、大小写、前后空白)。填错一个空格,头像就变灰色 “ghost”。
新提交立刻修正:
- 改全局邮箱:
git config --global user.email "correct@example.com"(直接赋新值,不用--replace-all) - 改当前仓库邮箱:
git config user.email "correct@example.com"
已提交但还没 push:
- 改最后一次:
git commit --amend --author="Correct Name <correct>" --no-edit</correct> - 改最近 N 次:
git rebase -i HEAD~N,把要改的行标为edit,再逐条git commit --amend --author=...
已经 push 出去了?别急着 git push --force。先确认协作者是否已拉取;如果只是自己 fork 的仓库,或者团队约定可重写历史,再用 --force-with-lease。
VS Code 里提交还是显示旧用户名,是不是编辑器设置没改对
VS Code 的 Git 功能完全依赖系统 PATH 中的 git 命令,它读的是 Git 自己的配置,不是 VS Code 设置里的 git.user 或类似字段 —— 那些选项根本不存在,搜也白搜。
正确排查步骤:
- 在 VS Code 内置终端里运行
which git(Linux/macOS)或where git(Windows),确认调用的是哪个 Git - 在同一终端里运行
git config --global user.name,看输出是否是你期望的值 - 如果值为空或不对,就当场执行配置命令;设完后必须重载窗口(
Ctrl+Shift+P→Developer: Reload Window),否则 VS Code Git 扩展可能缓存旧状态
Windows 用户特别注意:Git Bash 默认写入 C:\Users\XXX\.gitconfig,但 PowerShell 可能因 $HOME 环境变量不同而读错位置。统一用 git config --list --show-origin 定位最稳。











