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

4

77

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 
Obviate answered 26/4, 2015 at 10:13 Comment(0)
A
108

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
Ashlieashlin answered 26/4, 2015 at 10:56 Comment(3)
It does work with git show, but git show first shows the commit info as specified by format, and then the diff. To suppress the diff, add the -s option (aka --no-patch).Residential
You are right. So the best way would be a simple: git show -s --format='%ae' HASHAshlieashlin
Or the equally simple git log -1 --format='%ae' HASH for yet another alternative :)Residential
D
30
git show <commit_id> | grep Author

Using git show + pipe + grep works!

Dallon answered 15/11, 2019 at 18:59 Comment(0)
A
15

This will show - sha, committer email, author email

git log --pretty=format:"%h %ce %ae" HASH
Anton answered 9/6, 2021 at 6:58 Comment(1)
For this you need to add HASH at the end, otherwise it produces output for all commits instead of for single commitZamia
G
5

If you want the author's name instead of e-mail, the following works:

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

The difference from the other answers is the format string (%an vs %ae).

Goosander answered 6/12, 2022 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.