2

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.

Amine Barrak
  • 139
  • 9

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • the problem here, when we have just Foo="return 0", we will have a lot of responses of changes that are not really included in what we are expecting. – Amine Barrak Mar 14 '18 at 12:30
  • @AmineBarrak Even when limited to a specific file? – VonC Mar 14 '18 at 12:31
  • yes, sure in a file there is several "return 0". Let's say in many cases. It is not a concrete solution – Amine Barrak Mar 14 '18 at 12:48
  • @AmineBarrak And if you limit it to a *function* within a file? Would that work? See https://git-scm.com/docs/git-log#git-log--Lltstartgtltendgtltfilegt – VonC Mar 14 '18 at 13:22
  • I did that part already, on the step one of my search of the commit – Amine Barrak Mar 14 '18 at 13:28
  • @AmineBarrak no, I mean, per function, not per line. And using log, not blame. – VonC Mar 14 '18 at 14:14
  • Actualy in the first search part, I determine commits changing the function where the line were modified and search on these commits one by one and find where the string were modified. – Amine Barrak Mar 14 '18 at 14:51
  • @AmineBarrak That is what git log -S would do, especially when using the function name in -L. – VonC Mar 14 '18 at 14:53