More than one value for the key user.name Git

后端 未结 7 1018
再見小時候
再見小時候 2020-12-12 20:32

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 n

7条回答
  •  悲哀的现实
    2020-12-12 21:00

    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.

提交回复
热议问题