Git 中的“无法获取您的身份”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25414599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:19:13  来源:igfitidea点击:

"Unable to obtain your identity" error in Git

git

提问by user3361043

I set up user.email and user.name successfully, but whenever I try to commit to a repo Git still displays an error saying that it can't recognize my identity. What could be wrong?

我成功地设置了 user.email 和 user.name,但是每当我尝试提交到一个 repo Git 仍然显示一个错误,说它无法识别我的身份。可能有什么问题?

This is what git config --listcommand prints out:

这是git config --list命令打印出来的:

user.name=myname
[email protected]
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Edit:Error reads Unable to obtain your identity: *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set identity only in this repository. fatal: unable to auto-detect email address (got 'root@computername.'(none))

编辑:错误读取Unable to obtain your identity: *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set identity only in this repository. fatal: unable to auto-detect email address (got 'root@computername.'(none))

cat ~/.gitconfigcommand outputs this:

cat ~/.gitconfig命令输出这个:

[user]
    name = myname
    email = [email protected]

cat .git/configoutputs this:

cat .git/config输出这个:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[gui]
    wmstate = normal
    geometry = 1855x1026+65+24 262 188

回答by phihag

You are running git with sudo. In a sudo environment, $HOMEand therefore the git configuration will not be present. Run git without sudo.

你正在运行 git sudo。在 sudo 环境中,$HOME因此不会出现 git 配置。运行 git 没有sudo.

For the interested, here's how to reproduce the problem:

对于感兴趣的人,这里是重现问题的方法:

$ mkdir repo
$ cd repo
$ git init
Initialized empty Git repository in /home/phihag/repo/.git/
$ git config --global user.email "[email protected]"
$ git config --global user.name "My Name"
$ sudo git commit -m first

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  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: unable to auto-detect email address (got 'root@t4.(none)')

Notice the root@in the automatically detected email address.

请注意root@自动检测到的电子邮件地址中的 。

回答by JingYi

cd your project
git config --local user.name "your name"
git config --local user.email "your email"

I made it.

我做到了。

回答by rahul gowda

1-open your git terminal

1-打开你的git终端

2-enter git config --listin your git bash

2-在你的 git bash 中输入 git config --list

3-it displays your complete git data

3-它显示你完整的git数据

4- check your

4-检查你的

user.name= your name

用户名=你的名字

user.email=your email id

user.email=您的电子邮件 ID

5- if data is not correct update it using

5-如果数据不正确更新它使用

git config --local user.name "your username"

git config --local user.name "你的用户名"

git config --local user.email "your email"

git config --local user.email "你的邮箱"

回答by Sudhanshu Bhatia

Open the cmd go to your GIT repo

打开 cmd 转到您的 GIT 存储库

cd your project
git config --global user.email "your email registered with GIT"
git config --global user.name "your GIT user name"

Keep the spaces as it is. Otherwise, it will through the same error.

保持空格不变。否则,它会通过同样的错误。