GIT 以不同的用户身份提交,没有电子邮件/或只有电子邮件

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

GIT commit as different user without email / or only email

gitcommit

提问by Willem D'Haeseleer

I'm trying to commit some changes as a different user, but i do not have a valid email address, following command is not working for me:

我正在尝试以不同的用户身份提交一些更改,但我没有有效的电子邮件地址,以下命令对我不起作用:

git commit --author="john doe" -m "some fix"
fatal: No existing author found with 'john doe'

I have the same problem when trying to commit with only an email address

尝试仅使用电子邮件地址提交时,我遇到了同样的问题

git commit --author="[email protected]" -m "some fix"
fatal: No existing author found with '[email protected]'

On the GIT man pages for the commit command it says i can use the

在提交命令的 GIT 手册页上,它说我可以使用

standard A U Thor <[email protected]> format

For the --author option.

对于 --author 选项。

Where is this format defined ? what does A and U stand for ? how do i commit for a different user with only a username or only an email?

这种格式在哪里定义?A 和 U 代表什么?我如何为只有用户名或电子邮件的不同用户提交?

采纳答案by Willem D'Haeseleer

The

standardA U Thor <[email protected]> format

标准AU Thor <[email protected]> 格式

Seems to be defined as followed: ( as far as i know, with absolutely no warranty )

似乎定义如下:(据我所知,绝对没有保修)

A U Thor = required username

AU Thor =必需的用户名

  • The separation of the characters probablyindicates that spaces are allowed, it could also be resembling initials.
  • The username has to be followed by 1 space, extra spaces will be truncated
  • 字符的分隔可能表明允许使用空格,也可能类似于首字母。
  • 用户名后必须跟 1 个空格,多余的空格将被截断

<[email protected]> = optional email address

<[email protected]> =可选的电子邮件地址

  • Must always be between < > signs.
  • The email address format isn't validated, you can pretty much enter whatever you want
  • Optional, you can omit this explicitly by using <>
  • 必须始终在 < > 符号之间。
  • 电子邮件地址格式未经验证,您几乎可以输入任何您想要的内容
  • 可选,您可以使用 <> 显式省略它

If you don't use this exact syntax, git will search through the existing commits and use the first commit that contains your provided string.

如果您不使用此确切语法,git 将搜索现有提交并使用包含您提供的字符串的第一个提交。

Examples:

例子:

  1. Only user name

    Omit the email address explicitly:

    git commit --author="John Doe <>" -m "Impersonation is evil."
    
  2. Only email

    Technically this isn't possible. You can however enter the email address as the username and explicitly omit the email address. This doesn't seem like it's very useful. I think it would make even more sense to extract the user name from the email address and then use that as the username. But if you have to:

    git commit --author="[email protected] <>" -m "Impersonation is evil." 
    
  1. 只有用户名

    明确省略电子邮件地址:

    git commit --author="John Doe <>" -m "Impersonation is evil."
    
  2. 只有电子邮件

    从技术上讲,这是不可能的。但是,您可以输入电子邮件地址作为用户名并明确省略电子邮件地址。这似乎不是很有用。我认为从电子邮件地址中提取用户名然后将其用作用户名会更有意义。但如果你必须:

    git commit --author="[email protected] <>" -m "Impersonation is evil." 
    

I ran in to this when trying to convert a repository from mercurial to git. I tested the commands on msysgit 1.7.10.

我在尝试将存储库从 mercurial 转换为 git 时遇到了这个问题。我在 msysgit 1.7.10 上测试了命令。

回答by eykanal

The minimal required author format, as hinted to in this SO answer, is

如此 SO answer 中所暗示的,所需的最低作者格式是

Name <email>

In your case, this means you want to write

在你的情况下,这意味着你想写

git commit --author="Name <email>" -m "whatever"

Per Willem D'Haeseleer's comment, if you don't have an email address, you can use <>:

根据 Willem D'Haeseleer 的评论,如果您没有电子邮件地址,可以使用<>

git commit --author="Name <>" -m "whatever"

As written on the git commitman pagethat you linked to, if you supply anything less than that, it's used as a search token to search through previous commits, looking for other commits by that author.

正如您链接到的git commit手册页上所写的那样,如果您提供的内容少于此内容,它将用作搜索标记来搜索以前的提交,查找该作者的其他提交。

回答by pmr

The specific format is:

具体格式为:

git commit --author="John Doe <[email protected]>" -m "Impersonation is evil." 

回答by qinxian

Just supplement:

只是补充:

git commit --author="[email protected] " -m "Impersonation is evil."

git commit --author="[email protected] " -m "冒充是邪恶的。"

In some cases the commit still fails and shows you the following message:

在某些情况下,提交仍然失败并显示以下消息:

*** Please tell me who you are.

Run

git config --global user.email "[email protected]" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got xxxx)

*** 请告诉我你是谁。

git config --global user.email "[email protected]" git config --global user.name "你的名字"

设置您帐户的默认身份。省略 --global 以仅在此存储库中设置身份。

致命:无法自动检测电子邮件地址(得到 xxxx)

So just run "git config", then "git commit"

所以只需运行“git config”,然后运行“git commit”

回答by KL-7

Format

格式

A U Thor <[email protected]>

simply mean that you should specify

只是意味着你应该指定

FirstName MiddleName LastName <[email protected]>

Looks like middle and last names are optional (maybe the part before email doesn't have a strict format at all). Try, for example, this:

看起来中间名和姓氏是可选的(也许电子邮件之前的部分根本没有严格的格式)。例如,试试这个:

git commit --author="John <[email protected]>" -m "some fix"

As the docs say:

正如文档所说:

  --author=<author>
       Override the commit author. Specify an explicit author using the standard 
       A U Thor <[email protected]> format. Otherwise <author> is assumed to 
       be a pattern and is used to search for an existing commit by that author 
       (i.e. rev-list --all -i --author=<author>); the commit author is then copied 
       from the first such commit found.

if you don't use this format, git treats provided string as a pattern and tries to find matching name among the authors of other commits.

如果您不使用此格式,git 会将提供的字符串视为模式,并尝试在其他提交的作者中查找匹配的名称。

回答by A Mo

Open Git Bash.

打开 Git Bash。

Set a Git username:

设置 Git 用户名:

$ git config --global user.name "name family" Confirm that you have set the Git username correctly:

$ git config --global user.name "name family" 确认你已经正确设置了 Git 用户名:

$ git config --global user.name

$ git config --global 用户名

name family

姓氏

Set a Git email:

设置 Git 电子邮件:

$ git config --global user.email [email protected] Confirm that you have set the Git email correctly:

$ git config --global user.email [email protected] 确认您已正确设置 Git 电子邮件:

$ git config --global user.email

$ git config --global user.email

[email protected]

电子邮件@foo.com

回答by user2394284

The --authoroption doesn't work:

--author选项不起作用:

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

This does:

这样做:

git -c user.name='A U Thor' -c [email protected] commit

回答by Kolob Canyon

It is all dependent on how you commit.

这完全取决于你如何提交。

For example:

例如:

git commit -am "Some message"

git commit -am "Some message"

will use your ~\.gitconfigusername. In other words, if you open that file you should see a line that looks like this:

将使用您的~\.gitconfig用户名。换句话说,如果您打开该文件,您应该看到如下所示的一行:

[user]
    email = [email protected]

That would be the email you want to change. If your doing a pull request through Bitbucket or Github etc. you would be whoever you're logged in as.

那将是您要更改的电子邮件。如果您通过 Bitbucket 或 Github 等进行拉取请求,您将成为您登录的任何人。

回答by KCD

An alternativeif the concern is to hide the real email address...If you are committing to Github you don't need a real email you can use <username>@users.noreply.github.com

如果担心隐藏真实的电子邮件地址,则一种选择……如果您承诺使用 Github,则不需要真实的电子邮件,您可以使用<username>@users.noreply.github.com

Regardless of using Github or not, you probably first want change your committerdetails (on windows use SET GIT_...)

无论是否使用 Github,您可能首先想更改提交者的详细信息(在 Windows 上使用SET GIT_...

GIT_COMMITTER_NAME='username' 
GIT_COMMITTER_EMAIL='[email protected]'

Then set the author

然后设置作者

git commit --author="username <[email protected]>"

https://help.github.com/articles/keeping-your-email-address-private

https://help.github.com/articles/keeping-your-email-address-private

回答by Diptendu Das

Run these two commands from the terminal to set User email and Name

从终端运行这两个命令来设置用户电子邮件和名称

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

 git config --global user.name "your name"