-1

tried every answer from similar questions:

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

none worked!

would it even be possible to search using anything other than git itself?

repository tested: http://cregox.net

scenario

picture hundreds of markdown files, a dozens of which will have something like this:

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

(in practice, instead of foo it was checklist and instead of bar i wanted published)

expected

ag "foo[\s\S]*bar:\ "

will search all files with 1 foo that happens before the first bar: if they both exist.

all i needed was that, applied to git history.

that's it.

but...

reality

git log -G "foo[\s\S]*bar:\ "

instead of silversearcher-ag doesn't even work because of \s.

i've tried many variations of regexp, couldn't find any single one that would work!

so that's something that i'll want to fix at some point, but meanwhile i also tried other alternatives...

git log -p -S foo

should bring something similar to rg foo, but doesn't come even close to be readable and it's way too verbose.

git log --name-status --oneline -S foo

this was the closest i could get to the expected results... but it's still too cumbersome.

i give up digging for now.

anubhava
  • 761,203
  • 64
  • 569
  • 643
cregox
  • 17,674
  • 15
  • 85
  • 116
  • is asking for regex help to solve his problem so restoring `regex` tag – anubhava Nov 12 '20 at 19:21
  • What do you mean by "history log"? Is "ag" [this searcher](https://github.com/ggreer/the_silver_searcher)? – torek Nov 13 '20 at 01:52
  • @torek i meant git log commit messages history. yes, it's the silver searcher. also mentioned rip grep. – cregox Nov 13 '20 at 17:28
  • It's a bit difficult to use an external searcher on Git log messages: the only way to do that is to have Git extract each commit to some plain-text file. This is because commits are, internally, Git objects, and all Git objects are just these read-only, compressed, de-duplicated data blocks. (Commits are never duplicates so the de-duplication side effect is largely irrelevant here, except in terms of delta compression in pack files.) It's even more difficult to search commit diffs as Git has to *generate* those diffs from scratch every time you have Git compare two commits. – torek Nov 13 '20 at 23:07
  • If you do wish to do something like that, consider running `git log -m -p`, redirecting the output to a file, and then using your external searcher on the file. It's going to be messy. – torek Nov 13 '20 at 23:09
  • @torek thanks for the input! seems like it's a better idea to figure out what could be wrong in my end... i was thinking it could be unsupported operations by git. – cregox Nov 21 '20 at 09:51

1 Answers1

2

With git log regex following should work for you to match across the lines:

git log --name-status --oneline -G 'foo(\S|\s)+bar:\s'
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • nope. still getting the same deprecation warning for the regex... and empty results. wonder if there's something broken with my termux now. – cregox Nov 12 '20 at 20:49
  • 1
    Hmm strange as that is working fine on my `git version 2.24.3 (Apple Git-128)` – anubhava Nov 12 '20 at 20:51