“Author identity unknown *** Please tell me who you are” 是新装 git 的第一道坎。这篇在本机把它复现出来,发现在这台 macOS 上不设 user.useConfigOnly 的话 git 其实会自动猜出身份并提交;再把几处配置的优先级、按目录切换身份和配错之后的补救逐个测一遍。
$ git commit -m first 2>&1 | head -8; git log --format='作者 %an <%ae> | 提交者 %cn <%ce>' -1
[main (root-commit) 478c6eb] first
Committer: <登录名> <<登录名>@<主机名>>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
作者 <登录名> <<登录名>@<主机名>> | 提交者 <登录名> <<登录名>@<主机名>>
$ git config user.useConfigOnly true; git commit -m first (退出码 128)
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
$ git var GIT_AUTHOR_IDENT 2>&1 (退出码 128)
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
$ git -c user.useConfigOnly=false var GIT_AUTHOR_IDENT 2>&1; hostname
<登录名> <<登录名>@<主机名>> 1767196800 +0800
<主机名>没配身份且无法自动猜、或者设了 user.useConfigOnly=true 时;这台机器上默认能自动猜。
git add 退出码 0 OK git log 退出码 0 OK git commit 退出码 128 Author identity unknown git tag(轻量) 退出码 0 OK git tag -a 退出码 128 Committer identity unknown git stash 退出码 0 OK git revert 退出码 128 Author identity unknown git branch 退出码 0 OK
commit、revert、tag -a 要;add、log、轻量 tag、branch、stash 不要。
$ git config --show-origin --get-all user.email | sed "s#<tmp>#<tmp>#"; git config --show-origin --get-all user.name | sed "s#$HOME#~#"
file:<tmp>/_home/gitconfig global@example.com
file:.git/config repo@example.com
file:~/gitconfig GlobalName
file:.git/config RepoName
只有全局 + 仓库配置:
作者 RepoName <repo@example.com> | 提交者 RepoName <repo@example.com>
再加环境变量 GIT_AUTHOR_NAME / GIT_COMMITTER_EMAIL:
作者 EnvAuthor <repo@example.com> | 提交者 RepoName <env-committer@example.com>
同时有 GIT_AUTHOR_NAME=EnvAuthor 和 -c user.name=CliName:
作者 EnvAuthor <repo@example.com> | 提交者 CliName <repo@example.com>
--author 指定:
作者 Other <other@example.com> | 提交者 RepoName <repo@example.com>全局 < 仓库 < -c < 环境变量,作者和提交者各自独立,--author 只改作者。
在 work/proj 里提交:作者 Me <me@company.example> | 提交者 Me <me@company.example>
在 personal 里提交:作者 Me <me@personal.example> | 提交者 Me <me@personal.example>
$ git config --show-origin --get-all user.email | sed "s#<tmp>#<tmp>#"
file:<tmp>/_home/gitconfig me@personal.exampleincludeIf gitdir 条件配置。
$ git log --format='%h %an <%ae> %s'
08506a7 Wrong <wrong@example.com> c3
9d42fc5 Wrong <wrong@example.com> c2
aeb44a3 Wrong <wrong@example.com> c1
$ git config user.name Right; git config user.email right@example.com; git commit -q --amend --reset-author --no-edit; git log --format="%h %an <%ae> %s"
fedd650 Right <right@example.com> c3
9d42fc5 Wrong <wrong@example.com> c2
aeb44a3 Wrong <wrong@example.com> c1
$ git rebase -q -r --root --exec "git commit -q --amend --reset-author --no-edit" 2>&1 | tail -2; git log --format="%h %an <%ae> %s"
24f0e89 Right <right@example.com> c3
d1d18f9 Right <right@example.com> c2
65d1ab9 Right <right@example.com> c1
空字符串的身份:
$ git config user.name ""; git commit -q --allow-empty -m e 2>&1 | tail -2
fatal: empty ident name (for <right@example.com>) not allowedamend --reset-author 改最近一次;rebase --exec 改一串,哈希都会变。