Reputation: 55
At day job there are some automated commits made to our git repos with a specific subject: "Job: sync <unique-id> <timestamp>"
A script exists that finds the latest commit of this type and extracts the <unique-id>, using something like:
git log --pretty=format:"%s" --grep='Job: sync' -n 1 | awk '{print $3}'
A problem arose when someone created a commit that contains the text "Job: sync" somewhere in the commit message body (not in the first line of the message).
It turns out git log --grep=
searches the whole message and not just the subject.
Problem has been partially mitigated by changing --grep='Job: sync'
to --grep='^Job: sync'
(so it only matches at the beginning of a line). But in theory someone can create a commit message that will also match the new grep pattern.
My question: How do I best search for all commit messages in a git repo that contains a specific text in its subject (first line of the commit message)?
Upvotes: 2
Views: 40
Reputation: 94397
git log --oneline | grep " Job: sync"
A space before the pattern to match the pattern after the commit IDs. Try git log --oneline
to see its output.
grep "Job: sync"
(without the leading space) to search the pattern everywhere in the subject line.
Upvotes: 1