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:
git log --grep=<pattern>
How do I invert the sense of matching?
I am trying to ignore commits that have "bumped to version ..." in the message.
EDIT: I want my final output to be pretty verbose. e.g. git log --pretty --stat
. So output from git log --format=oneline
won't work for me.
As far as I can tell, this is not possible to do directly with a single command line; you'd have to do something like Justin Lilly suggests and then run 'git log' on the resulting list of hashes, e.g.,
should do the trick.
As mentioned by VonC the best option is if you can update to Git 2.4.0 (which is currently on RC2). But even if you can't do that there is no reason for elaborate scripts. A (gnu) awk one-liner should do it.
git log
has the useful-z
option to separate commits by a NUL-character which makes it easy to parse them:If you don't have gnu awk, you probably should at least install that. Or port this script to your specific awk version, which I leave as an exercise for the reader ;-).
Generate a list of all commits, subtract those whose log messages contain the offending pattern, and feed the result to
git log
with your desired options. In the final stage, a couple of options togit log
are handy:You can do it with a single pipeline and process substitution.
If you don't want to use bash, you could do it with Perl.
Assuming one of the above is in your PATH as
git-log-vgrep
and with a history of the formwe could say
to get Z, Y, W, and V.
You can also log other branches, so
gives D, C, B, and V; and
yields just D.
One limitation of the above implementations is if you use a pattern that matches all commits, e.g.,
.
or^
, then you'll get HEAD. This is howgit log
works:This will be possible with Git 2.4+ (Q2 2015): see commit 22dfa8a by Christoph Junghans (
junghans
):Example:
I first grep message with "sequencer" in them:
If I want messages with no sequencer:
A relatively simple method with a lot of flexibility is to use git log with the -z option piped to awk. The -z option adds nulls between commit records, and so makes it easy parse with awk:
(color=always is required to keep coloring when the output is a pipe). Then, its simple to add any boolean expression you want that works on each field. For example, this will print all entries where the author email is not from fugly.com, and the day of the commit was Sunday:
Another nice thing is its you can add in any formatting option or revision range to the git log, and it still works.
One last thing, if you want to paginate it, use "less -r" to keep the colors.
EDIT: changed to use -v in awk to make it a little simpler.