56

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
  • 20,424
  • 38
  • 116
  • 227

3 Answers3

81

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
  • 80,291
  • 25
  • 162
  • 229
Igal S.
  • 11,488
  • 4
  • 31
  • 44
  • 2
    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
  • 3
    Or the equally simple `git log -1 --format='%ae' HASH` for yet another alternative :) –  Apr 26 '15 at 11:33
19
git show <commit_id> | grep Author

Using git show + pipe + grep works!

Chaitanya Bapat
  • 2,345
  • 3
  • 27
  • 50
11

This will show - sha, committer email, author email

git log --pretty=format:"%h %ce %ae"
Majid Hajibaba
  • 2,834
  • 6
  • 19
  • 46
Monika Singh
  • 141
  • 1
  • 8