密钥 user.name Git 的多个值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4310974/
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-10 09:34:14  来源:igfitidea点击:

More than one value for the key user.name Git

gitgithub

提问by tshauck

For some reason I'm getting the error that "More than one value for the key user.name" when I try to set the user.name for my git account. How can I set it to a single name?

出于某种原因,当我尝试为我的 git 帐户设置 user.name 时,我收到错误消息“key user.name 有多个值”。如何将其设置为单个名称?

采纳答案by VonC

Update (December 2012)

更新(2012 年 12 月)

git1.8.1rc1now operates differently:

git1.8.1rc1现在以不同的方式运行:

"git config --get" used to diagnose presence of multiple definitions of the same variable in the same configuration file as an error, but it now applies the "last one wins" rule used by the internal configuration logic.

“git config --get”用于将同一配置文件中同一变量的多个定义的存在诊断为错误,但它现在应用内部配置逻辑使用的“最后一个获胜”规则

Strictly speaking, this may be an API regression but it is expected that nobody will notice it in practice.

严格来说,这可能是 API 回归,但预计在实践中没有人会注意到它。



Original answer (November 2010)

原始答案(2010 年 11 月)

The git config man page mentions:

git config 手册页提到:

The variable names are case-insensitive and only alphanumeric characters and - are allowed.
There can be more than one value for a given variable; we say then that variable is multivalued.

变量名称不区分大小写,并且只允许使用字母数字字符和 -。
一个给定的变量可以有多个值;我们说那个变量是多值的

Actually, such config settings (with multiple possible values) are called multivar

实际上,这样的配置设置(具有多个可能的值)称为multivar

As Jefromi suggests, see in what of the 3 config files you have more than one user.nameline.
You can query multiple values like so:

正如 Jefromi 所建议的那样,看看在 3 个配置文件中,你有多于user.name一行。
您可以像这样查询多个值:

git config --local  --get-all user.name #local repo git config file)
git config --global --get-all user.name #user config file)
git config --system --get-all user.name #system git config file)

The one config file which answers more than one user.namevalue needs to be fixed.

user.name需要修复回答多个值的一个配置文件。



From the comments:

来自评论:

Examining files "local", "global" and "settings" I can see only one user.namein global.
But git config --listand git config --get-all user.namegives it twice to me

检查文件“本地”、“全局”和“设置”我只能user.name在全局中看到一个。
git config --listgit config --get-all user.name给它两次我

As I mention in here with Git 2.8 (March 2016), you can use (to see allsettings:

正如我在Git 2.8 (March 2016) 中提到的,您可以使用(查看所有设置:

git config -l --show-origin

One you see where the duplicate setting is (local, global, system), you can use git config [--local/--global/--system] --replace-all key value, as in mb21's answer.

您可以看到重复设置的位置(本地、全局、系统),您可以使用git config [--local/--global/--system] --replace-all key value,如mb21答案

回答by mb21

If you just want to reset all of them:

如果您只想重置所有这些:

git config --global --replace-all user.email "[email protected]"

回答by Cascabel

You should examine the contents of ~/.gitconfig(your user-global config) as well as .git/configin the repository in question (the repo-specific config). You should see two namelines under a usersection in one of them. (It could also be two separate user sections in one file.) Just delete the one you don't want, and you should be good to go.

您应该检查~/.gitconfig(您的用户全局配置)以及.git/config相关存储库(特定于存储库的配置)的内容。您应该在其中name一个的user部分下看到两行。(它也可以是一个文件中的两个单独的用户部分。)只需删除您不想要的部分,就可以了。

You could also directly set it with git config --global user.name "Desired name"if you want it to be a global setting (probably the case), or the same minus the --globalfor a repo-specific setting - but it's probably best to inspect the files and find the culprit yourself, to make sure you know what you have. The repo-specific one will override the global one. Ideally you should set your name globally, and only override it in a project for a good reason.

git config --global user.name "Desired name"如果您希望它是全局设置(可能是这种情况),您也可以直接设置它,或者同样减去--globalrepo 特定设置 - 但最好检查文件并自己找到罪魁祸首,使确定你知道你有什么。特定于回购的将覆盖全局的。理想情况下,您应该全局设置您的名称,并且只有在有充分理由的情况下才在项目中覆盖它。

回答by Sumit Munot

You can manually change / edit user name and email for github

您可以手动更改/编辑 github 的用户名和电子邮件

Go to your application directory

转到您的应用程序目录

See all hidden files...In that go to .githidden folder

查看所有隐藏文件...进入.git隐藏文件夹

Open file config file

打开文件配置文件

It will show some lines like

它会显示一些像

[user]
    name = =
    name = =
    email = =

Replace those line with

将这些行替换为

[user]
    name = username
    email = [email protected]

回答by Schroeder

First look to see what user.names are in the config:

首先看看配置中的 user.names 是什么:

git config --list

Example output:

示例输出:

[email protected]
user.name=fiveisgreen
user.github=fiveisgreen
user.name=Anthony

In this example, user.name is listed twice. To remove the duplicate do:

在此示例中,user.name 列出了两次。要删除重复项,请执行以下操作:

git config --global --unset user.name

回答by luke

To debug such things you may use this command:

要调试此类事情,您可以使用以下命令:

git config --list --show-origin

It shows the origin file for each configuration entry.
Example output with duplicated core.autocrlfand unwanted C:\\ProgramData/Git/configfile:

它显示了每个配置条目的原始文件。
带有重复core.autocrlf和不需要的C:\\ProgramData/Git/config文件的示例输出:

$ git config --list --show-origin
file:"C:\ProgramData/Git/config"       core.symlinks=false
file:"C:\ProgramData/Git/config"       core.autocrlf=true
file:"C:\ProgramData/Git/config"       core.fscache=true
file:"C:\ProgramData/Git/config"       color.diff=auto
file:"C:\ProgramData/Git/config"       color.status=auto
file:"C:\ProgramData/Git/config"       color.branch=auto
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    diff.astextplain.textconv=astextplain
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    filter.lfs.clean=git-lfs clean -- %f
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    filter.lfs.smudge=git-lfs smudge -- %f
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    filter.lfs.required=true
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    filter.lfs.process=git-lfs filter-process
file:"C:\Program Files\Git\mingw64/etc/gitconfig"    credential.helper=manager
file:C:/Users/john.doe/.gitconfig   user.name=John Doe
file:C:/Users/john.doe/.gitconfig   [email protected]
file:C:/Users/john.doe/.gitconfig   core.preloadindex=true
file:C:/Users/john.doe/.gitconfig   core.fscache=true
file:C:/Users/john.doe/.gitconfig   core.autocrlf=input
file:C:/Users/john.doe/.gitconfig   gc.auto=256
file:.git/config        core.filemode=false
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.symlinks=false
file:.git/config        core.ignorecase=true
file:.git/config        core.autocrlf=input

You may do the same with --systemand --globalto check where your gitconfig files are located:

您可以使用--system--global检查您的 gitconfig 文件所在的位置:

git config --global --list --show-origin

Example output:

示例输出:

file:C:/Users/john.doe/.gitconfig   user.name=John Doe
file:C:/Users/john.doe/.gitconfig   [email protected]
file:C:/Users/john.doe/.gitconfig   core.preloadindex=true
file:C:/Users/john.doe/.gitconfig   core.fscache=true
file:C:/Users/john.doe/.gitconfig   core.autocrlf=input
file:C:/Users/john.doe/.gitconfig   gc.auto=256

回答by user3133732 Ver. 2.1

This thread helped me a great deal. Here is what I did to resolve a duplicate key entry in my global config settings. Windows 7. I searched for a file called .gitconfig which was located in /users/owner on my system. I edited it with a text editor (Atom) and removed the offending line.

这个线程对我帮助很大。这是我为解决全局配置设置中的重复键条目所做的工作。Windows 7。我搜索了一个名为 .gitconfig 的文件,该文件位于我系统的 /users/owner 中。我使用文本编辑器 (Atom) 对其进行了编辑并删除了违规行。

I believe the duplicate key was set when I inadvertently enclosed my email address in quotes while using the git config command, at least that's what my shell log indicates. Ooops!

我相信当我在使用 git config 命令时无意中将我的电子邮件地址用引号括起来时,设置了重复键,至少这是我的 shell 日志所指示的。哎呀!