【问题标题】:GIT commit as different user without email / or only emailGIT 以不同的用户身份提交,没有电子邮件/或只有电子邮件
【发布时间】:2012-07-19 17:28:14
【问题描述】:

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

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'

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

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

对于 --author 选项。

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

【问题讨论】:

  • AU 不代表任何东西,它只是一个例子:AU Thor => AUThor => 作者。您可以指定任何您想要的名称。
  • 我知道 A U Thor 形成了作者,我想知道分离是否有任何意义。

标签: git commit


【解决方案1】:

具体格式为:

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

【讨论】:

  • 如果你提交他的名字,为什么不需要 John Doe 的密码?
  • @Narek 在这种情况下会是什么?
【解决方案2】:

格式

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 会将提供的字符串视为一种模式,并尝试在其他提交的作者中找到匹配的名称。

【讨论】:

  • 没有 FirstName MiddleName LastName 这样的东西。见this
【解决方案3】:

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

Name <email>

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

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

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

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

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

【讨论】:

  • 刚刚发现如果您没有电子邮件地址,您也可以直接输入 "name " ,明确将其留空,而不是输入假的。
  • 如果你使用"name &lt;&gt;",之后使用git commit --amend,它将失败并出现invalid ident错误;所以不要
  • 显然即使使用该选项,您仍然需要在 git 配置中设置 user.email 和 user.name,否则 git 会抱怨。
  • 如何为我的第一次提交添加一个文件作为不同的用户?之后我会使用commit命令。
【解决方案4】:

标准 A U Thor 格式

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

A U Thor = 必填用户名

  • 字符的分隔可能表示允许空格,也可能类似于首字母。
  • 用户名后面必须有 1 个空格,多余的空格将被截断

= 可选电子邮件地址

  • 必须始终位于 符号之间。
  • 电子邮件地址格式未经验证,您几乎可以输入任何您想要的内容
  • 可选,您可以使用
  • 显式省略它

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

示例:

  1. 只有用户名

    明确省略电子邮件地址:

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

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

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

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

【讨论】:

    【解决方案5】:

    只是补充:

    git commit --author="john@doe.com " -m "冒充是邪恶的。"

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

    *** 请告诉我你是谁。

    运行

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

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

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

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

    【讨论】:

    • 这是我需要的。对于企业 GitHub 和公共 GitHub,我有单独的用户名和电子邮件。我需要将我当前的仓库设置为使用我的公共 GitHub 用户名和电子邮件,这样我就可以在不暴露私人电子邮件的情况下推送我的更改。
    【解决方案6】:

    一个替代方法如果担心隐藏真实的电子邮件地址...如果你致力于 Github 你不需要真实的电子邮件你可以使用&lt;username&gt;@users.noreply.github.com

    无论是否使用 Github,您可能首先要更改您的 committer 详细信息(在 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

    【讨论】:

    • 与所有其他解决方案不同,这在您最初没有初始化 user.email/user.name 时有效。
    【解决方案7】:

    打开 Git Bash。

    设置一个 Git 用户名:

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

    $ git config --global 用户名

    姓氏

    设置 Git 电子邮件:

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

    $ git config --global user.email

    email@foo.com

    【讨论】:

      【解决方案8】:

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

      例如:

      git commit -am "Some message"

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

      [user]
          email = someemail@gmail.com
      

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

      【讨论】:

        【解决方案9】:

        --author 选项不能正确地避免在您的 git 个性之间泄露信息:它不会绕过读取调用用户的配置:

        *** 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
        

        为了区分工作和私人 git 个性,Git 2.13 支持directory specific configuration:您不再需要包装 git 并自己破解它来获得它。

        【讨论】:

        • 这是唯一对我有用的。注意顺序很重要。 git commit -c user.name="j bloggs" -am "message" 给出错误fatal: Option -m cannot be combined with -c/-C/-F
        • @Martin 是的,因为-c 标志属于git 命令本身,而不是commit 子命令(顺便说一句,它有一个不同的-c 标志)
        猜你喜欢
        • 2011-11-14
        • 2017-08-10
        • 2021-10-05
        • 1970-01-01
        • 1970-01-01
        • 2016-04-23
        • 2014-09-08
        • 2015-11-06
        • 2018-07-26
        相关资源
        最近更新 更多