brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git show :/text picks the newest commit whose message matches

Git
~/tips/tip-git-show-commit-by-message

git show ':/fix login'

Refers to a commit by words from its message instead of by its hash.

Copying hashes around gets old. Git lets you point at a commit by a bit of its message, with a colon and a slash.

git show ':/fix login'

:/ followed by text means “the youngest commit whose message matches this regular expression”, searched from all your refs. It works anywhere git expects a commit, so you can use it with other commands:

git cherry-pick ':/Add export button'
git diff ':/release 2.3' HEAD

Quote it, because the text often contains spaces, and some shells have their own ideas about the colon and exclamation mark.

There’s a variant that searches from a specific branch: main^{/fix login} looks for the newest matching commit reachable from main. I prefer that one when the same words appear on several branches.

A leading exclamation mark has a special meaning. :/!-foo means “message does not match foo”, and :/!! stands for a literal exclamation mark. That’s rarely what you want by accident, so avoid starting your search text with one.

The search picks only one commit, the newest match. If you have five commits that say “fix login”, you get the last one, which may not be the one you meant. Run git show -s on it first to check before you cherry-pick or reset anything.

Further reading: gitrevisions documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link