好奇:git 在哪里存储用户信息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7328826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:57:46  来源:igfitidea点击:

curious: where does git store user information?

git

提问by goh

I'm wondering where does git stores user information. I created a repository, which both me and my friend works on. When we both commit, we can see both of us as individual authors for different revisions. while theres a .gitconfig file created using git config --globalin his home folder, I couldn't find one in mine. So where's my user information stored? Does git config --globalonly affect the individual login user?

我想知道 git 在哪里存储用户信息。我创建了一个存储库,我和我的朋友都在使用它。当我们都提交时,我们可以将我们视为不同修订版的单独作者。虽然git config --global在他的主文件夹中创建了一个 .gitconfig 文件,但我在我的文件夹中找不到。那么我的用户信息存储在哪里?是否git config --global只影响个人登录用户?

采纳答案by Bombe

If you do not store user information in your configuration files Git looks in the environment for committer information, using the variables GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, GIT_AUTHOR_NAME, and GIT_AUTHOR_EMAIL. In absence of these variables, your username and host name are used to construct a value. So even without any user information stored in configuration files two users will have different committer information.

如果没有存储用户信息在配置文件中Git会查找在提交者信息环境,使用变量GIT_COMMITTER_NAMEGIT_COMMITTER_EMAILGIT_AUTHOR_NAME,和GIT_AUTHOR_EMAIL。如果没有这些变量,您的用户名和主机名将用于构造一个值。所以即使没有任何用户信息存储在配置文件中,两个用户也会有不同的提交者信息。

回答by jweyrich

There are 3 default paths for the config file.

配置文件有 3 个默认路径。

  • Repository itself: <your_git_repository>/.git/config
  • User home directory: ~/.gitconfig
  • System-wide directory: $(prefix)/etc/gitconfig
  • 存储库本身: <your_git_repository>/.git/config
  • 用户主目录: ~/.gitconfig
  • 系统范围目录: $(prefix)/etc/gitconfig

The --globaloption always use the home directory. Note that gitwill always try to read all of them. If it finds one, it loads it, and moves to the next one. Local takes precedence over global, which takes precedence over system-wide. It uses a simple key-merging algorithm.

--global选项始终使用主目录。请注意,git将始终尝试阅读所有内容。如果它找到一个,它就会加载它,然后移动到下一个。本地优先于全局,全局优先于系统范围。它使用简单的密钥合并算法。

Reference: git-config FILES

参考:git-config 文件

回答by manojlds

There are three places - system ( all users on the system at $(prefix)/etc/gitconfig), global ( for the user at ~/.gitconfig) and local ( for the repo at .git/config). Any config should be in either of the three to be taken by git.

有三个地方 - 系统(系统 at 上的所有用户$(prefix)/etc/gitconfig)、全局(对于用户 at ~/.gitconfig)和本地(对于 repo at .git/config)。任何配置都应该在 git 使用的三个中的任何一个中。

However if GIT_CONFIGor myriad other environment variable are set, some of the values will be coming from those. If you are not able to find what you want in any of the config files, or not even able to find these files, look at all GIT_* environment variables as the last resort.

但是,如果设置了GIT_CONFIG或无数其他环境变量,其中一些值将来自那些。如果您无法在任何配置文件中找到您想要的内容,或者甚至无法找到这些文件,请将所有 GIT_* 环境变量视为最后的手段。

More details here:

更多细节在这里:

http://git-scm.com/docs/git-config#FILES

http://git-scm.com/docs/git-config#FILES

回答by Michael Behrens

In my case, I found my username in the ~/.git-credentialsfile. Hope this helps you. You can also list the configuration using:

就我而言,我在~/.git-credentials文件中找到了我的用户名。希望这对你有帮助。您还可以使用以下方法列出配置:

git config --list