When we are working on a real project, we may want to know from which commit a particular line is introduced.

We can use the following git-log command to find:

git log -S "search term"


For example, to find when the line foo = foo + bar was introduced, we may use the following command:

git log -S "foo = foo + bar"


It will find the commit that created this line.

Another similar command is git-blame, for example, to find which commit introduced line 100, we can use the following command:

git blame -L 100,100


In fact, git-blame shows the most recent change to this line. So if this line has been updated since its creation, for example, you have removed the trailing white spaces or renamed variables in this line, git-blame does not work.

Ref: