Does "whose commit message matches the given regular expression" qualify "the youngest commit" or `rev`?

Viewed 59

Git Pocket Guide says

rev^regexp

For example, HEAD^{/"fixed pr#1234"}; this selects the youngest commit reachable from rev whose commit message matches the given regular expression.

Does "whose commit message matches the given regular expression" qualify "the youngest commit" or rev?

I am always uncertain about this and similar cases.

1 Answers

rev does. From gitrevisions...

<rev>^{/<text>}, e.g. HEAD^{/fix nasty bug}

A suffix ^ to a revision parameter, followed by a brace pair that contains a text led by a slash, is the same as the :/fix nasty bug syntax below except that it returns the youngest matching commit which is reachable from the <rev> before ^.

Note that it's not the youngest commit in the entire repo. It's the youngest commit reachable from the <rev>. If you want the youngest in the whole repo use :/<regexp>.

:/<text>, e.g. :/fix nasty bug

A colon, followed by a slash, followed by a text, names a commit whose commit message matches the specified regular expression. This name returns the youngest matching commit which is reachable from any ref, including HEAD. The regular expression can match any part of the commit message. To match messages starting with a string, one can use e.g. :/^foo. The special sequence :/! is reserved for modifiers to what is matched. :/!-foo performs a negative match, while :/!!foo matches a literal ! character, followed by foo. Any other sequence beginning with :/! is reserved for now. Depending on the given text, the shell's word splitting rules might require additional quoting.

This makes more sense if you realize Git history is not like a big stack of pancakes. It's a directed graph. Git history looks like this...

------ time -------->

              [HEAD]
A <- B <- C <- D [master]
           ^
            \
             E <- F <- G [feature]

This shows a repository with the master branch checked out. It also has a feature branch which has younger commits than master. G is the youngest commit in the repository, but D is the youngest commit reachable by master and HEAD.

HEAD^{/fix nasty bug} will search for fix nasty bug in D, then C, then B, then A. Because the connections are one-way it will not search E, F, nor G because they cannot be reached from HEAD.

Related