Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Git log for commits that don't contain a specific word

Tags:

git

How can I filter git logs for commits that don't contain a specific word?

I've looked at regexp sites, and tried some cases without success in Git Bash.

like image 846
jsmith Avatar asked Oct 25 '25 07:10

jsmith


2 Answers

You can use git log --grep="<your string>" combined with the --invert-grep parameter to invert the search criteria (as of Git for Windows 2.6.2).

Example:

Find commits where the commit message contains the string foo:

git log --grep="foo"

Find commits where the commit message does not contain the string foo:

git log --invert-grep --grep="foo"

like image 129
Pabru Avatar answered Oct 27 '25 21:10

Pabru


As mentioned by Claudiu

In general it's a pain to write a regular expression not containing a particular string. We had to do this for models of computation - you take an NFA, which is easy enough to define, and then reduce it to a regular expression. The expression for things not containing "cat" was about 80 characters long.

and you can do it in inverse, not elegant, but working way

git log ... | grep -v "someword"

PS - negation in RE is ^ prefix, it (prefix usage) may want -E (extended regexp) for git log, but defining negated word as word for regexp is just real nightmare

like image 41
Lazy Badger Avatar answered Oct 27 '25 21:10

Lazy Badger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!