Kostas Konstantinidis
Kostas Konstantinidis

Reputation: 13707

Git log - How to list all commits that don't start with a specific word

My main aim is to filter out all pull request merges thus in theory i would expect the following to work(it doesn't)

git log --grep="^!(Merge)"

Do I miss something ?

Upvotes: 4

Views: 1271

Answers (2)

Learath2
Learath2

Reputation: 21343

That is not correct you ant use regex like that something like this would be better:

git log | grep -o '^(Merge)'

And this would provide more info:

git log --pretty=format:'%h by %an, %ar, %s' | grep -o '^((?!Merge).)*$'

I think you used ! To inverse it but the only known way of inverse revex search i know of is like above. Still the --no-merge would provide better info just writing for future referance

Upvotes: 2

KL-7
KL-7

Reputation: 47588

First, you can't simply negate a word in a regexp by putting a bang in front of it (where did you find that?). You might have used lookarounds for that, but regular grep regexps do not support them. Using grep directly you can pass -P option to use much more powerful Perl regexps, but I didn't find similar option for git log.

Though, there is --no-merges option that will filter out all merge commits from the log:

git log --no-merges

Man page says that --no-merges means:

Do not print commits with more than one parent

Upvotes: 11

Related Questions