Marcin Erdmann

Groovy, Grails, Geb...

Specifying git revisions using a commit message

Sometimes when I want to rebase some commits in git I cannot be bothered to copy and paste commit hash or calculate how many commits behind HEAD the commit I want to rebase onto is to be able to use the HEAD~N notation.

Recently I've learned from gitrevisions manual that you can also specify a git revision using the :/<text> notation where <text> is a regular expression applied against commit messages. Unfortunately it doesn't work with git rebase complaining that it expects a single revision. But you can always use git rev-parse to resolve a git commit hash:

git rebase -i $(git rev-parse ":/some commit message")