git 如何在给定SHA1的git中获取(仅)作者姓名或电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29876342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:56:46  来源:igfitidea点击:

How to get (only) author name or email in git given SHA1?

gitcommitsha1author

提问by Patryk

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

我想检查作者的电子邮件和姓名,以验证谁正在推送我的 repo。

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 中提出一个命令来显示提交者的姓名/电子邮件,仅给出提交的 SHA1 值?

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 hook 这就是为什么它使用 2 SHA1 和rev-list。第二个只是使用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 

回答by Igal S.

You can use the following command:

您可以使用以下命令:

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

It works with git showas well. You need to include -sto suppress the diff.

它也适用git show。您需要包含-s以抑制差异。

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

回答by Chaitanya Bapat

git show <commit_id> | grep Author

Using git show + pipe + grep works!

使用 git show + pipe + grep 工作!