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

GitCommitSha1Author

Git Problem Overview


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 

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

git show <commit_id> | grep Author

Using git show + pipe + grep works!

Solution 3 - Git

This will show - sha, committer email, author email

git log --pretty=format:"%h %ce %ae"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPatrykView Question on Stackoverflow
Solution 1 - GitIgal S.View Answer on Stackoverflow
Solution 2 - GitChaitanya BapatView Answer on Stackoverflow
Solution 3 - GitMonika SinghView Answer on Stackoverflow