使用termux和regexp在git上搜索历史日志和文件

问题描述

尝试了类似问题的所有答案:

How to grep Git commit diffs or contents for a certain word?

Search all of Git history for a string?

How to grep (search) committed code in the Git history

没有工作!

甚至可以使用anything other than git itself进行搜索吗?

已测试存储库:http://cregox.net

场景

图片数百个markdown文件,其中许多将具有以下内容

---
title: lorem ipsum
description: foo,or not foo,it's not even a question
bar: false

(实际上,我想要的是foo而不是checklist,而不是bar

预期

published

搜索所有出现在第一个ag "foo[\s\S]*bar:\ " 之前的1个foo文件(如果它们都存在)。

我需要的只是那个,应用于git历史记录。

就是这样。

但是...

现实

bar: 

由于git log -G "foo[\s\S]*bar:\ " ,甚至无法代替silversearcher-ag。

我已经尝试过many个正则表达式的变体,找不到任何可以使用的正则表达式!

所以这是我想在某个时候解决的问题,但与此同时,我也尝试了其他替代方法...

\s

应该带来类似于git log -p -S foo 的东西,但距离可读性还差得太远,而且太冗长了。

rg foo

this是我能达到预期结果的最接近的结果……但是它仍然太麻烦了。

我暂时放弃挖掘。

解决方法

使用git log正则表达式可以使您跨线匹配:

git log --name-status --oneline -G 'foo(\S|\s)+bar:\s'