I want to use git log
to show all commits that do not match a given pattern. I know I can use the following to show all commits that do match a pattern:
As with thebriguy's answer, grep also has a -z option to enable it to work with null terminated strings rather than lines. This would then be as simple as inverting the match:
git log -z --color | grep -vz "bumped to version"
For safety you may want to match within the commit message only. To do this with grep, you need to use pearl expressions to match newlines within the null terminated strings. To skip the header:
git log -z | grep -Pvz '^commit.*\nAuthor:.*\nDate:.*\n[\S\s]*bumped to version'
Or with colour:
git log -z --color | \
grep -Pvz '^.....commit.*\nAuthor:.*\nDate:.*\n[\S\s]*bumped to version'
Finally, if using --stat, you could also match the beginning of this output to avoid matching file names containing the commit string. So a full answer to the question would look like:
log -z --color --pretty --stat | \
grep -Pvz '^.....commit.*\nAuthor:.*\nDate:.*\n[\S\s]*?bumped to version[\S\s]*?\n [^ ]'
Note that grep -P
is described as 'highly experimental' in my man page. It may be better to use pcregrep
instead which uses libpcre, see How to give a pattern for new line in grep?. Although grep -P
works fine for me and I have no idea if pcregrep
has a -z option or equivalent.