Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-bash

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 ?

like image 293
Konstantinos Avatar asked Dec 12 '22 03:12

Konstantinos


2 Answers

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

like image 191
KL-7 Avatar answered May 08 '23 12:05

KL-7


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

like image 30
Learath2 Avatar answered May 08 '23 13:05

Learath2