Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which commits removed a line that contain a specific string?

Tags:

git

I have a file that is no longer referenced anywhere in my code. I am looking for find which commits removed a reference to this file. (I have no idea which files used to reference it).

I know that git log -S would find commits that either added or removed this string. What I am looking for really is the ability to limit this search to just those lines that were removed. Is this possible?

like image 953
Jonny Shanahan Avatar asked Jul 22 '15 14:07

Jonny Shanahan


1 Answers

I would like to see an easier solution. But with some shell-Scripting it would look like:

for id in $(git log -Sstring --pretty=%h)
do
  if [ "$(git show $id | grep "+.*string")" != "" ]
  then
    echo $id
  fi
done
like image 69
Bertram Nudelbach Avatar answered Oct 20 '22 01:10

Bertram Nudelbach