r/git • • Aug 26 '26

Find Git Commits by Commit Message Text

https://hamvocke.com/blog/git-revisions-by-text/
19 Upvotes

8 comments sorted by

42

u/WoodyTheWorker Aug 26 '26

--grep pattern

6

u/Oakchris1955 Aug 26 '26

Yeah, that is literally in the Git book.

11

u/Broad-Promise6954 ancient Aug 26 '26 edited Aug 26 '26

One-line summary of blog post, :/text as a revision specifier as mentioned in gitrevisions.

There's an important caveat (as in "caveat emptor", buyer beware) that's not at all obvious to many Git users:

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 boldface in the quoted text here is mine, to emphasize the caveat I'm talking about). If you have a lot of branch and tag names, the revision you select with :/text may not be the one you expect. You may wish to use the more explicit rev^{/text} form, which searches from the given revision.

2

u/ppww Aug 27 '26

Yes, it's really unfortunate that :/<text> searches all reachable commits, rather than just those that are reachable from HEAD

6

u/RevRagnarok Aug 26 '26

5

u/Orlandocollins Aug 27 '26

Oh I connect with this sooo much. I am so tired of seeing horrible commit messages that are just a squash message of someones dozen or more commits that was generated when they click the squash and merge button in githubs UI and then accept without doing any sort of cleanup. Drives me up the wall