我在不同的机器上使用Git,使用不同的用户名。有时,在克隆存储库时,我会忘记配置user.name
和user.email
,并且当我提交第一个未指定身份名称的本地提交时,我会得到以下错误:
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:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
是的,Git说得很清楚为什么会这样。(如果我注意到了的话)但是,有没有可能抑制这种行为,让Git不传播我的用户名和主机名作为提交作者的用户名?我之所以问这个问题是因为我在
~/.gitconfig
中故意没有[user] name =
和[user] email =
:我只是为不同的存储库组使用不同的用户名和电子邮件,并且希望Git能够在无法从配置中获取用户名和电子邮件时中止提交。最糟糕的是,我配置了一个自定义的Git通知PS1
,正确显示当前存储库的用户名和电子邮件,因为我之前进行过历史重写和强行推送,甚至没有注意到巨大的Git警告来提醒默认的用户名。如果我没有全局指定
user.name
和user.email
,是否可以中止Git提交?(我想这可以通过钩子来修复,但钩子仅限于本地,对吧?)
PS1
...谢谢! - Lyubomyr Shaydariv.gitconfig
中的user =
和email =
没有值(我的意思是=\n
)并且没有被注释掉,那么user.useConfigOnly
似乎不起作用。 - Lyubomyr Shaydariv