jsmith
jsmith

Reputation: 127

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

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.

Upvotes: 4

Views: 3572

Answers (3)

Pabru
Pabru

Reputation: 231

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"

Upvotes: 7

Lazy Badger
Lazy Badger

Reputation: 97270

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

Upvotes: 1

Justin Lange
Justin Lange

Reputation: 72

You can only search commit messages this way, which is done by submitting code using the -m flag in your check-in. Example:

commit -m "message describing awesome code changes"

This will save the message "message describing awesome code changes" in the log, meaning that a search for the word awesome, as an example, will now return this as a result.

Is it possible that the phrase/word/message you are searching for has never been included in a commit message?

Upvotes: 0

Related Questions