Git 将索引和筛选结果一起显示到标准输出

Git 将索引和筛选结果一起显示到标准输出,git,shell,sh,Git,Shell,Sh,我有一个脚本,可以通过sh命令搜索git存储库中的文本,我可以将它导入其他自定义搜索方法。它在思想上与git log-s类似,但更具可扩展性,而且仍然非常快速 这是WIP脚本 #!/usr/bin/env sh ROOT=`git rev-parse --show-toplevel` # Explanation: # # Git uses pack (*.idx) files to compress older commits. One line reads this # file and

我有一个脚本,可以通过sh命令搜索git存储库中的文本,我可以将它导入其他自定义搜索方法。它在思想上与git log-s类似,但更具可扩展性,而且仍然非常快速

这是WIP脚本

#!/usr/bin/env sh

ROOT=`git rev-parse --show-toplevel`

# Explanation:
#
# Git uses pack (*.idx) files to compress older commits. One line reads this
# file and uncompresses it to get the original git indices.
#
# The second command reads the more recent git indices, as-is.
#
find $ROOT/.git/objects/pack -name "*.idx" | xargs -I{} sh -c 'git show-index < "{}"' | awk '{print $2}' | git -C $ROOT cat-file --batch
find $ROOT/.git/objects/ -type f | grep -v '/pack/\|/info/packs$' | awk -F'/' '{print $(NF-1)$NF}' | git -C $ROOT cat-file --batch

或者类似的东西,所以我知道哪些索引创建了哪些匹配项

我不明白您的工具到底在做什么。它正在打印所有提交的文件?它与git log-S有何不同?我认为手动通过
.git/objects
文件进行遍历是个坏主意。它的不同之处在于您可以自定义搜索内容的方式。如果您想要执行更复杂的查询,
git log-S
是不够的。但是,如果只是进行部分匹配,
git log-S
可以工作。复杂查询是什么意思?我看到
git log
支持所有
grep
东西,包括perl regexp。我还看到您的工具输出不受所用表达式的影响,那么您的
git search
输出是什么呢
获取名称中同时包含“http”和“foo”的URL
git log--grep'http.*foo'
git log--all match--grep foo--grep http
ff7c1dfa2447eae0c3d51b8ddea3e4a6ff32acf
    def __init__(self):
    def __call__(self, match):
ff7e497f3b1884e2934e37914da497f2ece9c7a9
...