如何使用 git (git config --global)?

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

How to use git (git config --global)?

gitconfiguration

提问by prosseek

The Pragmatic Guide to GIThas the following "Git uses both to calculate the commit ID—a SHA-111 hash—that identifies each commit." in page 21.

所述语用指南GIT具有以下“GIT中同时使用来计算提交ID-A SHA-111散列每个标识提交”。在第 21 页。

And in page 22, I can use the following command to 'Configure Git to know who you are'.

在第 22 页中,我可以使用以下命令来“配置 Git 以了解您是谁”。

git config --global smcho "Your Name"

When I ran it, I got the following error message.

当我运行它时,我收到以下错误消息。

error: key does not contain a section: smcho

What's wrong with this? I guess it has something to do with SHA-111 hash, but I don't know how to get it to be used with git.

这有什么问题?我猜它与 SHA-111 哈希有关,但我不知道如何让它与 git 一起使用。

ADDED

添加

I thought user.name is to be replaced my name, not a section/parameter structured name. After changing that it works OK.

我认为 user.name 是要替换我的名字,而不是部分/参数结构化名称。更改后它工作正常。

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

回答by Bruno

Not sure where "smcho" comes from, but the setting to set your name is user.name:

不确定“smcho”来自哪里,但设置您的名字的设置是user.name

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

You can set your e-mail address too:

您也可以设置您的电子邮件地址:

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

I guess the reason it complains about the lack of a section is that the name of the parameter to set probably needs to be in two parts: section.parameter_name(You can see the sections names within []if you look in the configuration file, for example in .git/config).

我猜它抱怨缺少部分的原因是要设置的参数的名称可能需要分为两部分:(如果您查看配置文件,例如在 中,section.parameter_name您可以看到其中的部分名称)。[].git/config

(None of this is specific to OSX as far as I'm aware.)

(据我所知,这些都不是特定于 OSX 的。)

回答by user_CC

A simple answer to this question/problem is that do not replace "user.name" with your actual git username leave the user.name as it is the command needs to be:

这个问题/问题的一个简单答案是不要用您的实际 git 用户名替换“user.name”,保留 user.name,因为它是命令需要的:

git config --global user.name "Your Name here only"

回答by Matoeil

to edit the whole config file

编辑整个配置文件

git config --global --edit

回答by Oriol Prat

This error is because you have this word (smcho) at the beginning of your .gitconfig file at home directory.

此错误是因为您在主目录的 .gitconfig 文件的开头有这个词 (smcho)。

Bit late, but could be useful to somebody.

有点晚了,但可能对某人有用。