Search code examples
gitgit-rev-parse

Refer to parent of matched commit when using :/ syntax


The :/ syntaxallows you to match commits using regular expressions. E.g., to create a fixup commit for an earlier commit that contains the string 'Add widget', you can write:

git commit --fixup ':/Add widget'

Is there way to apply modifiers such as ^ or ~ to the :/ expression? I've tried the obvious syntax...

git show ':/Add widget^'

Which doesn't work:

fatal: ambiguous argument ':/widget^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(And git show ':/Add widget^' -- results in fatal: bad revision ':/Add widget^').


Solution

  • Use the anchored search, '@^{/Add widget}^' or do the substitution yourself with $(git rev-parse :/Add\ widget)^