Git 配置 user.name 不起作用

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

Git configuration user.name doesn't work

gitgit-config

提问by Jimsea

I installed Git for Windows 7 today. I don't know much about Git yet and I'm following http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setupand videos from YouTube on that subject. On the videos people install Git and go to the command line and use

我今天为 Windows 7 安装了 Git。我还不太了解 Git,我正在关注http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup和 YouTube 上关于该主题的视频。在视频中人们安装 Git 并转到命令行并使用

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

and

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

and it creates .gitconfigfile in C:/Users/admin/.gitconfigwith correct values for them.

并为它们创建具有正确值的.gitconfig文件C:/Users/admin/.gitconfig

After running the above lines of code three times this is what I got in that file:

运行上述代码行三遍后,这就是我在该文件中得到的内容:

[user]
    name = =
    email = =
    name = =

Why isn't it working? I followed the official tutorial and I see that it works for other people on YouTube but not for me.

为什么它不起作用?我遵循了官方教程,我发现它适用于 YouTube 上的其他人,但不适用于我。

回答by jub0bs

You're not using the correct syntax: there shouldn't be any equal sign between user.nameand "My name", or between user.emailand "[email protected]". For instance, when you run

您没有使用正确的语法:user.nameand"My name"之间或user.emailand之间不应该有任何等号"[email protected]"。例如,当你运行

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

the command interprets the =character as the string value passed to the user.namekey, and the rest of the line ("My Name") is silently ignored. That's why your .gitconfigfile ends up containing

该命令将=字符解释为传递给user.name键的字符串值,而行 ( "My Name")的其余部分将被静默忽略。这就是为什么您的.gitconfig文件最终包含

[user]
    name = =
    email = =

Everything should work if you use the correct syntax:

如果您使用正确的语法,一切都应该有效:

enter image description here

在此处输入图片说明

回答by factotum

There is no "=" for the parameters user.name and user.email, just use spaces. From the same page -

参数 user.name 和 user.email 没有“=”,只需使用空格。从同一页面 -

The first thing you should do when you install Git is to set your user name and e-mail address. This is important because every Git commit uses this information, and it's immutably baked into the commits you pass around:

安装 Git 时应该做的第一件事是设置用户名和电子邮件地址。这很重要,因为每个 Git 提交都使用此信息,并且它会永久地融入您传递的提交中:

  • $ git config --global user.name "John Doe"
  • $ git config --global user.email [email protected]
  • $ git config --global user.name "John Doe"
  • $ git config --global user.email [email protected]

回答by VonC

Note: that kind of syntax error (git config --global user.email = "[email protected]") will be better reported by Git 2.13+ (Q2 2017)

注意:git config --global user.email = "[email protected]"Git 2.13+(2017 年第二季度)会更好地报告这种语法错误 ( )

See commit 9442555, commit 13b9a24, commit 862e80a, commit afb6c30(23 Feb 2017) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster--in commit 066c38c, 10 Mar 2017)

请参阅Jeff King ( ) 的commit 9442555commit 13b9a24commit 862e80acommit afb6c30(2017 年 2 月 23 日(由Junio C Hamano合并-- --commit 066c38c,2017 年 3 月 10 日)peff
gitster

user.emailthat consists of only cruft charsshould consistently error out, but didn't.

user.email仅由cruft chars组成的应该始终出错,但没有。

That means this will now fail:

这意味着现在将失败:

GIT_AUTHOR_NAME=" .;<>" git commit --allow-empty -m foo
fatal: name consists only of disallowed characters: .;<>

GIT_AUTHOR_EMAIL="" GIT_AUTHOR_NAME="" git commit --allow-empty -m foo 
fatal: no email was given and auto-detection is disabled