问题
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 wheregit config
will search for configuration options:
$(prefix)/etc/gitconfig
System-wide configuration file.$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.~/.gitconfig
User-specific configuration file. Also called "global" configuration file.$GIT_DIR/config
Repository specific configuration file.$GIT_DIR/config.worktree
This is optional and is only searched whenextensions.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