78

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 

4 Answers 4

110

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
3
  • 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).
    – user743382
    Commented Apr 26, 2015 at 11:01
  • 3
    You are right. So the best way would be a simple: git show -s --format='%ae' HASH
    – Igal S.
    Commented Apr 26, 2015 at 11:29
  • 4
    Or the equally simple git log -1 --format='%ae' HASH for yet another alternative :)
    – user743382
    Commented Apr 26, 2015 at 11:33
30
git show <commit_id> | grep Author

Using git show + pipe + grep works!

15

This will show - sha, committer email, author email

git log --pretty=format:"%h %ce %ae" HASH
1
  • 1
    For this you need to add HASH at the end, otherwise it produces output for all commits instead of for single commit
    – Damian
    Commented Dec 14, 2022 at 9:36
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.