Search code examples
gitdiffblame

Find commit that deleted a line between two revision


I am trying to find the commit that deleted a line between between two revisions. I could not find it directly.

This is what I tried in the following:

git blame $v1..$v2 -L $line,+1 --reverse -- $file_name

then this command line returns the line that was deleted and not the commit in question. I searching for this character string using these methods:

1- Search in commits that have modified the function where the line is.

git show $commit:$file | grep -Fq "$st"

2- Searching using the character string.

git log $v1...$v2 --pretty=format:"%h"  -S"$String" $file

In the first, I could not find the function containing that line (or it doesn't exist) in some cases. In the second approach, The string could be repeated in several cases and I need to review all of them.

I need a better way to find the commit that deleted the line.


Solution

  • I usually use a pickaxe search

    git log -SFoo -- path_containing_change 
    

    That lists commits which introduced the string Foo, but also the commits where Foo was deleted.
    Yes, with that approach you need to review those commits in order to determine which one add or remove Foo.