git:致命错误,无法自动检测电子邮件地址

156

我在Ubuntu 14.04上无法使用git提交代码

错误信息如下:

git: 致命错误:无法自动检测电子邮件地址(获取到“一些错误的电子邮件地址”)

我尝试使用git-config命令设置了user.name和user.mail选项,包括使用--global参数和不使用,但都没有起作用。


可能是重复的问题:为什么 Git 在配置后仍不允许我提交? - Chris
19个回答

227

很可能是一个笔误:将user.mail设为无e。通过在全局配置中设置user.email来修复它。


$ git config --global user.email "you@example.com"

已经有人问过了:为什么在配置后 Git 仍然不允许我提交?

为确定起见,请运行:

$ git config --local -l

11
奇怪,对吧?有多少人会犯同样的打字错误。 - Vitaly Sazanovich
4
关于这个问题,我有一个理论:我认为这是因为我们不是以英语为母语的缘故。对于我们大多数人来说,“mail”的意思是指其电子版本,所以不需要加上“e”,因此这是一个笔误 xDDDD。 - Jofe
2
好的。我刚刚点了赞。但现在我必须花整个一天的时间来寻找你把摄像头放在我的办公室哪里了。 - Almir Campos
在我的例子中,我输错了uers.email :) 你可以使用 git config -l 命令来查看那些不友好的配置项。 - Edgar Manukyan
@Jofe 这个答案帮了我很多。 谢谢,伙计 <3, - JIGNESH PATEL

53

确保在设置用户名和电子邮件地址时,您应该在主目录而不是本地目录中。

git config --global user.email "you@example.com"
git config --global user.name "github_username"

然后遵循 GitHub 上的步骤。


41

如果 git config --global user.email "you@domain.com" git config --global user.name "github_username" 不起作用,你可以尝试使用以下命令:

git config --replace-all user.email "you@domain.com"
git config --replace-all user.name "github_username"

4
最后这是唯一适用于我的解决方案。谢谢。 - Seeschon

21

致命错误:无法自动检测电子邮件地址(获取的是'jsiddharth@TheDEN.(none)')

我运行了以下命令:

git config --global user.email "myemailid@example.com"
git config --global user.name "my name"
repo init -u https://example.com/platform/manifest

11

运行git stash时,我遇到了这个错误。用以下方法解决:

git config --global user.email {emailaddress}
git config --global user.name {name}

6

我昨天遇到了这个问题。在我的解决方案中,先检查以下设置。

git config --global user.email "your_address_email@example.com"
git config --global user.name "your_name"

"user"代表笔记本电脑的用户。

例如:dias@dias-hp-pavilion$ git config --global dias.email ...

因此,请确认添加的信息,执行以下操作:

dias@dias-hp-pavilion:/home/dias$ git config --global dias.email
my_address_email@example.com
dias@dias-hp-pavilion:/home/dias$ git config --global dias.name
my_name

或者

nano /home/user_name/.gitconfig

请检查这些信息。

如果您已尝试并仍然存在错误,请尝试其他 Git IDE(GUI 客户端)。我曾使用 git-cola,但出现了此错误,因此我更换了 IDE,并且目前我使用 CollabNet GitEye


5

在我使用sudo运行这些命令后,问题得到了解决。


奇怪的解决方案。'git-config --global' 不涉及本地系统所有用户,而是涉及已登录用户的所有存储库和所有远程,参见 https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration: "Git 查找的下一个位置是 ~/.gitconfig (或 ~/.config/git/config) 文件,它是特定于每个用户的。您可以通过传递 --global 选项使 Git 读取和写入此文件。" 我建议不要使用 root 来运行 git,最好控制这些文件是否存在以及您是否有权编辑它们。 - Jochen Haßfurter

2

我遇到了类似的问题,虽然我还是个新手,但我需要先进入上级目录,设置用户名,然后再返回到git仓库所在的目录。

cd ..    
git config --global user.email "your_address_email@domain.com"
git config --global user.name "your_name"
cd <your repository folder>

希望这篇内容能帮助到那些遇到困难的人。

1
我正在通过Windows子系统的Linux运行Ubuntu,并已通过Git Bash正确设置了我的凭据,包括在VS Code的终端中(每次尝试提交时都会出现错误)。
显然,即使VS在终端中使用Bash,UI git控件仍然通过Windows运行,在那里我没有设置我的凭据。
在Windows Powershell中设置凭据解决了这个问题。

1
我刚遇到了同样的问题,我的问题在于没有注意到"user.email"和"your_address_mail@domain.com"之后的空格。
 git config --global user.email "your_address_email@domain.com"

我希望它能对您有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接