Is there any way to get the SHA of a commit from its message?

前端 未结 3 2338
一整个雨季
一整个雨季 2021-02-19 23:19

When doing a git tag, I\'m not always great at remembering if HEAD~6 (for example) is inclusive or exclusive.

Given that most of my commits are prefixed wi

3条回答
  •  无人共我
    2021-02-20 00:13

    You can use :/blah syntax to specify a commit whose commit message starts with the given text.

    E.g.

    git show ":/Issue #299"
    

    This is valid anywhere a commit can be used. E.g.

    git cherry-pick ":/Issue #299"
    

    If you actually need the SHA-1 of the commit you can just use rev-parse.

    git rev-parse ":/Issue #299"
    

    See the "SPECIFYING REVISIONS" section of the git rev-parse man page:

    A colon, followed by a slash, followed by a text:
    This names a commit whose commit message starts with the specified text.
    This name returns the youngest matching commit which is reachable from any ref.
    If the commit message starts with a !, you have to repeat that; the special sequence :/!, followed by something else than ! is reserved for now.

提交回复
热议问题