git提交为不同的用户,没有电子邮件/或只有电子邮件

时间:2012-07-20 12:23:16

标签: git commit

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

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

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

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

在commit命令的git手册页上,它说我可以使用

standard A U Thor <author@example.com> format

对于--author选项。

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

10 个答案:

答案 0 :(得分:123)

this SO answer中暗示的最低要求作者格式是

Name <email>

在您的情况下,这意味着您要写

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

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

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

如您所链接的git commit man page所写,如果您提供的内容少于此值,则会将其用作搜索令牌以搜索之前的提交,并查找该作者的其他提交。

答案 1 :(得分:42)

具体格式为:

git commit --author="John Doe <john@doe.com>" -m "Impersonation is evil." 

答案 2 :(得分:29)

  

标准 A U Thor&lt; author@example.com>格式

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

U Thor = 必填用户名

  • 字符可能的分隔表示允许使用空格,也可能类似于缩写。
  • 用户名必须后跟1个空格,额外的空格将被截断

&LT; author@example.com> = 可选的电子邮件地址

  • 必须始终在&lt; &GT;迹象。
  • 电子邮件地址格式未经过验证,您可以输入任何您想要的内容
  • 可选,您可以使用&lt;&gt;
  • 明确省略此内容

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

<强>示例:

  1. 仅限用户名

    明确地省略电子邮件地址:

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

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

    git commit --author="john@doe.com <>" -m "Impersonation is evil." 
    
  3. 我试图将存储库从mercurial转换为git时遇到了这个问题。 我测试了msysgit 1.7.10上的命令。

答案 3 :(得分:8)

--author选项不起作用:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

这样做:

git -c user.name='A U Thor' -c user.email=author@example.com commit

答案 4 :(得分:6)

格式

A U Thor <author@example.com>

只是意味着你应该指定

FirstName MiddleName LastName <email@example.com>

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

git commit --author="John <john@doe.com>" -m "some fix"

正如文档所说:

  --author=<author>
       Override the commit author. Specify an explicit author using the standard 
       A U Thor <author@example.com> 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.

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

答案 5 :(得分:4)

补充:

  

git commit --author =“john@doe.com”-m“假冒是邪恶的。”

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

  

***请告诉我你是谁。

     

运行

     

git config --global user.email“you@example.com”    git config --global user.name“你的名字”

     

设置帐户的默认身份。   Omit --global仅在此存储库中设置标识。

     

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

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

答案 6 :(得分:2)

打开Git Bash。

设置Git用户名:

$ git config --global user.name“名称族” 确认您已正确设置Git用户名:

$ git config --global user.name

  

姓名家族

设置Git电子邮件:

$ git config --global user.email电子邮件@ foo.com 确认您已正确设置Git电子邮件:

$ git config --global user.email

  

email@foo.com

答案 7 :(得分:1)

这完全取决于您的提交方式。

例如:

git commit -am "Some message"

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

[user]
    email = someemail@gmail.com

这就是您要更改的电子邮件。如果您通过Bitbucket或Github等发出请求请求,则无论您以谁身份登录。

答案 8 :(得分:0)

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

 git config --global user.email "you@example.com" 

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

答案 9 :(得分:-3)

如果你正在向Github投稿,你不需要真正的电子邮件,你可以使用<username>@users.noreply.github.com

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

GIT_COMMITTER_NAME='username' 
GIT_COMMITTER_EMAIL='username@users.noreply.github.com'

然后设置作者

git commit --author="username <username@users.noreply.github.com>"

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

相关问题