git 如何知道配置时保存的git用户名和邮箱?

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

How to know the git username and email saved during configuration?

gitgit-config

提问by Jebin Philipose

While configuring gitI ran these two commands:

在配置时,git我运行了这两个命令:

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

git config --global user.email "[email protected]"

However, I doubt whether I made a typo or not. So, is there any command to know the nameand emailwhich gitsaved during configuration? Obviously, I can know that using the git logcommand by looking at the commit history. But for that I have to make commits, right? Can I know that with the help of command line?

但是,我怀疑我是否打错了字。那么,是否有任何命令可以知道在配置过程中保存的姓名电子邮件git?显然,我可以git log通过查看提交历史来知道使用该命令。但为此我必须做出承诺,对吗?我可以在命令行的帮助下知道吗?

回答by Rob

The command git config --listwill list the settings. There you should also find user.nameand user.email.

该命令git config --list将列出设置。在那里你还应该找到user.nameuser.email

回答by Jebin Philipose

Considering what @Robert said, I tried to play around with the configcommand and it seems that there is a direct way to know both the name and email.

考虑到@Robert 所说的,我尝试使用config命令,似乎有一种直接的方法可以知道姓名和电子邮件。

To know the username, type:

要知道用户名,请键入:

git config user.name

To know the email, type:

要知道电子邮件,请键入:

git config user.email

These two output just the name and email respectively and one doesn't need to look through the whole list. Comes in handy.

这两个分别只输出姓名和电子邮件,一个不需要查看整个列表。派上用场。

回答by kgf3JfUtW

Inside your git repository directory, run git config user.name.

在您的 git 存储库目录中,运行git config user.name.

Why is running this command within your git repo directory important?

为什么在 git repo 目录中运行此命令很重要?

If you are outside of a git repository, git config user.namegives you the value of user.nameat globallevel. When you make a commit, the associated user name is read at locallevel.

如果您在 git 存储库之外,则为git config user.nameuser.name提供全局级别的值。进行提交时,将在本地级别读取关联的用户名。

Although unlikely, let's say user.nameis defined as fooat globallevel, but barat locallevel. Then, when you run git config user.nameoutside of the git repo directory, it gives bar. However, when you really commits something, the associated value is foo.

虽然不太可能,让我们说user.name定义为foo全球层面,但bar地方层面。然后,当您git config user.name在 git repo 目录之外运行时,它会给出bar. 但是,当您真正提交某些内容时,关联的值为foo



Git config variables can be stored in 3 different levels. Each level overrides values in the previous level.

Git 配置变量可以存储在 3 个不同的级别。每个级别都会覆盖上一级别中的值。

1. System level (applied to every user on the system and all their repositories)

1.系统级别(适用于系统上的每个用户及其所有存储库)

  • to view, git config --list --system(may need sudo)
  • to set, git config --system color.ui true
  • to edit system config file, git config --edit --system
  • 查看,git config --list --system(可能需要sudo
  • 设置, git config --system color.ui true
  • 编辑系统配置文件, git config --edit --system

2. Global level (values specific personally to you, the user. )

2. 全局级别(特定于您个人的值,用户。)

  • to view, git config --list --global
  • to set, git config --global user.name xyz
  • to edit global config file, git config --edit --global
  • 查看, git config --list --global
  • 设置, git config --global user.name xyz
  • 编辑全局配置文件, git config --edit --global

3. Repository level (specific to that single repository)

3. 存储库级别(特定于单个存储库)

  • to view, git config --list --local
  • to set, git config --local core.ignorecase true(--localoptional)
  • to edit repository config file, git config --edit --local(--localoptional)
  • 查看, git config --list --local
  • 设置,git config --local core.ignorecase true--local可选)
  • 编辑存储库配置文件,git config --edit --local--local可选)

How to view allsettings?

如何查看所有设置?

  • Run git config --list, showing system, global, and (if inside a repository) localconfigs
  • Run git config --list --show-origin, also shows the origin file of each config item
  • 运行git config --list,显示systemglobal和(如果在存储库中)本地配置
  • 运行git config --list --show-origin,还显示每个配置项的源文件

How to read one particular config?

如何阅读一个特定的配置?

  • Run git config user.nameto get user.name, for example.
  • You may also specify options --system, --global, --localto read that value at a particular level.
  • 例如,运行git config user.name以获取user.name
  • 您还可以指定 options --system, --global,--local以在特定级别读取该值。


Reference: 1.6 Getting Started - First-Time Git Setup

参考:1.6 入门 - 首​​次 Git 设置

回答by Srikrushna

If you want to check or set the user name and email you can use the below command

如果要检查或设置用户名和电子邮件,可以使用以下命令

Check user name

检查用户名

git config user.name

Set user name

设置用户名

git config user.name "your_name"

Check your email

查看你的邮件

git config user.email

Set/change your email

设置/更改您的电子邮件

git config user.email "[email protected]"

List/see all configuration

列出/查看所有配置

git config --list

回答by Eugene

Add my two cents here. If you want to get user.name or user.email only without verbose output.

在这里加上我的两分钱。如果您只想获取 user.name 或 user.email 而没有详细输出。

On liunx, type git config --list | grep user.name.

在 liunx 上,输入git config --list | grep user.name.

On windows, type git config --list | findstr user.name.

在 Windows 上,键入git config --list | findstr user.name.

This will give you user.name only.

这只会给你 user.name。

回答by Kanish

Sometimes above solutions doesn't work in macbook to get username n password.

有时上述解决方案在 macbook 中无法获取用户名和密码。

IDK why?, here i got another solution.

IDK为什么?,这里我有另一个解决方案。

$ git credential-osxkeychain get
host=github.com
protocol=https

this will revert username and password