Can't change git config's user.name, gets reset immediately

守給你的承諾、 提交于 2021-01-04 17:37:15

问题


If I do:

 git config --global user.name "My New Name"

It works, for a short while. If I do this:

cat ~/.gitconfig

I can see the proper value in the user.name property.

However, as soon as I open a new terminal window or do a git commit, the old name gets reset.

I'm using ssh. Is there some cache mechanism?

(Note this is not about the GitHub username, but rather about the author name for every commit)


回答1:


The FILES section of the git config documentation shows sources of configuration values.

If not set explicitly with --file, there are four [or five] files where git config will search for configuration options:

  1. $(prefix)/etc/gitconfig
    System-wide configuration file.
  2. $XDG_CONFIG_HOME/git/config
    Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.
  3. ~/.gitconfig
    User-specific configuration file. Also called "global" configuration file.
  4. $GIT_DIR/config
    Repository specific configuration file.
  5. $GIT_DIR/config.worktree
    This is optional and is only searched when extensions.worktreeConfig is present in $GIT_DIR/config.

As to their precedence

The files are read in the order given above, with last value found taking precedence over values read earlier. When multiple values are taken then all values of a key from all files will be used.

In the case where you modify a repository’s config with git config or git config --local (which will modify $GIT_DIR/config, so either .git/config for a repo with a work tree or config in a bare repo), and changes through git config --global (stored in ~/.gitconfig) will be invisible inside that repository.

For a quick sanity check, run two commands.

git config --global user.name
git config --local  user.name



回答2:


I had a shell script that was overriding the global ~/.gitconfig. Specifically, this .extra file from Mathias Bynens' dotfiles.

See this GitHub issue for more details.



来源:https://stackoverflow.com/questions/57998652/cant-change-git-configs-user-name-gets-reset-immediately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!