git:谁推入了 post-receive 挂钩
如何确定谁推送到存储库?
即,某人执行 git Push origin master 操作,并且在 origin 存储库上的 post-receive 挂钩中,我需要使用某人的姓名或电子邮件。
How do I determine who pushed to the repository?
I.e. Somebody does git push origin master
and in the post-receive hook on the origin
repo I need to use the name or e-mail of Somebody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 SSH 协议将更改推送到服务器,并且每个用户在服务器上都有自己的帐户,那么您的脚本应该以执行推送的用户身份运行。因此,您应该能够使用
whoami
或id -un
获取执行推送的人的用户名。如果您不使用此设置,跟踪谁在推送的最佳方法可能是使用 Gitolite,强大的Git认证和授权系统。在 Gitolite 中,您可以使用
update.secondary
和post- update.secondary
hooks,它将把GL_USER
环境变量设置为当前 Gitolite 用户。If you're using the SSH protocol to push changes to the server, with each user having their own account on the server, then your script should be running as the user who's doing the push. So, you should be able to use
whoami
orid -un
to get the username of the person doing the push.If you are not using this setup, the best way to keep track of who is pushing is probably using Gitolite, a powerful Git authentication and authorization system. In Gitolite, you can use the
update.secondary
andpost-update.secondary
hooks, which will have theGL_USER
environment variable set to the current Gitolite user.我不确定 Git 是否旨在管理这种访问控制。
这就是为什么你有基于 ssh 的包装器,例如 gitosis 或 gitolite 将提供您所需的足够的身份验证级别。
I am not sure Git is meant to manage that kind of access control.
That is why you have ssh-based wrappers like gitosis or gitolite that will provide the adequate authentication level you are after.
你无法使用 Git 来判断这一点。如果您使用 SSH 推送,那么您可以使用 SSH 来获取用户名,如果您使用 gitolite 等用户管理前端,您可以使用 that 来获取用户名,如果您使用 HTTP身份验证,您可以使用网络服务器获取用户名,但 Git 网络协议不传输任何用户名。
You cannot tell that using Git. If you use SSH to push, then you can use SSH to get the username, if you use a user-management frontend such as gitolite, you can use that to get the username, if you use HTTP with authentication, you can use your webserver to get the username, but the Git networking protocols do not transmit any usernames.