在我看来,更容易的方法是使用git blame:
git blame $ref -L'/search_pattern/,+1' filename(s)
这是一个关于我的zfs-fuse存储库的完整示例:
$ git for-each-ref --format='%(refname)' -- refs/heads |
while read ref;
do git blame $ref -L'/push/,+1' zfs_operations.c;
done
正如您所见,一半的工作在于获取分支名称;当然,如果这对您的使用更容易,您也可以直接硬编码版本。 上述输出:
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1492) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
请注意行号(
1492 vs.
1512):
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
未匹配搜索模式的任何修订版本都将显示。
fatal: -L parameter 'push': No match
您还需要考虑以下选项:
-M (detect moved lines)
-n (show source line number)
-f (show filename, especially handy with -C)
-p / --incremental: if you want something parsed more easily in code