GIT 在Commit时 提示 Author identity unknown的解决方案

Posted 铁憨憨的小小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GIT 在Commit时 提示 Author identity unknown的解决方案相关的知识,希望对你有一定的参考价值。

git 执行 报错 Author identity unknown,是因为用户信息配置错误导致的

GIT 在Commit时 提示 Author identity unknown的解决方案

一、发生事件

在git 新建 commit时 提示 Author identity unknown

二、提示代码

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: unable to auto-detect email address (got \'xxx@xxx.(none)\')

三、解决方案

//直接执行提示的代码
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
即可解决

四、其它问题

1,执行了还是提示之前的错误(我真实出现的)

//确认 user.name 、 user.email 这两个参数名是否正确,我就是把 user.email 打成 user.mail 导致的
//执行代码查看信息,确认信息对不对,即可解决
git config --global -l

2,删除配置信息代码

//例子
git config --global --unset user.mail

//说明
git config --global --unset [用户参数名]

如何修改git commit的author信息

本地有多个git账号时,容易发生忘记设置项目默认账号,最后以全局账号提交的情况,其实对代码本身并无影响,只是提交记录里显示的是别的名字稍显别扭。

举个例子:  查看提交日志,假设以a([email protected])提交了三次,发现提交用户错了,应该用b用户提交:

$ git log
# 输出如下
commit 3 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 3
commit 2 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 2
commit 1 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 1


一、如何重置本项目用户信息

$ git config user.name ‘b‘
$ git config user.email [email protected]

 

二、使用amend命令修改commit信息(注: amend命令只会修改最后一次commit的信息,之前的commit需要使用rebase)

$ git commit --amend --reset-author

 

三、如果需要修改历史提交消息,通过rebase操作

$ git rebase -i HEAD~3        // 这个命令如果报错,请翻我博客,有解决方法

# 输出如下
pick 1 commit 1
pick 2 commit 2
pick 3 commit 3
要修改哪个,就把那行的pick改为edit,然后退出。例如想修改commit 1的author,光标移到第一个pick,按i键进入INSERT模式,把pick改为edit:

edit 1 commit 1
pick 2 commit 2
pick 3 commit 3
...
-- INSERT --
然后按esc键,退出INSERT模式,输入:wq退出,这时可以看到提示,可以修改commit 1的信息了:

技术图片

输入amend命令重置用户信息:  $ git commit --amend --reset-author

会出现commit 1的提交记录及注释内容,可进入INSERT模式修改注释,:wq退出。

这时再查看提交历史,发现commit 1的author已经变成b([email protected])了,且是最新一次记录。

通过continue命令回到正常状态: $ git rebase --continue

 

以上是关于GIT 在Commit时 提示 Author identity unknown的解决方案的主要内容,如果未能解决你的问题,请参考以下文章

为Git commit 签名

git push 时:报missing Change-Id in commit message footer的错误

text 批量更改git commit author

sh 为单个存储库设置git commit author

Git commit时提示错误时    解决办法

Git远程仓库 复制到另一个远程仓库 并保留commit信息。关于Git代码提交到远程仓库怎么撤回。.gitignore。git pull 时提示为何需要merge操作如何退出