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

你离开我真会死。 提交于 2019-12-18 14:09:01

问题


I would like to check for author's e-mail and name, surname to verify who's pushing to my 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?

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 

回答1:


You can use the following command:

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

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

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



回答2:


git show <commit_id> | grep Author

Using git show + pipe + grep works!



来源:https://stackoverflow.com/questions/29876342/how-to-get-only-author-name-or-email-in-git-given-sha1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!