Git repo search for the names of all files that ever contained a string

I need to find every instance of a specific line that is added or deleted from any file in the repository.

So far i tried

git log -S'string' --all git log --follow -p path/to/file git show --pretty="format:" --name-only <hash> git diff $(git log -S'string' -i --all --pretty="%H") | tee output.txt 

in various combinations.

All I can get is a list of thousands of files that were part of the commits that included the line. I need a list of only those files that at some point contain a string.

+4
source share
3 answers

git log -Sstring -p provides all the output, and it is easy enough to extract the file names:

 git log -p -Sstring --all | grep '^---\|^+++' | grep -v /dev/null \ | sed 's%^\(---\|+++\) [ab]/%%' 
+4
source

Use git grep

 git log --all --format=format:%H | xargs -n 1 git grep -i -I --full-name "perl" 

This one will look for perl entries for each commit, the output is this.

 c3eab7df88fdc5e848fd13fdab4298afd24f9ee8:bugzilla/bugzilla.pl:#!/usr/bin/perl 

It may not solve your problem as you want to know when it will be added and removed.

0
source

You can use the shell script to iterate over all the files that are currently being tracked using Git, and then determine if each file contains a line:

 for f in $(git ls-files); do commits=$(git log -S'string' --oneline -- $f | wc -l) if [[ $commits -gt 0 ]]; then echo $f fi done 

This list will not list the files that contained this line, but were subsequently deleted.

0
source

Source: https://habr.com/ru/post/1488513/


All Articles