2

I know this kind of thing gets asked a lot (for example here), but (maybe because of this) I have not been able to find what I'm looking for.

I know that I can specify a commit by a pattern matching its commit message, instead of by its hash, like this:

git show ":/rename function X to function Y"

This shows me the most recent commit whose message starts with the given pattern, without me having to search for its hash first.

My questions are:

  1. What is the name of this feature, and where is it documented? (searching Google for :/ is futile)

  2. How can I get the parent of that commit? This does not work:

    git show ":/pattern"^
    
Community
  • 1
  • 1
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

2

It's a bit ugly, and there may be a better way, but you could use something like the following to find the parent:

git show $(git rev-parse ":/pattern")^

git rev-parse gives the SHA1 for the specified revision, to which you can apply operators such as ^. Alternatively, you could use git name-rev --name-only, which will give a symbolic name for the revision (e.g. master~10).

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
1

The :/ syntax does not appear to have a dedicated name and is documented in the gitrevisions(7) manual page.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65