gpt4 book ai didi

git - 无法更改 git config 用户名,立即重置

转载 作者:行者123 更新时间:2023-12-04 02:44:03 24 4
gpt4 key购买 nike

如果我这样做:

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

它可以工作一小会儿。如果我这样做:

cat ~/.gitconfig

我可以在 user.name 属性中看到正确的值。

但是,只要我打开一个新的终端窗口或执行 git 提交,旧名称就会被重置。

我正在使用 ssh。有没有缓存机制?

(注意这不是关于 GitHub 用户名,而是关于每次提交的作者姓名)

最佳答案

FILES section of the git config documentation显示配置值的来源。

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.

关于它们的优先级

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.

如果您使用 git configgit config --local 修改存储库的配置(这将修改 $GIT_DIR/config ,所以要么 .git/config 用于带有工作树的 repo 或 config 在裸 repo 中),并通过 git config --global(存储在 ~/.gitconfig 中)将在该存储库中不可见。

要进行快速完整性检查,请运行两个命令。

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

关于git - 无法更改 git config 用户名,立即重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57998652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com