387

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
  • 6,233
  • 7
  • 46
  • 75
Ghadeer
  • 3,879
  • 2
  • 13
  • 3

3 Answers3

559

Just use the following command

git show a2c25061
Pavan Yalamanchili
  • 12,021
  • 2
  • 35
  • 55
  • 31
    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
  • 69
    `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
  • 2
    Note that `git log -p -1 ` is **exactly identical to** `git show `. – Gabriel Staples Feb 20 '21 at 23:14
  • 4
    `git show a2c25061 -s` is an even shorter way to suppress the diff output. – Logan Apr 14 '21 at 23:07
  • Beware of rewritten commits. Even if the commit sourcetree is not changed, you won't find the commit. Because of lack of the hash for the sourcetree in a commit additionally to the hash for entire commit. – Andry Feb 03 '23 at 01:12
72
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
  • 134,834
  • 32
  • 188
  • 245
29

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
  • 1,070
  • 1
  • 16
  • 36