Alex R
Alex R

Reputation: 2221

How to use the "colon slash" revision short form and still refer to a commit's parent?

Assume I want to refer to a the parent of youngest commit whose commit message contains 'foo'.

HEAD^{/foo}^ will do the job.
This can be slightly shortened to @^{/foo}^ (I think).

The <rev>^{/<text>} construction has a simplified form, though: :/<text>.

Is there any way to use the short form and still refer to the parent of the resulting commit?

Upvotes: 4

Views: 184

Answers (1)

VonC
VonC

Reputation: 1327294

Following the git rev-parse command, you can combine two of those in order to get the parent of a commit whose message match the regexp.

In a git bash, type:

git rev-parse $(git rev-parse :/<text>)^

Those are two commands:

  • first getting the commit with the right message: git rev-parse :/<text>
  • then getting its parent git rev-parse $(...)^

The $() will execute the first command git rev-parse and give its result to the second command git rev-parse.

That will get you the parent of the commit with a commit message matching <text>.


This differ from using only one command with:

git rev-parse HEAD^{/<text>}^

Or in Windows CMD:

git rev-parse "@^{/<text>}^"
# or, more complex, as ^ is the windows escape sign:
git rev-parse ^@^^{/<text>}^^

Upvotes: 5

Related Questions