用于在 git 日志中查找精确短语的正则表达式

Regex for grepping exact phrase in git log

目前,我正在 github 从事挖掘软件存储库的工作。我使用 git log command 来获取提交日志。但是当我只需要查找包含特定单词的提交日志时,一些意外的日志也显示了。

例如,我需要提交日志包含单词HBASE-792。我使用命令 git log --grep='HBASE-792' --oneline。但是这些日志显示:

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

我需要的只是最后 2 个完全包含 HBASE-792 的提交日志。我应该在 grep 中写什么模式?

您可以尝试 运行 Perl 模式下的 grep:

git log --grep='\bHBASE-792\b' --perl-regexp --oneline

我所做的只是在 HBASE-792 周围设置单词边界。有了它们,您的模式不应再与例如HBASE-7923 出现在不应匹配的行之一的开头。

您可以尝试将 git 日志的输出通过管道传输到 grep,并使用 grep 的 -w 标志。这是我制作的测试回购的示例 运行:

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

带有 -w 标志:

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