我在我的存储库中使用 git notes。有时我需要找到包含给定字符串的注释的提交。到目前为止,我正在使用这个命令:
git log --show-notes=* --grep="PATTERN" --format=format:%H
这里的问题是,这会打印每个带有 PATTERN 的提交 SHA,即使它不是仅在提交消息中的注释中。有没有更好的方法呢?
笔记存储在一个COMMIT
edTREE
中,该 ed 被“隐藏”在 notes ref 下方(refs/notes/commits
默认情况下)。这意味着您可以像处理内容一样处理它们。
$ git grep Testing refs/notes/commits
refs/notes/commits:fad066950ba73c309e80451d0d0f706e45adf5a8:This is a test - Testing
$ git show fad0669
commit fad066950ba73c309e80451d0d0f706e45adf5a8
Author: Mark Adelsberger <adelsbergerm@xxx>
Date: Thu Sep 6 07:51:15 2018 -0500
1
Notes:
This is a test - Testing
diff --git a/file1 b/file1
index e69de29..038d718 100644
--- a/file1
+++ b/file1
@@ -0,0 +1 @@
+testing
格式字符串中有一个用于注释的占位符,%N
. 我不知道如何在一行中打印注释,所以我使用循环来一一测试所有可达提交的注释。
尝试
git log --format=%H | while read commit;do
git log -1 $commit --format=%N | if grep -q "PATTERN";then echo $commit;fi;
done
您可以更改echo $commit
为git log -1 --show-notes $commit
.