70

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 
Patryk
  • 22,602
  • 44
  • 128
  • 244

4 Answers4

100

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
asmeurer
  • 86,894
  • 26
  • 169
  • 240
Igal S.
  • 13,146
  • 5
  • 30
  • 48
  • 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`). –  Apr 26 '15 at 11:01
  • 3
    You are right. So the best way would be a simple: `git show -s --format='%ae' HASH` – Igal S. Apr 26 '15 at 11:29
  • 4
    Or the equally simple `git log -1 --format='%ae' HASH` for yet another alternative :) –  Apr 26 '15 at 11:33
24
git show <commit_id> | grep Author

Using git show + pipe + grep works!

Chaitanya Bapat
  • 3,381
  • 6
  • 34
  • 59
13

This will show - sha, committer email, author email

git log --pretty=format:"%h %ce %ae"
Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
Monika Singh
  • 169
  • 1
  • 8
  • For this you need to add HASH at the end, otherwise it produces output for all commits instead of for single commit – Damian Dec 14 '22 at 09:36
1

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).

djsavvy
  • 106
  • 1
  • 2
  • 9