开发者

More than one value for the key user.name Git

开发者 https://www.devze.com 2023-01-28 02:09 出处:网络
For some re开发者_StackOverflowason 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?If yo

For some re开发者_StackOverflowason 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?


If you just want to reset all of them:

git config --global --replace-all user.email "new@mail.com"


Update (December 2012)

git1.8.1rc1 now operates differently:

"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.

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


Original answer (November 2010)

The git config man page mentions:

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

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

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.name value needs to be fixed.


From the comments:

Examining files "local", "global" and "settings" I can see only one user.name in global.
But git config --list and git config --get-all user.name gives it twice to me

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

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.


You should examine the contents of ~/.gitconfig (your user-global config) as well as .git/config in the repository in question (the repo-specific config). You should see two name lines under a user section 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.

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 --global for 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.


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.autocrlf and unwanted C:\\ProgramData/Git/config file:

$ 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   user.email=john.doe@somemail.com
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 --system and --global to check where your gitconfig files are located:

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

Example output:

file:C:/Users/john.doe/.gitconfig   user.name=John Doe
file:C:/Users/john.doe/.gitconfig   user.email=john.doe@somemail.com
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


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

Go to your application directory

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

Open file config file

It will show some lines like

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

Replace those line with

[user]
    name = username
    email = user@test.com


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

git config --list

Example output:

user.email=abarker@cern.ch
user.name=fiveisgreen
user.github=fiveisgreen
user.name=Anthony

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

git config --global --unset user.name


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.

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!


Show/Replace/Remove/Add Keys to git config

First check your config as

git config --list

Then if you have multiple values against on key then you have to

#git config --replace-all git_key_name git_key_value
# real example
git config --replace-all credential.helper store

Once you have only one value against a key, the key can be removed as well

#git config --unset git_key_name
# real example
#git config --unset credential.helper

Any time later you can add any key again or new one just by

git config git_key_name git_key_value


I faced the same issue. Here is how I fixed it.

First, check how many user.name or user.email fields do you have in config: (in my case I had 4 to 5 user.name and user.email fields)

git config --list

Example output:

user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==

Now go to your C:\Users[Your PC User Name] and search for the file .gitconfig (It is a hidden file. Make sure to enable view hidden files option).
After finding the file open it. Now remove all the duplicate fields of user.name and user.email.

You can now either set your user.name and user.email with code

git config --global user.name "Ali"
git config --global user.email "Abc@gmail.com"

or either type your user.name= Ali and user.email=abc@gmail.com manually in the .gitconfig file.


warning: user.name has multiple values

To change the user.name:

git config --global --replace-all user.name Mohammad

To check your Current Username or Email:

git config --global user.name


git config --global user.email
0

精彩评论

暂无评论...
验证码 换一张
取 消