如何在配置名称时修复git中的多值错误?


$ git config --global user.name "Amritjyot Singh"
warning: user.name has multiple values
error: cannot overwrite multiple values with a single value
Use a regexp, --add or --replace-all to change user.name.

如何使用regexp来解决这个问题?

我试了git config—global user.name "Amritjyot Singh"期望在git bash中配置我的名字,但是这个错误显示

由于某种原因,您有多个user.name配置密钥。使用:

将它们全部删除
git config --global --unset-all user.name

然后重新设置:

git config --global user.name "Your Name"

查看配置参数的不同值在哪里定义:

$ git config --show-origin --get-all user.name
# sample output:
file:/home/wwhite/.gitconfig   Walter White
file:.git/config  Heisenberg

如果您看到来自单个文件的多个值:

file:/home/jack/.gitconfig   Jack
file:/home/jack/.gitconfig   Tyler Durden

  • 使用常规文本编辑器编辑上述配置文件,并删除错误值,
  • 或使用:
git config [correct scope] --replace-all user.name "My Name"

其中[correct scope]可能是--global(如果源是$HOME/.gitconfig)或--local(<-如果源是.git/config,则与空字符串相同)。

运行git config --global -e命令编辑全局配置文件。根据警告和错误消息,有多个这样的值

[user]
name = foo

找到所有的,留下一个,除去其他的。