Git post-receive钩子“空标识名称”

17
我已经编写了以下的post-receive钩子:
#!/bin/sh
cd /var/node/heartbeat/ || exit
unset GIT_DIR
echo $USER
git pull --no-edit

当我向代码库推送时,会返回以下错误信息:
remote:
remote: From server.net:chris/heartbeat
remote:    c0df678..5378ade  master     -> origin/master
remote:
remote: *** Please tell me who you are.
remote:
remote: Run
remote:
remote:   git config --global user.email "you@example.com"
remote:   git config --global user.name "Your Name"
remote:
remote: to set your account's default identity.
remote: Omit --global to set the identity only in this repository.
remote:
remote: fatal: empty ident name (for <git@server.net>) not allowed

当在git用户下运行 git config -l 命令时:

user.name=server
user.email=server@server.com
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=git@server.net:chris/heartbeat.git
branch.master.remote=origin
branch.master.merge=refs/heads/master

我不明白为什么它仍认为我的user.email和user.name为空,因为git config -l告诉我它们不是空的。有人知道这个问题的解决方案或变通方法吗?


你是在服务器端(“远程”端)运行 git config 吗?而且你的跟踪结果中 echo $USER 的输出在哪里? - VonC
是的,我正在服务器端运行git config,echo $USER的结果是错误的第一行空行。 - user2817219
如果你将那个 echo 替换为 id -a,你会得到 'git' 作为结果吗?这个钩子是由用户 git 执行的吗? - VonC
1
以下行被返回,因此由git用户执行。 remote: uid=1000(git) gid=1000(git) groups=1000(git)奇怪的是,当我在su git之后手动执行钩子时,没有返回任何错误。 - user2817219
在这个钩子中,执行 git config --local -l 会返回什么? - VonC
如果找不到user.name或user.email,那么为git用户在本地设置的正确方法是什么? - user2817219
3个回答

29

为确保此项工作,需要运行命令 git config --local -l ,返回用户名和电子邮件。

如果未能返回,请前往服务器上的该存储库,输入以下命令:

git config user.name server
git config user.email server@server.com

哦,我的天啊,终于完成了。我用Node.js写了两天的提交脚本。非常感谢!但是由于作者从未出现,即使服务器用户具有全局凭据,也无法提交。现在好了。 - krivar
@wytten,你使用的是哪个Git版本?在哪个操作系统上?是在shell还是CMD会话中?你输入了什么命令?你在local前面加了两个破折号吗? - VonC
@VonC Linux git 1.7.1 'git config --local -l' 谢谢 - wytten
1.7.1虽然有些古老,但我相信这个选项应该可以工作。不过,如果您能升级的话,那就更好了。(http://unix.stackexchange.com/a/170831/7490) - VonC
为什么它不工作?名称和电子邮件已在全局配置中正确注册。 - la_urre
@la_urre 你可以为此提出一个新问题。 - VonC

1

我的git版本是git 1.7.1(centos 6.8); 当然,我不能使用“git config --local -l”

我的最终解决方案:

进入git代码服务器, 然后进入你的home/www/your projecet/.git/文件夹修改配置,如下:

repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = /home/git/repos/music.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
name = server
email = server@minstech.cn

名称 = 服务器

电子邮件 = server@minstech.cn

已添加


非常感谢,没有其他东西有帮助。我已经将这些行添加到托管的.git/config文件中,钩子最终起作用了。 - lalezky

-1

你还应该取消设置:

GIT_COMMITER_NAME
GIT_COMMITER_EMAIL
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL

我同意。上述环境变量将覆盖在 git config --local -l 中设置的变量。如果它们被设置为空字符串,则仍会出现 fatal: empty ident name 错误。您可以使用 env | grep GIT_ 查看它们是否已填充,并使用 unset 将其删除。 - Mead

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接