3

git用来跟踪服务器上一系列系统配置文件的更改。这些文件归该root帐户所有(出于各种内部企业原因,root 是此框中唯一的帐户)。

有一个中央 git 服务器,在该系统上所做的所有更改都被推送到该服务器。

我想要做的是抑制git由于没有设置用户帐户而引发的警告。我们所做的是,任何在 git 控制下更改文件的人只需--author在提交时设置选项 - 但是,git 仍然抱怨未设置用户信息。

有关详细信息,确切的消息是:

[root@server ~]# git commit --author "Karunamon <karunamon@company.com>"
[master 491d9f8] File updated
 Author: Karunamon <Karunamon@company.com>
 Committer: root <root@server>
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 you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)

所以基本上,这是一个双重问题:

首先,有没有办法压制这个警告信息?设置 config 变量会以混乱结束,因为会有很多人以 root 帐户访问此服务器上的同一存储库。

我确实尝试使用环境变量(GIT_AUTHOR_EMAIL,GIT_AUTHOR_NAME等),但出现了相同的消息。

其次,有没有更好的方法(缺少一些涉及 .rc 文件并在登录时询问的可怕黑客攻击)来设置用户名和电子邮件,以便我的用户不必--author在每次提交时添加标志?

环境变量选项本来是完美的——我可以让我的用户在登录时导出变量,然后在下一次连接之前它们都很好。但 git 仍然抱怨。

4

2 回答 2

3

尝试

git -c user.email="Karunamon <karunamon@company.com>" commit

这将在执行该命令时覆盖配置设置。

然后,您可以创建一个git别名/包装器,在执行时从本地环境变量中插入该值。

于 2013-06-12T19:32:24.213 回答
1
git -c user.email="karunamon@company.com" -c user.name="Karunamon" commit

那个对我有用。它也需要 user.name。

于 2017-08-17T15:57:30.187 回答