Git:姓名和电子邮件地址配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10946893/
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
Git: name and email address configuration
提问by Eric Brotto
Once in a while I get the message shown below from Git. My questions regarding this are:
偶尔我会从 Git 收到如下所示的消息。我的问题是:
- Why does this happen?
- How can I prevent this from happening again?
- How does this affect my commits or any other Git actions I may take?
- 为什么会发生这种情况?
- 我怎样才能防止这种情况再次发生?
- 这如何影响我的提交或我可能采取的任何其他 Git 操作?
I realize similar questions have been posted to Stack Overflow, but I don't believe they address this message in particular.
我意识到类似的问题已经发布到 Stack Overflow,但我认为他们并没有特别解决这个消息。
Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
您的姓名和电子邮件地址是根据您的用户名和主机名自动配置的。请检查它们是否准确。您可以通过显式设置它们来抑制此消息:
git config --global user.name "Your Name"
git config --global user.email [email protected]
After doing this, you may fix the identity used for this commit with:
执行此操作后,您可以使用以下命令修复用于此提交的身份:
git commit --amend --reset-author
回答by Sandro Munda
Git
simply detects you don't have the following section in your config files:
Git
只是检测您的配置文件中没有以下部分:
[user]
name = <your name>
email = <your mail>
<project_path>/.git/config
for the project specific config file.~/.gitconfig
the global config file
<project_path>/.git/config
对于项目特定的配置文件。~/.gitconfig
全局配置文件
When you do:
当你这样做时:
git config --global user.name "Your Name"
git config --global user.email [email protected]
Git writes that information into the configuration file (--global
means in the global config file).
Git 将该信息写入配置文件(--global
意味着在全局配置文件中)。
To have a the correct Author section in a commit like the following example commit:
要在提交中包含正确的 Author 部分,如下例提交:
commit 79eeaa9f22321580a0e5bee6e237331691cd3b68
Author: Sandro Munda <[email protected]>
Date: Thu Jun 8 10:40:05 2012 +0200
My first commit
You need to reset the commit information with the command:
您需要使用以下命令重置提交信息:
git commit --amend --reset-author
git commit --amend --reset-author
回答by Denys Séguret
That's simply because you didn't set your global user.name and user.email and so git has to guess them when creating a new repository.
这仅仅是因为您没有设置全局 user.name 和 user.email,因此 git 在创建新存储库时必须猜测它们。
Use this :
用这个 :
git config --global user.email "[email protected]"
git config --global user.name "ha"
So next time those settings will be used.
所以下次将使用这些设置。
回答by laktak
If you want to prevent git from guessing automatic values you can set
如果你想防止 git 猜测自动值,你可以设置
git config --global user.useConfigOnly true
See https://git-scm.com/docs/git-config#Documentation/git-config.txt-useruseConfigOnly
请参阅https://git-scm.com/docs/git-config#Documentation/git-config.txt-useruseConfigOnly
回答by linquize
You have not set the default user name and email for you "desktop user account".
您尚未为“桌面用户帐户”设置默认用户名和电子邮件。
Follow the instructions that you posted to do so.
按照您发布的说明进行操作。