338

I need to find a commit in Git by a given hash, SHA. For example, if I have the "a2c25061" hash, and I need to get the author and the committer of this commit.

What is the command to get that?

Flip
  • 5,443
  • 6
  • 39
  • 69
Ghadeer
  • 3,389
  • 2
  • 12
  • 3

3 Answers3

495

Just use the following command

git show a2c25061
Pavan Yalamanchili
  • 11,981
  • 2
  • 34
  • 55
  • 27
    Also good will be `git log a2c25061 -n 1`. It will show only info about commit, without diff. – Hauleth Jan 05 '13 at 00:56
  • 62
    `git show a2c25061 --stat` works the same and is easier to remember – mvp Jan 06 '13 at 08:47
  • Off topic, but may be very useful for those looking to checkout a commit by hash, without knowing e.g. what branch an old commit was made on, simply by using `git checkout a2c25061` – MahNas92 Aug 18 '20 at 15:27
  • 1
    Note that `git log -p -1 ` is **exactly identical to** `git show `. – Gabriel Staples Feb 20 '21 at 23:14
  • 3
    `git show a2c25061 -s` is an even shorter way to suppress the diff output. – Logan Apr 14 '21 at 23:07
69
git log -1 --format="%an %ae%n%cn %ce" a2c25061

The Pretty Formats section of the git show documentation contains

  • format:<string>

The format:<string> format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n

The placeholders are:

  • %an: author name
  • %ae: author email
  • %cn: committer name
  • %ce: committer email
Community
  • 1
  • 1
Greg Bacon
  • 128,067
  • 29
  • 183
  • 243
20

There are two ways to do this.

1. providing the SHA of the commit you want to see to git log

git log -p a2c25061

Where -p is short for patch

2. use git show

git show a2c25061

The output for both commands will be:

  • the commit
  • the author
  • the date
  • the commit message
  • the patch information
Yamona
  • 960
  • 1
  • 14
  • 33