2

I want to know the commit ID (hash) of a specific commit message. More often than not, the commit message will be unique hence there should be no case of multiple commits with same message.

Following command gives the complete detail about the commit, but i'm interested only in the commit-id (Hash). How can i know it ?

Input:

git log --grep="....commit message that you want to search..."

Output:

commit a5s6d7f8g9cde4100ce92c87c3cff83e8112345de
Author: Authors Name <name@domain.com>
Date:   Tue Feb 2 09:22:29 2048 +0000

    commit-message: This is the message that i search to get commit hash

Expected Output:

a5s6d7f8g9cde4100ce92c87c3cff83e8112345de
Yash
  • 2,944
  • 7
  • 25
  • 43
  • 2
    Possible duplicate of [git log show one commit id only](https://stackoverflow.com/questions/31448445/git-log-show-one-commit-id-only) – GolezTrol Feb 13 '18 at 15:36
  • I've come to realize that it's not *exactly* the same, but it does show how to do this, namely though a `pretty-format` parameter. The format you're looking for is `%H` for the complete hash, in contrast to the lowercase `%h` for the abbreviated hash, as used in the other question. See also [Pretty formats](https://git-scm.com/docs/pretty-formats). – GolezTrol Feb 13 '18 at 15:39
  • @GolezTrol: My question was different. However, the solution suggested by "0kay" has solved my query. Thanks! – Yash Feb 13 '18 at 15:45

1 Answers1

5

Add --format='%H'

git log --grep="....commit message that you want to search..." --format='%H'

More info: https://git-scm.com/docs/pretty-formats

0kay
  • 433
  • 4
  • 7