给定SHA1,如何在git中获取(仅)作者姓名或电子邮件? [英] How to get (only) author name or email in git given SHA1?

查看:115
本文介绍了给定SHA1,如何在git中获取(仅)作者姓名或电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查作者的电子邮件和姓名,以确认谁在推送我的回购邮件。

I would like to check for author's e-mail and name, surname to verify who's pushing to my repo.

我有什么办法可以提出git中的命令仅显示提交的SHA1即可显示提交者的名称/电子邮件?

Is there any way that I can come up with a command in git to show commiter's name/e-mail given only SHA1 of the commit?

这是我想出的,但它与理想的解决方案相去甚远(第一个解决方案是使用git hook,这就是为什么它使用2个SHA1和 rev-list 。第二个SHA1仅使用 git show ) :

This is what I came up with but it's far from ideal solution (the first solution is for git hook that's why it's using 2 SHA1s with rev-list. The second one simply uses git show):

git rev-list -n 1 --pretty=short  ccd3970..6ddf170 | grep Author | cut -d ' ' -f2- | rev | cut -d ' ' -f2- | rev
git show 6ddf170 | grep Author | cut -d ' ' -f2- | rev | cut -d ' ' -f2- | rev 


推荐答案

您可以使用以下命令:

 git log --format='%ae' HASH^!

它也可以与 git show 一起使用。您需要包括 -s 来抑制差异。

It works with git show as well. You need to include -s to suppress the diff.

git show -s --format='%ae' HASH

这篇关于给定SHA1,如何在git中获取(仅)作者姓名或电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆