Git cli:从用户名获取用户信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7552054/
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-10 11:56:01  来源:igfitidea点击:

Git cli: get user info from username

gitgithubgithub-api

提问by cwhelms

Is there a way to get the name of the user, given only their username?

有没有办法获得用户的名字,只给出他们的用户名?

Something like this output git show <username>(I know this doesn't work)

像这样的输出git show <username>(我知道这不起作用)

username: username
name: First Last
email: email@address

I know I can do this with a GitHub api call, but would prefer to keep it within the CLI.

我知道我可以通过 GitHub api 调用来做到这一点,但更愿意将它保留在 CLI 中。

采纳答案by knittl

There are no "usernames" in Git.

Git 中没有“用户名”。

When creating a commit with Git it uses the configuration values of user.name(the real name) and user.email(email address). Those config values can be overridden on the console by setting and exporting the environment variables GIT_{COMMITTER,AUTHOR}_{NAME,EMAIL}.

使用 Git 创建提交时,它使用user.name(真实姓名)和user.email(电子邮件地址)的配置值。可以通过设置和导出环境变量在控制台上覆盖这些配置值GIT_{COMMITTER,AUTHOR}_{NAME,EMAIL}

Git doesn't know anything about github's users, because github is not part of Git. So you're only left with an API call to github (I guess you could do that from the command line with a little scripting.)

Git 对 github 的用户一无所知,因为 github 不是 Git 的一部分。所以你只剩下对 github 的 API 调用(我想你可以从命令行用一点脚本来做到这一点。)

回答by NewPersona

git config user.name
git config user.email

I believe these are the commands you are looking for.

我相信这些是您正在寻找的命令。

Here is where I found them: http://alvinalexander.com/git/git-show-change-username-email-address

这是我找到它们的地方:http: //alvinalexander.com/git/git-show-change-username-email-address

回答by Paul

git config --list

git config -l

will display your username and email together, along with other info

git config --list

git config -l

将显示您的用户名和电子邮件以及其他信息

回答by Prakash

Try this

尝试这个

git config user.name

git config command stores and gives all the information.

git config 命令存储并提供所有信息。

git config -l

This commands gives you all the required info that you want.

此命令为您提供所需的所有必需信息。

You can change the information using

您可以使用更改信息

git config --global user.name "<Your-name>"

Similarly you can change many info shown to you using -loption.

同样,您可以使用-l选项更改显示给您的许多信息。

回答by David

While its true that git commits don't have a specific field called "username", a git repo does have users, and the users do have names. ;) If what you want is the github username, then knittl's answer is right. But since your question asked about git cli and not github, here's how you get a git user's email address using the command line:

虽然 git commits 确实没有名为“username”的特定字段,但 git repo 确实有用户,并且用户确实有姓名。;) 如果您想要的是 github 用户名,那么 knittl 的答案是正确的。但是由于您的问题是关于 git cli 而不是 github,因此您可以通过以下方式使用命令行获取 git 用户的电子邮件地址:

To see a list of all users in a git repo using the git cli:

要使用 git cli 查看 git repo 中所有用户的列表:

git log --format="%an %ae" | sort | uniq

To search for a specific user by name, e.g., "John":

要按名称搜索特定用户,例如“John”:

git log --format="%an %ae" | sort | uniq | grep -i john

回答by The Humble Angy

You can try this to get infos like:

你可以试试这个来获取如下信息:

  • username: git config --get user.name
  • user email: git config --get user.email
  • 用户名: git config --get user.name
  • 用户邮箱: git config --get user.email

There's nothing like "first name" and "last name" for the user.

对于用户来说,没有什么比“名字”和“姓氏”更像的了。

Hope this will help.

希望这会有所帮助。

回答by A-Sharabiani

Use this to see the logged in user (the actual git account):

使用它来查看登录用户(实际的 git 帐户):

git config credential.username

And as other answers the user email and user name (this is differenct from user credentials):

和其他答案一样,用户电子邮件和用户名(这与用户凭据不同):

git config user.name
git config user.email

To see the list of all configs:

查看所有配置的列表:

git config --list

回答by Eugene

Add my two cents, if you're using windows commnad line:

如果您使用的是 windows commnad 行,请添加我的两分钱:

git config --list | findstr user.namewill give username directly.

git config --list | findstr user.name将直接提供用户名。

The findstrhere is quite similar to grepin linux.

findstr这里是非常相似grep的Linux操作系统。