1

假设我做了一个回购

cd repo1
git init
git config user.name "Jack"
git config user.email jack@hill.com

然后我再做一个

cd ../repo2
git init
git config --global user.name "Jill"
git config --global user.email jill@hill.com

我会在 repo1 中成为 Jack 还是 Jill?如果这两个步骤以相反的顺序完成,我假设我将成为 repo1 中的 Jack?

4

1 回答 1

3

无论您运行命令的顺序如何,您都将成为 Jack inrepo1和 Jill in 。repo2git config手册页:

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

   $GIT_DIR/config
       Repository specific configuration file.

   ~/.gitconfig
       User-specific configuration file. Also called "global" 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.

   $(prefix)/etc/gitconfig
       System-wide configuration file.

Git 按该顺序加载这些文件。您的本地存储库的, .git/config, 优先于~/.gitconfig, 优先于$HOME/.config/git/config, 优先于/etc/gitconfig. 而且:

All writing options will per default write to the repository specific configuration file. Note that this also affects options like --replace-all and
--unset. git config will only ever change one file at a time.

--global标志不会更改.git/config您系统上的所有内容,只是~/.gitconfig.

于 2012-08-16T11:56:29.360 回答