Skip git commits with a specific string using git log

142 views Asked by At

I would like to take the latest 5 commits using git log that do not contain a specific string, for example "Merge branch".

I tried several options, but none of them worked. e.g.:

 git log -n 5 --grep="Merge branch" --invert-grep
 git log -n 5 -v --grep="Merge branch"
 git log -n 5 --not --grep="Merge branch"

It seems that --invert-grep does the job but it doesn't work (http://git-scm.com/docs/git-log)

1

There are 1 answers

0
ComputerDruid On BEST ANSWER

If you're specifically trying to look for non-merge-commits, you can use:

git log -n 5 --no-merges

This will, of course, also skip merge commits that don't contain "Merge branch" in their log message.