Search code examples
pythongitgithubgrepgit-log

Regex for grepping exact phrase in git log


Currently, I am working on mining software repository in github. I use the git log command to get the commit logs. But when I only need to find the commit logs contain a specific word, some unexpected logs also have shown.

For example, I need the commit log contains word HBASE-792. I used command git log --grep='HBASE-792' --oneline. But these logs have shown:

HBASE-7921. TestHFileBlock.testGzipCompression should ignore the block checksum
HBASE-7923 force unassign can confirm region online on any RS to get rid of double assignments
HBASE-7928 Scanning .META. with startRow and/or stopRow is not giving proper results; REVERT.  NEEDS SOME MORE WORK
Fix overlogging; part of HBASE-792 patch
Patches to alleviate HBASE-790 and HBASE-792

What I need are only the last 2 commit logs which exactly contain HBASE-792. What pattern should I write in grep?


Solution

  • You can try piping the output of git log to grep, and using the -w flag of grep. Here go the sample run for a test repo I made:

    Test $ git log --grep='HBASE-792' --oneline
    09172fd asd sHBASE-792 asd
    bea6628 asd HBASE-792s asd
    3100179 asd HBASE-792 asd
    4cb3200 HBASE-792
    

    with -w flag:

    Test $ git log --oneline | grep -w "HBASE-792"
    3100179 asd HBASE-792 asd
    4cb3200 HBASE-792